public void デシリアライズ後Restoreされたものは経験を引き継ぐ() { // Init parent var parentDecisionMaker = new ReinforcementDecisionMaker(); var actions = new List <IAction>(); for (int i = 0; i < 100; i++) { actions.Add(LocomotionAction.GoStraight(i.ToString())); } parentDecisionMaker.Init(actions); parentDecisionMaker.DecideAction(_dummyStates[0], forceRandom: false, forceMax: true); parentDecisionMaker.Feedback(new List <float>() { 3f }); parentDecisionMaker.DecideAction(_dummyStates[0], forceRandom: false, forceMax: true); var saveDataClone = EditorTestExtensions.DeepCloneByMsgPack(parentDecisionMaker.Save()); var decisionMakerClone = saveDataClone.Instantiate() as ReinforcementDecisionMaker; var originalTrainer = TestHelper.GetFieldValue(parentDecisionMaker, "_trainer") as TemporalDifferenceQTrainer; var cloneTrainer = TestHelper.GetFieldValue(decisionMakerClone, "_trainer") as TemporalDifferenceQTrainer; // Assertion Assert.AreEqual(originalTrainer.GetHistorySaveData().Count, 1); Assert.AreEqual(cloneTrainer.GetHistorySaveData().Count, 1); Assert.AreEqual(originalTrainer.GetHistorySaveData()[0].Instantiate().State, cloneTrainer.GetHistorySaveData()[0].Instantiate().State); }
public void 遺伝によるコピーで作られたDecisionMakerは完全に同じ動きをする() { // Init parent var parentDecisionMaker = new ReinforcementDecisionMaker(); var actions = new List <IAction>(); for (int i = 0; i < 100; i++) { actions.Add(LocomotionAction.GoStraight(i.ToString())); } parentDecisionMaker.Init(actions); parentDecisionMaker.DecideAction(_dummyStates[0], forceRandom: false, forceMax: true); // Init child var childDecisionMaker = new ReinforcementDecisionMaker(); childDecisionMaker.Init(parentDecisionMaker); // Assertion foreach (var state in _dummyStates) { Assert.AreEqual( parentDecisionMaker.DecideAction(state, forceRandom: false, forceMax: true) .Name, // choose from 100 choice childDecisionMaker.DecideAction(state, forceRandom: false, forceMax: true).Name ); } }
public void デシリアライズ後Restoreされたものは同じDecisionをする() { // Init parent var parentDecisionMaker = new ReinforcementDecisionMaker(); var actions = new List <IAction>(); for (int i = 0; i < 100; i++) { actions.Add(LocomotionAction.GoStraight(i.ToString())); } parentDecisionMaker.Init(actions); parentDecisionMaker.DecideAction(_dummyStates[0], forceRandom: false, forceMax: true); var saveDataClone = EditorTestExtensions.DeepCloneByMsgPack(parentDecisionMaker.Save()); var decisionMakerClone = saveDataClone.Instantiate() as ReinforcementDecisionMaker; // Assertion foreach (var state in _dummyStates) { Assert.AreEqual( parentDecisionMaker.DecideAction(state, forceRandom: false, forceMax: true) .Name, // choose from 100 choice decisionMakerClone.DecideAction(state, forceRandom: false, forceMax: true).Name ); } }
public DummyRemoteDecisionMaker() { Fetcher = new DummyFetcher(); Actions = new List <IAction>() { LocomotionAction.GoStraight("test") }; }
public void 前に餌があるときはちゃんとそちらに向かう() { var decisionMaker = createDummy(); var tmpState = new State(); for (var y = -1; y <= 1; y++) { tmpState[State.BasicKeys.RelativeFoodPosition] = new DenseVector(new double[] { 0.5f, y * 100, 2 }); var action = decisionMaker.DecideAction(tmpState); Assert.AreEqual( LocomotionAction.GoStraight().Name, action.Name ); } }
public void 前にエネルギーがあるときはちゃんとそちらに向かう() { var decisionMaker = createDummy(); var tmpState = TempState(); for (var y = -1; y <= 1; y++) { tmpState[State.BasicKeys.TotalFoodEnergyEachDirection][0] = 1f; var action = decisionMaker.DecideAction(tmpState); Assert.AreEqual( LocomotionAction.GoStraight().Name, action.Name ); } }
public void RewardTest() { //Arrange var action = LocomotionAction.GoStraight("test"); var lastPosition = new Vector3(1, 2, 3); var nowPosition = new Vector3(3, 4, 5); var lastState = new State(); lastState[State.BasicKeys.Position] = new DenseVector(new double[] { lastPosition.x, lastPosition.y, lastPosition.z }); lastState[State.BasicKeys.Rotation] = new DenseVector(new double[] { 0, 0, 0, 0 }); var nowState = new State(); nowState[State.BasicKeys.Position] = new DenseVector(new double[] { nowPosition.x, nowPosition.y, nowPosition.z }); //Act var reward = action.Reward(lastState, nowState); //Assert Assert.AreEqual(reward, 2.0f); }