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 | using HeuristicLab.Common;
|
---|
| 8 |
|
---|
[11742] | 9 | namespace HeuristicLab.Algorithms.Bandits.BanditPolicies {
|
---|
| 10 | public class BernoulliPolicyActionInfo : IBanditPolicyActionInfo {
|
---|
[11732] | 11 | public int NumSuccess { get; private set; }
|
---|
| 12 | public int NumFailure { get; private set; }
|
---|
[11742] | 13 | public int Tries { get { return NumSuccess + NumFailure; } }
|
---|
[11747] | 14 | public double Value {
|
---|
| 15 | get {
|
---|
[11832] | 16 | return NumSuccess / (double)(Tries);
|
---|
[11747] | 17 | }
|
---|
| 18 | }
|
---|
[11732] | 19 | public void UpdateReward(double reward) {
|
---|
| 20 | //Debug.Assert(reward.IsAlmost(0.0) || reward.IsAlmost(1.0));
|
---|
| 21 |
|
---|
| 22 | //if (reward.IsAlmost(1.0)) NumSuccess++;
|
---|
| 23 | if (reward > 0) NumSuccess++;
|
---|
| 24 | else NumFailure++;
|
---|
| 25 | }
|
---|
| 26 | public void Reset() {
|
---|
| 27 | NumSuccess = 0;
|
---|
| 28 | NumFailure = 0;
|
---|
| 29 | }
|
---|
| 30 | public void PrintStats() {
|
---|
[11832] | 31 | Console.WriteLine("expected value {0,5:F2}", Value);
|
---|
[11732] | 32 | }
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.