Exemplo n.º 1
0
 public QLearning(IQLearningModel Model, List <IQState> States, List <IQAction> Actions, Decimal Gamma)
     : base(Model, States, Actions, Gamma)
 {
     foreach (IQState state in States)
     {
         foreach (IQAction action in Actions)
         {
             if (!this.NumQ.ContainsKey(state))
             {
                 this.NumQ.Add(state, new Dictionary <IQAction, int>());
             }
             this.NumQ[state].Add(action, 0);
         }
     }
 }
Exemplo n.º 2
0
        public QLearningBase(IQLearningModel Model, List <IQState> States, List <IQAction> Actions, Decimal Gamma)
        {
            this.Model = Model;

            this.States  = States;
            this.Actions = Actions;
            this.Gamma   = Gamma;

            foreach (IQState state in States)
            {
                foreach (IQAction action in Actions)
                {
                    if (!this.QValues.ContainsKey(state))
                    {
                        this.QValues.Add(state, new Dictionary <IQAction, decimal>());
                    }
                    this.QValues[state].Add(action, this.InitialQ);
                }
            }
        }
        public DelayedQLearning(IQLearningModel Model, List <IQState> States, List <IQAction> Actions, Decimal Gamma, Decimal Epsilon, Decimal Delta)
            : base(Model, States, Actions, Gamma)
        {
            this.Epsilon = Epsilon;
            this.Delta   = Delta;

            foreach (IQState state in States)
            {
                foreach (IQAction action in Actions)
                {
                    if (!this.AttemptedUpdates.ContainsKey(state))
                    {
                        this.AttemptedUpdates.Add(state, new Dictionary <IQAction, decimal>());
                    }
                    this.AttemptedUpdates[state].Add(action, 0.0M);
                    if (!this.NumSamplesInNextUpdate.ContainsKey(state))
                    {
                        this.NumSamplesInNextUpdate.Add(state, new Dictionary <IQAction, int>());
                    }
                    this.NumSamplesInNextUpdate[state].Add(action, 0);
                    if (!this.TimeOfLastAttemptedUpdate.ContainsKey(state))
                    {
                        this.TimeOfLastAttemptedUpdate.Add(state, new Dictionary <IQAction, int>());
                    }
                    this.TimeOfLastAttemptedUpdate[state].Add(action, 0);
                    if (!this.LearnFlags.ContainsKey(state))
                    {
                        this.LearnFlags.Add(state, new Dictionary <IQAction, bool>());
                    }
                    this.LearnFlags[state].Add(action, true);
                }
            }

            decimal epsilon1 = GetEpsilon1(Epsilon, Gamma);;

            this.Epsilon1         = epsilon1;
            this.NumSamplesNeeded = GetNumSamplesNeeded(Gamma, epsilon1, States.Count, Actions.Count, Delta);
        }