java.lang.Object
org.bzdev.math.stats.BasicStats
org.bzdev.math.stats.BasicStats.Population
- All Implemented Interfaces:
Cloneable
- Enclosing class:
- BasicStats
BasicStats specialized to compute a population mean and variance.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.bzdev.math.stats.BasicStats
BasicStats.Population, BasicStats.Sample
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.Population
(double[] array) Constructor given an array containing all the data used to compute a mean and variancePopulation
(double mean, double variance, long n) Constructor given a mean, variance, and data-set size. -
Method Summary
Modifier and TypeMethodDescriptionprotected double
Get the correction factor.static final org.bzdev.math.stats.BasicStats.Population.Identity
identity()
Get an instance of Population that serves as an identity forStream.reduce(Object,BiFunction,BinaryOperator)
.Methods inherited from class org.bzdev.math.stats.BasicStats
add, addAll, clone, getMean, getSDev, getVariance, mean, median, size, trimmedMean, trimmedMean
-
Constructor Details
-
Population
public Population()Constructor. The methodBasicStats.add(double)
must be called repeatedly to provide the data used to compute the covariance matrix and mean array. -
Population
public Population(double mean, double variance, long n) Constructor given a mean, variance, and data-set size.- Parameters:
mean
- the mean valuevariance
- the variancen
- the data-set size
-
Population
public Population(double[] array) Constructor given an array containing all the data used to compute a mean and variance- Parameters:
array
- an array, each component of which is a value to add to the computation
-
-
Method Details
-
identity
public static final org.bzdev.math.stats.BasicStats.Population.Identity identity()Get an instance of Population that serves as an identity forStream.reduce(Object,BiFunction,BinaryOperator)
. An identity implementation will not store any data, but will return an appropriate instance of BasicStats that does store the data added, but with no history of previously added values.If rv is a random variable that returns a stream of double values, the following example shows a typical use of this method:
The method mapToObj is needed because the reduce method is a method ofBasicStats stats = rv.parallelStream(1000000) .mapToObj(Double::valueOf) .reduce(BasicStats.Population.identity(), BasicStats::add, BasicStats::addAll);
Stream
but notDoubleStream
. When used with a parallel stream, the mapToObj method;'s argument will typically be a lambda expression that peforms significantly more compuation: otherwise the cost of threading can result in the parallel version performing worse than the sequential version.- Returns:
- an instance of BasicStat that can be used as an idenity in a "reduce" method.
-
getCorrection
protected double getCorrection()Description copied from class:BasicStats
Get the correction factor. The variance that is computed will be scaled by a correction factor. This factor should be 1.0 when the data represents a total population. For a sample of a population, the factor is m/(m-1) where m is the sample size (the number of data points).- Specified by:
getCorrection
in classBasicStats
- Returns:
- the correction factor
-