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 | // stores information that is relevant for most of the policies
|
---|
[11742] | 10 | public class DefaultPolicyActionInfo : IBanditPolicyActionInfo {
|
---|
[11732] | 11 | public bool Disabled { get { return Tries == -1; } }
|
---|
| 12 | public double SumReward { get; private set; }
|
---|
[11742] | 13 | public int Tries { get; private set; }
|
---|
[11732] | 14 | public double MaxReward { get; private set; }
|
---|
[11742] | 15 | public double Value { get { return SumReward / Tries; } }
|
---|
[11732] | 16 | public DefaultPolicyActionInfo() {
|
---|
[11742] | 17 | MaxReward = double.MinValue;
|
---|
[11732] | 18 | }
|
---|
| 19 |
|
---|
| 20 | public void UpdateReward(double reward) {
|
---|
| 21 | Debug.Assert(!Disabled);
|
---|
| 22 |
|
---|
| 23 | Tries++;
|
---|
| 24 | SumReward += reward;
|
---|
| 25 | MaxReward = Math.Max(MaxReward, reward);
|
---|
| 26 | }
|
---|
| 27 | public void Disable() {
|
---|
| 28 | this.Tries = -1;
|
---|
| 29 | this.SumReward = 0.0;
|
---|
| 30 | }
|
---|
| 31 | public void Reset() {
|
---|
| 32 | SumReward = 0.0;
|
---|
| 33 | Tries = 0;
|
---|
| 34 | MaxReward = 0.0;
|
---|
| 35 | }
|
---|
| 36 | public void PrintStats() {
|
---|
| 37 | Console.WriteLine("avg reward {0,5:F2} disabled {1}", SumReward / Tries, Disabled);
|
---|
| 38 | }
|
---|
[11742] | 39 |
|
---|
| 40 | public static Func<DefaultPolicyActionInfo, double> AverageReward {
|
---|
| 41 | get {
|
---|
| 42 | return (aInfo) =>
|
---|
| 43 | aInfo.Tries == 0 ?
|
---|
| 44 | double.PositiveInfinity :
|
---|
| 45 | aInfo.SumReward / (double)aInfo.Tries;
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
[11732] | 48 | }
|
---|
| 49 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.