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 double SumReward { get; private set; }
|
---|
[11742] | 12 | public int Tries { get; private set; }
|
---|
[11732] | 13 | public double MaxReward { get; private set; }
|
---|
[11747] | 14 | public double Value {
|
---|
| 15 | get {
|
---|
[11832] | 16 | return Tries > 0 ? SumReward / Tries : 0.0;
|
---|
[11747] | 17 | }
|
---|
| 18 | }
|
---|
[11732] | 19 | public DefaultPolicyActionInfo() {
|
---|
[11832] | 20 | MaxReward = 0.0;
|
---|
[11732] | 21 | }
|
---|
| 22 |
|
---|
| 23 | public void UpdateReward(double reward) {
|
---|
| 24 | Tries++;
|
---|
| 25 | SumReward += reward;
|
---|
| 26 | MaxReward = Math.Max(MaxReward, reward);
|
---|
| 27 | }
|
---|
[11806] | 28 |
|
---|
[11732] | 29 | public void Reset() {
|
---|
| 30 | SumReward = 0.0;
|
---|
| 31 | Tries = 0;
|
---|
| 32 | MaxReward = 0.0;
|
---|
| 33 | }
|
---|
[11742] | 34 |
|
---|
[11832] | 35 | public override string ToString() {
|
---|
| 36 | return string.Format("{0:F3} {1:F3} {2}", Value, MaxReward, Tries);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
[11742] | 39 | public static Func<DefaultPolicyActionInfo, double> AverageReward {
|
---|
| 40 | get {
|
---|
| 41 | return (aInfo) =>
|
---|
| 42 | aInfo.Tries == 0 ?
|
---|
| 43 | double.PositiveInfinity :
|
---|
| 44 | aInfo.SumReward / (double)aInfo.Tries;
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
[11732] | 47 | }
|
---|
| 48 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.