Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/BanditPolicies/MeanAndVariancePolicyActionInfo.cs @ 11792

Last change on this file since 11792 was 11747, checked in by gkronber, 10 years ago

#2283: implemented test problems for MCTS

File size: 1.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7
8namespace HeuristicLab.Algorithms.Bandits.BanditPolicies {
9  public class MeanAndVariancePolicyActionInfo : IBanditPolicyActionInfo {
10    private bool disabled;
11    public bool Disabled { get { return disabled; } }
12    private OnlineMeanAndVarianceEstimator estimator = new OnlineMeanAndVarianceEstimator();
13    private double knownValue;
14    public int Tries { get { return estimator.N; } }
15    public double SumReward { get { return estimator.Sum; } }
16    public double AvgReward { get { return estimator.Avg; } }
17    public double RewardVariance { get { return estimator.Variance; } }
18    public double Value {
19      get {
20        if (disabled) return knownValue;
21        else
22          return AvgReward;
23      }
24    }
25
26    public void UpdateReward(double reward) {
27      Debug.Assert(!Disabled);
28      estimator.UpdateReward(reward);
29    }
30
31    public void Disable(double reward) {
32      disabled = true;
33      this.knownValue = reward;
34    }
35
36    public void Reset() {
37      disabled = false;
38      knownValue = 0.0;
39      estimator.Reset();
40    }
41
42    public void PrintStats() {
43      Console.WriteLine("avg reward {0,5:F2} disabled {1}", AvgReward, Disabled);
44    }
45  }
46}
Note: See TracBrowser for help on using the repository browser.