Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2283: solution reorganization

File size: 1023 bytes
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;
[11747]12    public double Value {
13      get {
[11851]14        return model.Sample(new Random());
[11747]15      }
16    }
[11732]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) {
[11744]24      Tries++;
[11732]25      model.Update(reward);
26    }
27
28    public double SampleExpectedReward(Random random) {
[11851]29      return model.Sample(random);
[11732]30    }
31
32    public void Reset() {
33      Tries = 0;
34      model.Reset();
35    }
36
[11742]37    public override string ToString() {
[11806]38      return string.Format("model {1}", model);
[11742]39    }
[11732]40  }
41}
Note: See TracBrowser for help on using the repository browser.