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 | public class MeanAndVariancePolicyActionInfo : IBanditPolicyActionInfo {
|
---|
10 | private bool disabled;
|
---|
11 | public bool Disabled { get { return disabled; } }
|
---|
12 | private OnlineMeanAndVarianceEstimator estimator = new OnlineMeanAndVarianceEstimator();
|
---|
13 | private double knownValue;
|
---|
14 | public int Tries { get { return estimator.N; } }
|
---|
15 | public double SumReward { get { return estimator.Sum; } }
|
---|
16 | public double AvgReward { get { return estimator.Avg; } }
|
---|
17 | public double RewardVariance { get { return estimator.Variance; } }
|
---|
18 | public double Value {
|
---|
19 | get {
|
---|
20 | if (disabled) return knownValue;
|
---|
21 | else
|
---|
22 | return AvgReward;
|
---|
23 | }
|
---|
24 | }
|
---|
25 |
|
---|
26 | public void UpdateReward(double reward) {
|
---|
27 | Debug.Assert(!Disabled);
|
---|
28 | estimator.UpdateReward(reward);
|
---|
29 | }
|
---|
30 |
|
---|
31 | public void Disable(double reward) {
|
---|
32 | disabled = true;
|
---|
33 | this.knownValue = reward;
|
---|
34 | }
|
---|
35 |
|
---|
36 | public void Reset() {
|
---|
37 | disabled = false;
|
---|
38 | knownValue = 0.0;
|
---|
39 | estimator.Reset();
|
---|
40 | }
|
---|
41 |
|
---|
42 | public void PrintStats() {
|
---|
43 | Console.WriteLine("avg reward {0,5:F2} disabled {1}", AvgReward, Disabled);
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.