Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2283: implemented test problems for MCTS

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