Free cookie consent management tool by TermsFeed Policy Generator

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