public class Mean
extends java.lang.Object
This class can repeatedly be fed with data using the put() methods, the resulting values for mean can be queried at any time using getMean().
The high-precision function is based on:
P. M. Neely
Comparison of Several Algorithms for Computation of Means, Standard
Deviations and Correlation Coefficients
Communications of the ACM 9(7), 1966
Modifier and Type | Field and Description |
---|---|
protected double |
n
Weight sum (number of samples).
|
protected double |
sum
Sum of all values.
|
Constructor and Description |
---|
Mean()
Empty constructor
|
Mean(Mean other)
Constructor from other instance
|
Modifier and Type | Method and Description |
---|---|
double |
getCount()
Get the number of points the average is based on.
|
double |
getMean()
Return mean
|
static double |
highPrecision(double... data)
Static helper function, with extra precision
|
static Mean[] |
newArray(int dimensionality)
Create and initialize a new array of MeanVariance
|
static double |
of(double... data)
Static helper function.
|
void |
put(double val)
Add a single value with weight 1.0
|
Mean |
put(double[] vals)
Add values with weight 1.0
|
Mean |
put(double[] vals,
double[] weights)
Add values 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.
|
void |
reset()
Reset the value.
|
java.lang.String |
toString() |
protected double sum
protected double n
public Mean()
public Mean(Mean other)
other
- other instance to copy data from.public void put(double val)
val
- Valuepublic void put(double val, double weight)
val
- dataweight
- weightpublic void put(Mean other)
other
- Data to join withpublic Mean put(double[] vals)
vals
- Valuespublic Mean put(double[] vals, double[] weights)
vals
- Valuespublic double getCount()
public double getMean()
public static Mean[] newArray(int dimensionality)
dimensionality
- Dimensionalitypublic java.lang.String toString()
toString
in class java.lang.Object
public void reset()
public static double of(double... data)
data
- Data to compute the mean for.@Reference(authors="P. M. Neely", title="Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients", booktitle="Communications of the ACM 9(7), 1966", url="https://doi.org/10.1145/365719.365958", bibkey="doi:10.1145/365719.365958") public static double highPrecision(double... data)
data
- Data to compute the mean for.Copyright © 2019 ELKI Development Team. License information.