public class Stat private double mean private double sqMean private do

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public class Stat
{
private double mean = 0.0;
private double sqMean = 0.0;
private double variance = 0.0;
private int count = 0;
public void update(double value)
{
mean = (mean * count + value) / (count + 1);
sqMean = (sqMean * count + value * value) / (count + 1);
count++;
variance = sqMean - (mean * mean);
}
public double getVariance()
{
return variance;
}
public double getStdDev()
{
return Math.sqrt(variance);
}
public double getMean()
{
return mean;
}
public int getCount()
{
return count;
}
public void reset()
{
mean = 0.0;
count = 0;
}
}