Rev | Line | |
---|
[11732] | 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 |
|
---|
[11742] | 8 | namespace 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.