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
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 int NumSuccess { get; private set; }
12    public int NumFailure { get; private set; }
[11742]13    public int Tries { get { return NumSuccess + NumFailure; } }
[12893]14    public double MaxReward { get; private set; }
[11747]15    public double Value {
16      get {
[11832]17        return NumSuccess / (double)(Tries);
[11747]18      }
19    }
[11732]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++;
[12893]24      MaxReward = Math.Max(MaxReward, reward);
[11732]25      if (reward > 0) NumSuccess++;
26      else NumFailure++;
27    }
28    public void Reset() {
29      NumSuccess = 0;
30      NumFailure = 0;
[12893]31      MaxReward = double.NegativeInfinity;
32
[11732]33    }
34    public void PrintStats() {
[11832]35      Console.WriteLine("expected value {0,5:F2}", Value);
[11732]36    }
37  }
38}
Note: See TracBrowser for help on using the repository browser.