Changeset 12290 for branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Algorithms.Bandits/Policies
- Timestamp:
- 04/07/15 14:31:06 (10 years ago)
- Location:
- branches/HeuristicLab.Problems.GrammaticalOptimization-gkr
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Algorithms.Bandits/Policies/BoltzmannExplorationPolicy.cs
r11806 r12290 11 11 public class BoltzmannExplorationPolicy : IBanditPolicy { 12 12 private readonly double beta; 13 private readonly Func<DefaultPolicyActionInfo, double> valueFunction;14 13 15 public BoltzmannExplorationPolicy(double beta) : this(beta, DefaultPolicyActionInfo.AverageReward) { } 16 17 public BoltzmannExplorationPolicy(double beta, Func<DefaultPolicyActionInfo, double> valueFunction) { 14 public BoltzmannExplorationPolicy(double beta) { 18 15 if (beta < 0) throw new ArgumentException(); 19 16 this.beta = beta; 20 this.valueFunction = valueFunction;21 17 } 22 18 public int SelectAction(Random random, IEnumerable<IBanditPolicyActionInfo> actionInfos) { … … 37 33 38 34 var w = from aInfo in myActionInfos 39 select Math.Exp(beta * valueFunction(aInfo));35 select Math.Exp(beta * aInfo.Value); 40 36 41 37 var bestAction = Enumerable.Range(0, myActionInfos.Count()).SampleProportional(random, w); -
branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Algorithms.Bandits/Policies/EpsGreedyPolicy.cs
r11806 r12290 11 11 private readonly double eps; 12 12 private readonly RandomPolicy randomPolicy; 13 private readonly Func<DefaultPolicyActionInfo, double> valueFunction;14 13 private readonly string desc; 15 14 16 15 17 public EpsGreedyPolicy(double eps) : this(eps, DefaultPolicyActionInfo.AverageReward,string.Empty) { }16 public EpsGreedyPolicy(double eps) : this(eps, string.Empty) { } 18 17 19 public EpsGreedyPolicy(double eps, Func<DefaultPolicyActionInfo, double> valueFunction,string desc) {18 public EpsGreedyPolicy(double eps, string desc) { 20 19 this.eps = eps; 21 20 this.randomPolicy = new RandomPolicy(); 22 this.valueFunction = valueFunction;23 21 this.desc = desc; 24 22 } … … 36 34 aIdx++; 37 35 38 var q = valueFunction(aInfo);36 var q = aInfo.Value; 39 37 40 38 if (q > bestQ) {
Note: See TracChangeset
for help on using the changeset viewer.