Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/Policies/DefaultPolicyActionInfo.cs @ 11732

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

#2283: refactoring and bug fixes

File size: 1.1 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 {
9  // stores information that is relevant for most of the policies
10  public class DefaultPolicyActionInfo : IPolicyActionInfo {
11    public bool Disabled { get { return Tries == -1; } }
12    public double SumReward { get; private set; }
13    public double MaxReward { get; private set; }
14    public int Tries { get; private set; }
15
16    public DefaultPolicyActionInfo() {
17      MaxReward = double.NegativeInfinity;
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}
Note: See TracBrowser for help on using the repository browser.