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

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

#2283 refactoring

File size: 1.2 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  public class BernoulliPolicyActionInfo : IBanditPolicyActionInfo {
11    public bool Disabled { get { return NumSuccess == -1; } }
12    public int NumSuccess { get; private set; }
13    public int NumFailure { get; private set; }
14    public int Tries { get { return NumSuccess + NumFailure; } }
15    public double Value { get { return NumSuccess / (double)(Tries); } }
16    public void UpdateReward(double reward) {
17      Debug.Assert(!Disabled);
18      //Debug.Assert(reward.IsAlmost(0.0) || reward.IsAlmost(1.0));
19
20      //if (reward.IsAlmost(1.0)) NumSuccess++;
21      if (reward > 0) NumSuccess++;
22      else NumFailure++;
23    }
24    public void Disable() {
25      this.NumSuccess = -1;
26      this.NumFailure = -1;
27    }
28    public void Reset() {
29      NumSuccess = 0;
30      NumFailure = 0;
31    }
32    public void PrintStats() {
33      Console.WriteLine("expected value {0,5:F2} disabled {1}", Value, Disabled);
34    }
35  }
36}
Note: See TracBrowser for help on using the repository browser.