Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/ActionInfos/ModelPolicyActionInfo.cs @ 11851

Last change on this file since 11851 was 11851, checked in by gkronber, 8 years ago

#2283: solution reorganization

File size: 1023 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.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    public double Value {
13      get {
14        return model.Sample(new Random());
15      }
16    }
17
18    public int Tries { get; private set; }
19    public ModelPolicyActionInfo(IModel model) {
20      this.model = model;
21    }
22
23    public void UpdateReward(double reward) {
24      Tries++;
25      model.Update(reward);
26    }
27
28    public double SampleExpectedReward(Random random) {
29      return model.Sample(random);
30    }
31
32    public void Reset() {
33      Tries = 0;
34      model.Reset();
35    }
36
37    public override string ToString() {
38      return string.Format("model {1}", model);
39    }
40  }
41}
Note: See TracBrowser for help on using the repository browser.