Changeset 11793 for branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/GrammarPolicies/GrammarPolicy.cs
- Timestamp:
- 01/18/15 18:24:58 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/GrammarPolicies/GrammarPolicy.cs
r11770 r11793 8 8 9 9 namespace HeuristicLab.Algorithms.Bandits.GrammarPolicies { 10 // stores: tries, avg reward and max reward for each state 10 // stores: tries, avg reward and max reward for each state (base class for RandomPolicy and TDPolicy 11 11 public abstract class GrammarPolicy : IGrammarPolicy { 12 12 protected Dictionary<string, double> avgReward; 13 13 protected Dictionary<string, int> tries; 14 14 protected Dictionary<string, double> maxReward; 15 pr ivatereadonly bool useCanonicalState;16 pr ivatereadonly IProblem problem;15 protected readonly bool useCanonicalState; 16 protected readonly IProblem problem; 17 17 18 p ublicGrammarPolicy(IProblem problem, bool useCanonicalState = false) {18 protected GrammarPolicy(IProblem problem, bool useCanonicalState = false) { 19 19 this.useCanonicalState = useCanonicalState; 20 20 this.problem = problem; … … 24 24 } 25 25 26 public abstract bool TrySelect(Random random, ReadonlySequence curState, IEnumerable<ReadonlySequence> afterStates, out ReadonlySequence selectedState);26 public abstract bool TrySelect(Random random, string curState, IEnumerable<string> afterStates, out int selectedStateIdx); 27 27 28 public virtual void UpdateReward(IEnumerable< ReadonlySequence> stateTrajectory, double reward) {28 public virtual void UpdateReward(IEnumerable<string> stateTrajectory, double reward) { 29 29 foreach (var state in stateTrajectory) { 30 var s = CanonicalState(state .ToString());30 var s = CanonicalState(state); 31 31 32 32 if (!tries.ContainsKey(s)) tries.Add(s, 0); … … 47 47 } 48 48 49 public double AvgReward( ReadonlySequencestate) {50 var s = CanonicalState(state .ToString());49 public double AvgReward(string state) { 50 var s = CanonicalState(state); 51 51 if (avgReward.ContainsKey(s)) return avgReward[s]; 52 52 else return 0.0; 53 53 } 54 54 55 public double MaxReward( ReadonlySequencestate) {56 var s = CanonicalState(state .ToString());55 public double MaxReward(string state) { 56 var s = CanonicalState(state); 57 57 if (maxReward.ContainsKey(s)) return maxReward[s]; 58 58 else return 0.0; 59 59 } 60 60 61 public virtual int GetTries( ReadonlySequencestate) {62 var s = CanonicalState(state .ToString());61 public virtual int GetTries(string state) { 62 var s = CanonicalState(state); 63 63 if (tries.ContainsKey(s)) return tries[s]; 64 64 else return 0; 65 65 } 66 66 67 public virtual double GetValue( ReadonlySequencestate) {67 public virtual double GetValue(string state) { 68 68 return AvgReward(state); 69 69 }
Note: See TracChangeset
for help on using the changeset viewer.