source: branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/BanditPolicies/DefaultPolicyActionInfo.cs @ 11742

Last change on this file since 11742 was 11742, checked in by gkronber, 6 years ago

#2283 refactoring

File size: 1.4 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  // stores information that is relevant for most of the policies
10  public class DefaultPolicyActionInfo : IBanditPolicyActionInfo {
11    public bool Disabled { get { return Tries == -1; } }
12    public double SumReward { get; private set; }
13    public int Tries { get; private set; }
14    public double MaxReward { get; private set; }
15    public double Value { get { return SumReward / Tries; } }
16    public DefaultPolicyActionInfo() {
17      MaxReward = double.MinValue;
18    }
19
20    public void UpdateReward(double reward) {
21      Debug.Assert(!Disabled);
22
23      Tries++;
24      SumReward += reward;
25      MaxReward = Math.Max(MaxReward, reward);
26    }
27    public void Disable() {
28      this.Tries = -1;
29      this.SumReward = 0.0;
30    }
31    public void Reset() {
32      SumReward = 0.0;
33      Tries = 0;
34      MaxReward = 0.0;
35    }
36    public void PrintStats() {
37      Console.WriteLine("avg reward {0,5:F2} disabled {1}", SumReward / Tries, Disabled);
38    }
39
40    public static Func<DefaultPolicyActionInfo, double> AverageReward {
41      get {
42        return (aInfo) =>
43          aInfo.Tries == 0 ?
44          double.PositiveInfinity :
45          aInfo.SumReward / (double)aInfo.Tries;
46      }
47    }
48  }
49}
Note: See TracBrowser for help on using the repository browser.