Last change
on this file since 12966 was
12290,
checked in by gkronber, 10 years ago
|
#2283 created a new branch to separate development from aballeit
|
File size:
878 bytes
|
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 |
|
---|
| 8 | namespace HeuristicLab.Algorithms.Bandits {
|
---|
[11849] | 9 | public class OnlineMeanAndVarianceEstimator {
|
---|
[11732] | 10 | public int N { get; private set; }
|
---|
| 11 | public double Sum { get; private set; }
|
---|
| 12 | public double Avg { get; private set; }
|
---|
| 13 | public double Variance { get { return sampleM2 / N; } }
|
---|
| 14 | private double sampleM2;
|
---|
| 15 |
|
---|
| 16 | public void UpdateReward(double reward) {
|
---|
| 17 | N++;
|
---|
| 18 | Sum += reward;
|
---|
| 19 |
|
---|
| 20 | var delta = reward - Avg;
|
---|
[12290] | 21 | //Avg += delta / N;
|
---|
| 22 | // double alpha = 0.01;
|
---|
| 23 | double alpha = 1.0 / N;
|
---|
| 24 | Avg = Avg + alpha * (delta);
|
---|
[11732] | 25 | sampleM2 += delta * (reward - Avg);
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | public void Reset() {
|
---|
| 29 | Sum = 0.0;
|
---|
| 30 | Avg = 0.0;
|
---|
| 31 | N = 0;
|
---|
| 32 | sampleM2 = 0.0;
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.