示例#1
0
        public void RandomSequenceTest()
        {
            //Arrange
            const int   numControlPoints = 3;
            const int   dimention        = 3;
            const float maxValue         = 3.0f;
            var         sequenceMaker    = new RandomSequenceMaker(10, maxValue, numControlPoints,
                                                                   new Dictionary <Guid, int> {
                { Guid.NewGuid(), (new ManipulatableMock()).GetManipulatableDimention() }
            });

            //Act
            sequenceMaker.Init(
                _dummyActions,
                new Dictionary <Guid, int> {
                { Guid.NewGuid(), new ManipulatableMock().GetManipulatableDimention() }
            }
                );
            var sequenceDict = sequenceMaker.GenerateSequence(_dummyActions[0]);

            //Assert
            var sequence = sequenceDict.Values.First();

            Assert.AreEqual(sequence[0].Values.Length, numControlPoints);
            Assert.AreEqual(sequence[0].Values.Length, dimention);
            Assert.Less(sequence[0].Time, sequence[1].Time);
            Assert.Less(sequence[0].Values[0], maxValue);
            Assert.Less(sequence[0].Values[1], maxValue);
            Assert.Less(sequence[0].Values[2], maxValue);
            Assert.Greater(sequence[0].Values[0], 0);
            Assert.Greater(sequence[0].Values[1], 0);
            Assert.Greater(sequence[0].Values[2], 0);
        }
示例#2
0
 public RandomSequenceMaker(RandomSequenceMaker other, Dictionary <Guid, int> newManipulatorDimensions)
 {
     _timeRange        = other._timeRange;
     _valueRange       = other._valueRange;
     _numControlPoints = other._numControlPoints;
     _outputDimentions = newManipulatorDimensions.ToDictionary(x => x.Key, x => x.Value);
     _randomGenerator  = other._randomGenerator;
 }
示例#3
0
 public RandomSequenceMaker(RandomSequenceMaker other)
 {
     _timeRange        = other._timeRange;
     _valueRange       = other._valueRange;
     _numControlPoints = other._numControlPoints;
     _outputDimentions = other._outputDimentions.ToDictionary(x => x.Key, x => x.Value);
     _randomGenerator  = other._randomGenerator;
 }
示例#4
0
 public Candidate(Candidate other, Dictionary <Guid, int> manipulatableDimensions) // deep copy
 {
     mean        = other.mean;
     _meanSquare = other._meanSquare;
     variance    = other.variance;
     std         = other.std;
     numTried    = Mathf.Min(other.numTried, 1);
     value       = RandomSequenceMaker.CopyValueWithSequenceMapping(other.value, manipulatableDimensions);
 }
示例#5
0
        public void DeepCopyConstructorTest()
        {
            var sequenceMaker = new RandomSequenceMaker(10, 3.0f, 3,
                                                        new Dictionary <Guid, int> {
                { Guid.NewGuid(), new ManipulatableMock().GetManipulatableDimention() }
            });

            sequenceMaker.Init(_dummyActions,
                               new Dictionary <Guid, int> {
                { Guid.NewGuid(), new ManipulatableMock().GetManipulatableDimention() }
            });
            Assert.IsNotNull(new RandomSequenceMaker(sequenceMaker));
        }
示例#6
0
        private void Maintain(IAction action)
        {
            if (_maintainRandom.Sample() < _epsilon)
            {
                var newCandidates = _candidatesDict[action.Name].OrderBy(o => o.mean).ToList();

                Candidate maxCandidate = newCandidates[newCandidates.Count - 1];
                // replace a worst candidate
                newCandidates[0] =
                    new Candidate(
                        RandomSequenceMaker.GenerateSimilarSequence(maxCandidate.value, _epsilon, timeRatio: 1f));

                _candidatesDict[action.Name] = newCandidates;
            }
        }
示例#7
0
 public override void Init(List <IAction> actions, Dictionary <Guid, int> manipulatableDimensions)
 {
     base.Init(actions, manipulatableDimensions);
     _randomMakerDict = new Dictionary <string, RandomSequenceMaker>();
     _candidatesDict  = new Dictionary <string, List <Candidate> >();
     foreach (var action in actions)
     {
         var rsm = new RandomSequenceMaker(MaxSequenceLength, 1.0f, _numControlPoints, manipulatableDimensions);
         rsm.Init(actions, manipulatableDimensions);
         _randomMakerDict.Add(action.Name, rsm);
         _candidatesDict.Add(action.Name, new List <Candidate>
         {
             new Candidate(rsm.GenerateSequence(action))
         });
     }
 }
示例#8
0
        public override void Init(List <IAction> actions, Dictionary <Guid, int> manipulatableDimensions)
        {
            base.Init(actions, manipulatableDimensions);
            var actionsList = actions.Where(x => !(x is SubDecisionMakerAction)).ToList();

            _candidatesDict = new Dictionary <string, List <Candidate> >();
            foreach (var action in actionsList)
            {
                var rsm = new RandomSequenceMaker(_sequenceLength, 1, 3, manipulatableDimensions);
                rsm.Init(new List <IAction> {
                    action
                }, manipulatableDimensions);

                var candidates = new List <Candidate>(_minimumCandidates);
                for (var i = 0; i < candidates.Capacity; i++)
                {
                    candidates.Add(new Candidate(rsm.GenerateSequence(action)));
                }

                _candidatesDict.Add(action.Name, candidates);
            }
        }