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 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.