예제 #1
0
        private double GetPriority(State currentState, State nextState, AIAction action, double reward)
        {
            DiscreteActionValueFunction actionValueFunction = ai.ActionValueFunction;
            double discount        = ai.Discount;
            double bestActionValue = ListUtils.GetHighest(
                actionValueFunction.GetActionValues(nextState),
                (x, y) => x.Value > y.Value).Value;

            return(Math.Abs(reward + discount * bestActionValue - actionValueFunction.GetValue(currentState, action)));
        }
예제 #2
0
 public ExpectedSarsa(DiscreteEnvironment environment,
                      ActionPolicy policy,
                      double stepSize, double discount)
 {
     this.environment    = environment;
     this.policy         = policy;
     this.stepSize       = stepSize;
     this.discount       = discount;
     ActionValueFunction = new DiscreteActionValueFunction(environment);
 }
예제 #3
0
        private void UpdateActionValueFunction(State state, State nextState, AIAction action, double reward)
        {
            double value = ActionValueFunction.GetValue(state, action);
            double policyActionValueSum = 0;

            foreach (var actionValue in ActionValueFunction.GetActionValues(nextState))
            {
                policyActionValueSum += policy.GetProbabilityOfAction(actionValue.Key, nextState, ActionValueFunction) * ActionValueFunction.GetValue(nextState, actionValue.Key);
            }
            double newValue = value + stepSize * (reward + discount * policyActionValueSum - ActionValueFunction.GetValue(state, action));

            ActionValueFunction = ActionValueFunction.UpdateValue(state, action, newValue);
        }
예제 #4
0
 public void Load()
 {
     try
     {
         string JsonString = File.ReadAllText("../../Save/WalkerAIBin.json");
         var    settings   = new JsonSerializerSettings()
         {
             TypeNameHandling = TypeNameHandling.Objects
         };
         DiscreteActionValueFunction actionValueFunction = JsonConvert.DeserializeObject <DiscreteActionValueFunction>(JsonString, settings);
         ai.ActionValueFunction = actionValueFunction;
     }
     catch (Exception) {
         //TODO
     }
 }
예제 #5
0
        public void Load()
        {
            string actionValueFile = "../../Save/WalkerAIBin.json";
            string modelFile       = "../../Save/WalkerModelAIBin.json";

            try
            {
                DiscreteActionValueFunction actionValueFunction = Load <DiscreteActionValueFunction>(actionValueFile);
                Model model = Load <Model>(modelFile);
                sarsa.ActionValueFunction = actionValueFunction;
                ai.ai    = sarsa;
                ai.model = model;
            }
            catch (Exception)
            {
                //TODO
            }
        }
예제 #6
0
 private void InitState(State currentState)
 {
     ActionValueFunction = ActionValueFunction.InitActionValues(currentState);
 }