Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Algorithms.Bandits/Policies/IntervalEstimationPolicy.cs @ 12876

Last change on this file since 12876 was 12876, checked in by gkronber, 9 years ago

#2283: implemented first crude version of extreme hunter algorithm in branch

File size: 1.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7using HeuristicLab.Common;
8
9namespace HeuristicLab.Algorithms.Bandits.BanditPolicies {
10  // Powell, Approximate Dynamic Programming, section 12.3.5, page 466,
11  public class IntervalEstimationPolicy : IBanditPolicy {
12    public int SelectAction(Random random, IEnumerable<IBanditPolicyActionInfo> actionInfos) {
13      var myActionInfos = actionInfos.OfType<MeanAndVariancePolicyActionInfo>();
14      double bestQ = double.NegativeInfinity;
15      int totalTries = myActionInfos.Sum(a => a.Tries);
16
17      var bestActions = new List<int>();
18      int aIdx = -1;
19      foreach (var aInfo in myActionInfos) {
20        aIdx++;
21        double q;
22        if (aInfo.Tries == 0) {
23          q = double.PositiveInfinity;
24        } else {
25          double sigmaSqr = aInfo.RewardVariance * 1.0 / aInfo.Tries;
26          q = aInfo.SumReward / aInfo.Tries + 3.0 * Math.Sqrt(sigmaSqr); // 3.0 for around 95th percentile
27        }
28        if (q > bestQ) {
29          bestQ = q;
30          bestActions.Clear();
31          bestActions.Add(aIdx);
32        } else if (q.IsAlmost(bestQ)) {
33          bestActions.Add(aIdx);
34        }
35      }
36      Debug.Assert(bestActions.Any());
37      return bestActions.SelectRandom(random);
38    }
39
40    public IBanditPolicyActionInfo CreateActionInfo() {
41      return new MeanAndVariancePolicyActionInfo();
42    }
43    public override string ToString() {
44      return "IntervalEstimationPolicy(Powell)";
45    }
46  }
47}
Note: See TracBrowser for help on using the repository browser.