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

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.math.Mean
Direct Known Subclasses:
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 Mean
extends Object

Compute the mean using a numerically stable online algorithm. This class can repeatedly be fed with data using the add() methods, the resulting values for mean can be queried at any time using getMean(). 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 mean
          Mean of values
protected  double wsum
          Weight sum (number of samples)
 
Constructor Summary
Mean()
          Empty constructor
Mean(Mean other)
          Constructor from other instance
 
Method Summary
 double getCount()
          Get the number of points the average is based on.
 double getMean()
          Return mean
static Mean[] newArray(int dimensionality)
          Create and initialize a new array of MeanVariance
 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

mean

protected double mean
Mean of values


wsum

protected double wsum
Weight sum (number of samples)

Constructor Detail

Mean

public Mean()
Empty constructor


Mean

public Mean(Mean 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

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

Parameters:
val - data
weight - weight

put

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

Parameters:
other - Data to join with

getCount

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

Returns:
number of data points

getMean

public double getMean()
Return mean

Returns:
mean

newArray

public static Mean[] 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 Object

Release 0.4.0 (2011-09-20_1324)