Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/ActionInfos/DefaultPolicyActionInfo.cs @ 12547

Last change on this file since 12547 was 11849, checked in by gkronber, 10 years ago

#2283: solution reorganization

File size: 1.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7
8namespace HeuristicLab.Algorithms.Bandits.BanditPolicies {
9  // stores information that is relevant for most of the policies
10  public class DefaultPolicyActionInfo : IBanditPolicyActionInfo {
11    public double SumReward { get; private set; }
12    public int Tries { get; private set; }
13    public double MaxReward { get; private set; }
14    public double Value {
15      get {
16        return Tries > 0 ? SumReward / Tries : 0.0;
17      }
18    }
19    public DefaultPolicyActionInfo() {
20      MaxReward = 0.0;
21    }
22
23    public void UpdateReward(double reward) {
24      Tries++;
25      SumReward += reward;
26      MaxReward = Math.Max(MaxReward, reward);
27    }
28
29    public void Reset() {
30      SumReward = 0.0;
31      Tries = 0;
32      MaxReward = 0.0;
33    }
34
35    public override string ToString() {
36      return string.Format("{0:F3} {1:F3} {2}", Value, MaxReward, Tries);
37    }
38
39    public static Func<DefaultPolicyActionInfo, double> AverageReward {
40      get {
41        return (aInfo) =>
42          aInfo.Tries == 0 ?
43          double.PositiveInfinity :
44          aInfo.SumReward / (double)aInfo.Tries;
45      }
46    }
47  }
48}
Note: See TracBrowser for help on using the repository browser.