de.lmu.ifi.dbs.elki.math
Class MeanVariance

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.math.Mean
      extended by de.lmu.ifi.dbs.elki.math.MeanVariance

@Reference(authors="B. P. Welford",
           title="Note on a method for calculating corrected sums of squares and products",
           booktitle="Technometrics 4(3)")
public class MeanVariance
extends Mean

Do some simple statistics (mean, variance) using a numerically stable online algorithm. This class can repeatedly be fed with data using the add() methods, the resulting values for mean and average can be queried at any time using getMean() and getSampleVariance(). Make sure you have understood variance correctly when using getNaiveVariance() - since this class is fed with samples and estimates the mean from the samples, getSampleVariance() is the proper formula. Trivial code, but replicated a lot. The class is final so it should come at low cost. Related Literature:

B. P. Welford
Note on a method for calculating corrected sums of squares and products
in: Technometrics 4(3)

D.H.D. West
Updating Mean and Variance Estimates: An Improved Method
In: Communications of the ACM, Volume 22 Issue 9


Field Summary
protected  double nvar
          nVariance
 
Fields inherited from class de.lmu.ifi.dbs.elki.math.Mean
mean, wsum
 
Constructor Summary
MeanVariance()
          Empty constructor
MeanVariance(MeanVariance other)
          Constructor from other instance
 
Method Summary
 double denormalizeValue(double val)
          Return the unnormalized value (centered at the mean, distance normalized by standard deviation)
 double getCount()
          Get the number of points the average is based on.
 double getMean()
          Return mean
 double getNaiveStddev()
          Return standard deviation using the non-sample variance Note: usually, you should be using getSampleStddev() instead!
 double getNaiveVariance()
          Return the naive variance (not taking sampling into account) Note: usually, you should be using getSampleVariance() instead!
 double getSampleStddev()
          Return standard deviation
 double getSampleVariance()
          Return sample variance.
static MeanVariance[] newArray(int dimensionality)
          Create and initialize a new array of MeanVariance
 double normalizeValue(double val)
          Return the normalized value (centered at the mean, distance normalized by standard deviation)
 void put(double val)
          Add a single value with weight 1.0
 void put(double val, double weight)
          Add data with a given weight.
 void put(Mean other)
          Join the data of another MeanVariance instance.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nvar

protected double nvar
nVariance

Constructor Detail

MeanVariance

public MeanVariance()
Empty constructor


MeanVariance

public MeanVariance(MeanVariance other)
Constructor from other instance

Parameters:
other - other instance to copy data from.
Method Detail

put

public void put(double val)
Add a single value with weight 1.0

Overrides:
put in class Mean
Parameters:
val - Value

put

public void put(double val,
                double weight)
Add data with a given weight. See also: D.H.D. West
Updating Mean and Variance Estimates: An Improved Method

Overrides:
put in class Mean
Parameters:
val - data
weight - weight

put

public void put(Mean other)
Join the data of another MeanVariance instance.

Overrides:
put in class Mean
Parameters:
other - Data to join with

getCount

public double getCount()
Get the number of points the average is based on.

Overrides:
getCount in class Mean
Returns:
number of data points

getMean

public double getMean()
Return mean

Overrides:
getMean in class Mean
Returns:
mean

getNaiveVariance

public double getNaiveVariance()
Return the naive variance (not taking sampling into account) Note: usually, you should be using getSampleVariance() instead!

Returns:
variance

getSampleVariance

public double getSampleVariance()
Return sample variance.

Returns:
sample variance

getNaiveStddev

public double getNaiveStddev()
Return standard deviation using the non-sample variance Note: usually, you should be using getSampleStddev() instead!

Returns:
stddev

getSampleStddev

public double getSampleStddev()
Return standard deviation

Returns:
stddev

normalizeValue

public double normalizeValue(double val)
Return the normalized value (centered at the mean, distance normalized by standard deviation)

Parameters:
val - original value
Returns:
normalized value

denormalizeValue

public double denormalizeValue(double val)
Return the unnormalized value (centered at the mean, distance normalized by standard deviation)

Parameters:
val - normalized value
Returns:
de-normalized value

newArray

public static MeanVariance[] newArray(int dimensionality)
Create and initialize a new array of MeanVariance

Parameters:
dimensionality - Dimensionality
Returns:
New and initialized Array

toString

public String toString()
Overrides:
toString in class Mean

Release 0.4.0 (2011-09-20_1324)