Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Common/OnlineMeanAndVarianceEstimator.cs @ 12747

Last change on this file since 12747 was 11849, checked in by gkronber, 10 years ago

#2283: solution reorganization

File size: 778 bytes
Line 
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7
8namespace HeuristicLab.Algorithms.Bandits {
9  public class OnlineMeanAndVarianceEstimator {
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;
21      Avg += delta / N;
22      sampleM2 += delta * (reward - Avg);
23    }
24
25    public void Reset() {
26      Sum = 0.0;
27      Avg = 0.0;
28      N = 0;
29      sampleM2 = 0.0;
30    }
31  }
32}
Note: See TracBrowser for help on using the repository browser.