source: branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/Policies/ModelPolicyActionInfo.cs @ 11732

Last change on this file since 11732 was 11732, checked in by gkronber, 5 years ago

#2283: refactoring and bug fixes

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