Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Algorithms.Bandits/ActionInfos/BernoulliPolicyActionInfo.cs @ 13777

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

#2283: experiments on grammatical optimization algorithms (maxreward instead of avg reward, ...)

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;
7using HeuristicLab.Common;
8
9namespace HeuristicLab.Algorithms.Bandits.BanditPolicies {
10  public class BernoulliPolicyActionInfo : IBanditPolicyActionInfo {
11    public int NumSuccess { get; private set; }
12    public int NumFailure { get; private set; }
13    public int Tries { get { return NumSuccess + NumFailure; } }
14    public double MaxReward { get; private set; }
15    public double Value {
16      get {
17        return NumSuccess / (double)(Tries);
18      }
19    }
20    public void UpdateReward(double reward) {
21      //Debug.Assert(reward.IsAlmost(0.0) || reward.IsAlmost(1.0));
22
23      //if (reward.IsAlmost(1.0)) NumSuccess++;
24      MaxReward = Math.Max(MaxReward, reward);
25      if (reward > 0) NumSuccess++;
26      else NumFailure++;
27    }
28    public void Reset() {
29      NumSuccess = 0;
30      NumFailure = 0;
31      MaxReward = double.NegativeInfinity;
32
33    }
34    public void PrintStats() {
35      Console.WriteLine("expected value {0,5:F2}", Value);
36    }
37  }
38}
Note: See TracBrowser for help on using the repository browser.