Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/BanditPolicies/ModelPolicyActionInfo.cs @ 11742

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

#2283 refactoring

File size: 1.2 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  // uses a statistical model to sample and update posterior distribution p(Reward | Data)
[11742]10  public class ModelPolicyActionInfo : IBanditPolicyActionInfo {
[11732]11    private readonly IModel model;
12    public bool Disabled { get { return Tries == -1; } }
[11742]13    public double Value { get { return model.SampleExpectedReward(new Random()); } }
[11732]14
15    public int Tries { get; private set; }
16    public ModelPolicyActionInfo(IModel model) {
17      this.model = model;
18    }
19
20    public void UpdateReward(double reward) {
21      Debug.Assert(!Disabled);
22      model.Update(reward);
23    }
24
25    public double SampleExpectedReward(Random random) {
26      return model.SampleExpectedReward(random);
27    }
28
29    public void Disable() {
30      this.Tries = -1;
31    }
32
33    public void Reset() {
34      Tries = 0;
35      model.Reset();
36    }
37
38    public void PrintStats() {
39      model.PrintStats();
40    }
[11742]41
42    public override string ToString() {
43      return string.Format("disabled {0} model {1}", Disabled, model);
44    }
[11732]45  }
46}
Note: See TracBrowser for help on using the repository browser.