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
RevLine 
[11732]1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7
[11742]8namespace HeuristicLab.Algorithms.Bandits.BanditPolicies {
[11732]9  // stores information that is relevant for most of the policies
[11742]10  public class DefaultPolicyActionInfo : IBanditPolicyActionInfo {
[11732]11    public double SumReward { get; private set; }
[11742]12    public int Tries { get; private set; }
[11732]13    public double MaxReward { get; private set; }
[11747]14    public double Value {
15      get {
[11832]16        return Tries > 0 ? SumReward / Tries : 0.0;
[11747]17      }
18    }
[11732]19    public DefaultPolicyActionInfo() {
[11832]20      MaxReward = 0.0;
[11732]21    }
22
23    public void UpdateReward(double reward) {
24      Tries++;
25      SumReward += reward;
26      MaxReward = Math.Max(MaxReward, reward);
27    }
[11806]28
[11732]29    public void Reset() {
30      SumReward = 0.0;
31      Tries = 0;
32      MaxReward = 0.0;
33    }
[11742]34
[11832]35    public override string ToString() {
36      return string.Format("{0:F3} {1:F3} {2}", Value, MaxReward, Tries);
37    }
38
[11742]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    }
[11732]47  }
48}
Note: See TracBrowser for help on using the repository browser.