Free cookie consent management tool by TermsFeed Policy Generator

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, 9 years ago

#2283 refactoring

File size: 1.2 KB
RevLine 
[11732]1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7using HeuristicLab.Common;
8
[11742]9namespace HeuristicLab.Algorithms.Bandits.BanditPolicies {
10  public class BernoulliPolicyActionInfo : IBanditPolicyActionInfo {
[11732]11    public bool Disabled { get { return NumSuccess == -1; } }
12    public int NumSuccess { get; private set; }
13    public int NumFailure { get; private set; }
[11742]14    public int Tries { get { return NumSuccess + NumFailure; } }
15    public double Value { get { return NumSuccess / (double)(Tries); } }
[11732]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() {
[11742]33      Console.WriteLine("expected value {0,5:F2} disabled {1}", Value, Disabled);
[11732]34    }
35  }
36}
Note: See TracBrowser for help on using the repository browser.