Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2283: implemented test problems for MCTS

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