|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbcds.tools.RunningStdDev
public class RunningStdDev
Computes a running (or online, or continuous) standard deviation, that is, as a new value is available, it is pushed into an instance of this class and, at any time, the standard deviation can be obtained with a call to stdDev.
This is an adaptation of the C++ code given in http://www.johndcook.com/standard_deviation.html. Another variation is given in http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance.
Unlike the original code, the standard deviation (method devStd) is the population standard deviation, not the sample's. To compensate the possible effects of this decision, both populationVariance and sampleVariance are provided. Beware: The maximum number of items (samples) that can be pushed is 2^31. Beyond that, the returned values will be wrong.
Constructor Summary | |
---|---|
RunningStdDev()
Default constructor. |
Method Summary | |
---|---|
void |
clear()
Resets this object. |
double |
mean()
Returns the mean of the elements pushed up to now. |
double |
populationVariance()
Returns the population's variance. |
void |
push(double x)
Includes x in the computation of the standard deviation and
increments the counter of the number of items pushed. |
double |
sampleVariance()
Returns the sample's variance. |
int |
size()
Returns the number of items pushed up to now. |
double |
stdDev()
Returns the square root of the population's variance. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public RunningStdDev()
Method Detail |
---|
public void clear()
public void push(double x)
x
in the computation of the standard deviation and
increments the counter of the number of items pushed.
public int size()
public double mean()
public double populationVariance()
public double sampleVariance()
public double stdDev()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |