Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Algorithms.Bandits/ActionInfos/ModelPolicyActionInfo.cs @ 13042

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

#2283: experiments on grammatical optimization algorithms (maxreward instead of avg reward, ...)

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