Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Diagnostics;
|
---|
4 | using System.Linq;
|
---|
5 | using System.Text;
|
---|
6 | using System.Threading.Tasks;
|
---|
7 |
|
---|
8 | namespace 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 bool Disabled { get { return Tries == -1; } }
|
---|
13 | public double Value { get { return model.SampleExpectedReward(new Random()); } }
|
---|
14 |
|
---|
15 | public int Tries { get; private set; }
|
---|
16 | public ModelPolicyActionInfo(IModel model) {
|
---|
17 | this.model = model;
|
---|
18 | }
|
---|
19 |
|
---|
20 | public void UpdateReward(double reward) {
|
---|
21 | Debug.Assert(!Disabled);
|
---|
22 | model.Update(reward);
|
---|
23 | }
|
---|
24 |
|
---|
25 | public double SampleExpectedReward(Random random) {
|
---|
26 | return model.SampleExpectedReward(random);
|
---|
27 | }
|
---|
28 |
|
---|
29 | public void Disable() {
|
---|
30 | this.Tries = -1;
|
---|
31 | }
|
---|
32 |
|
---|
33 | public void Reset() {
|
---|
34 | Tries = 0;
|
---|
35 | model.Reset();
|
---|
36 | }
|
---|
37 |
|
---|
38 | public void PrintStats() {
|
---|
39 | model.PrintStats();
|
---|
40 | }
|
---|
41 |
|
---|
42 | public override string ToString() {
|
---|
43 | return string.Format("disabled {0} model {1}", Disabled, model);
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.