Class StatsAccumulator
- java.lang.Object
- 
- com.google.common.math.StatsAccumulator
 
- 
 @Beta @GwtIncompatible public final class StatsAccumulator extends Object A mutable object which accumulates double values and tracks some basic statistics over all the values added so far. The values may be added singly or in groups. This class is not thread safe.- Since:
- 20.0
- Author:
- Pete Gillin, Kevin Bourrillion
 
- 
- 
Constructor SummaryConstructors Constructor Description StatsAccumulator()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(double value)Adds the given value to the dataset.voidaddAll(double... values)Adds the given values to the dataset.voidaddAll(int... values)Adds the given values to the dataset.voidaddAll(long... values)Adds the given values to the dataset.voidaddAll(Stats values)Adds the given statistics to the dataset, as if the individual values used to compute the statistics had been added directly.voidaddAll(StatsAccumulator values)Adds the given statistics to the dataset, as if the individual values used to compute the statistics had been added directly.voidaddAll(Iterable<? extends Number> values)Adds the given values to the dataset.voidaddAll(Iterator<? extends Number> values)Adds the given values to the dataset.voidaddAll(DoubleStream values)Adds the given values to the dataset.voidaddAll(IntStream values)Adds the given values to the dataset.voidaddAll(LongStream values)Adds the given values to the dataset.longcount()Returns the number of values.doublemax()Returns the highest value in the dataset.doublemean()Returns the arithmetic mean of the values.doublemin()Returns the lowest value in the dataset.doublepopulationStandardDeviation()Returns the population standard deviation of the values.doublepopulationVariance()Returns the population variance of the values.doublesampleStandardDeviation()Returns the corrected sample standard deviation of the values.doublesampleVariance()Returns the unbiased sample variance of the values.Statssnapshot()Returns an immutable snapshot of the current statistics.doublesum()Returns the sum of the values.
 
- 
- 
- 
Constructor Detail- 
StatsAccumulatorpublic StatsAccumulator() 
 
- 
 - 
Method Detail- 
addpublic void add(double value) Adds the given value to the dataset.
 - 
addAllpublic void addAll(Iterable<? extends Number> values) Adds the given values to the dataset.- Parameters:
- values- a series of values, which will be converted to- doublevalues (this may cause loss of precision)
 
 - 
addAllpublic void addAll(Iterator<? extends Number> values) Adds the given values to the dataset.- Parameters:
- values- a series of values, which will be converted to- doublevalues (this may cause loss of precision)
 
 - 
addAllpublic void addAll(double... values) Adds the given values to the dataset.- Parameters:
- values- a series of values
 
 - 
addAllpublic void addAll(int... values) Adds the given values to the dataset.- Parameters:
- values- a series of values
 
 - 
addAllpublic void addAll(long... values) Adds the given values to the dataset.- Parameters:
- values- a series of values, which will be converted to- doublevalues (this may cause loss of precision for longs of magnitude over 2^53 (slightly over 9e15))
 
 - 
addAllpublic void addAll(DoubleStream values) Adds the given values to the dataset. The stream will be completely consumed by this method.- Parameters:
- values- a series of values
- Since:
- 28.2
 
 - 
addAllpublic void addAll(IntStream values) Adds the given values to the dataset. The stream will be completely consumed by this method.- Parameters:
- values- a series of values
- Since:
- 28.2
 
 - 
addAllpublic void addAll(LongStream values) Adds the given values to the dataset. The stream will be completely consumed by this method.- Parameters:
- values- a series of values, which will be converted to- doublevalues (this may cause loss of precision for longs of magnitude over 2^53 (slightly over 9e15))
- Since:
- 28.2
 
 - 
addAllpublic void addAll(Stats values) Adds the given statistics to the dataset, as if the individual values used to compute the statistics had been added directly.
 - 
addAllpublic void addAll(StatsAccumulator values) Adds the given statistics to the dataset, as if the individual values used to compute the statistics had been added directly.- Since:
- 28.2
 
 - 
countpublic long count() Returns the number of values.
 - 
meanpublic double mean() Returns the arithmetic mean of the values. The count must be non-zero.If these values are a sample drawn from a population, this is also an unbiased estimator of the arithmetic mean of the population. Non-finite valuesIf the dataset contains Double.NaNthen the result isDouble.NaN. If it contains bothDouble.POSITIVE_INFINITYandDouble.NEGATIVE_INFINITYthen the result isDouble.NaN. If it containsDouble.POSITIVE_INFINITYand finite values only orDouble.POSITIVE_INFINITYonly, the result isDouble.POSITIVE_INFINITY. If it containsDouble.NEGATIVE_INFINITYand finite values only orDouble.NEGATIVE_INFINITYonly, the result isDouble.NEGATIVE_INFINITY.- Throws:
- IllegalStateException- if the dataset is empty
 
 - 
sumpublic final double sum() Returns the sum of the values.Non-finite valuesIf the dataset contains Double.NaNthen the result isDouble.NaN. If it contains bothDouble.POSITIVE_INFINITYandDouble.NEGATIVE_INFINITYthen the result isDouble.NaN. If it containsDouble.POSITIVE_INFINITYand finite values only orDouble.POSITIVE_INFINITYonly, the result isDouble.POSITIVE_INFINITY. If it containsDouble.NEGATIVE_INFINITYand finite values only orDouble.NEGATIVE_INFINITYonly, the result isDouble.NEGATIVE_INFINITY.
 - 
populationVariancepublic final double populationVariance() Returns the population variance of the values. The count must be non-zero.This is guaranteed to return zero if the dataset contains only exactly one finite value. It is not guaranteed to return zero when the dataset consists of the same value multiple times, due to numerical errors. However, it is guaranteed never to return a negative result. Non-finite valuesIf the dataset contains any non-finite values ( Double.POSITIVE_INFINITY,Double.NEGATIVE_INFINITY, orDouble.NaN) then the result isDouble.NaN.- Throws:
- IllegalStateException- if the dataset is empty
 
 - 
populationStandardDeviationpublic final double populationStandardDeviation() Returns the population standard deviation of the values. The count must be non-zero.This is guaranteed to return zero if the dataset contains only exactly one finite value. It is not guaranteed to return zero when the dataset consists of the same value multiple times, due to numerical errors. However, it is guaranteed never to return a negative result. Non-finite valuesIf the dataset contains any non-finite values ( Double.POSITIVE_INFINITY,Double.NEGATIVE_INFINITY, orDouble.NaN) then the result isDouble.NaN.- Throws:
- IllegalStateException- if the dataset is empty
 
 - 
sampleVariancepublic final double sampleVariance() Returns the unbiased sample variance of the values. If this dataset is a sample drawn from a population, this is an unbiased estimator of the population variance of the population. The count must be greater than one.This is not guaranteed to return zero when the dataset consists of the same value multiple times, due to numerical errors. However, it is guaranteed never to return a negative result. Non-finite valuesIf the dataset contains any non-finite values ( Double.POSITIVE_INFINITY,Double.NEGATIVE_INFINITY, orDouble.NaN) then the result isDouble.NaN.- Throws:
- IllegalStateException- if the dataset is empty or contains a single value
 
 - 
sampleStandardDeviationpublic final double sampleStandardDeviation() Returns the corrected sample standard deviation of the values. If this dataset is a sample drawn from a population, this is an estimator of the population standard deviation of the population which is less biased thanpopulationStandardDeviation()(the unbiased estimator depends on the distribution). The count must be greater than one.This is not guaranteed to return zero when the dataset consists of the same value multiple times, due to numerical errors. However, it is guaranteed never to return a negative result. Non-finite valuesIf the dataset contains any non-finite values ( Double.POSITIVE_INFINITY,Double.NEGATIVE_INFINITY, orDouble.NaN) then the result isDouble.NaN.- Throws:
- IllegalStateException- if the dataset is empty or contains a single value
 
 - 
minpublic double min() Returns the lowest value in the dataset. The count must be non-zero.Non-finite valuesIf the dataset contains Double.NaNthen the result isDouble.NaN. If it containsDouble.NEGATIVE_INFINITYand notDouble.NaNthen the result isDouble.NEGATIVE_INFINITY. If it containsDouble.POSITIVE_INFINITYand finite values only then the result is the lowest finite value. If it containsDouble.POSITIVE_INFINITYonly then the result isDouble.POSITIVE_INFINITY.- Throws:
- IllegalStateException- if the dataset is empty
 
 - 
maxpublic double max() Returns the highest value in the dataset. The count must be non-zero.Non-finite valuesIf the dataset contains Double.NaNthen the result isDouble.NaN. If it containsDouble.POSITIVE_INFINITYand notDouble.NaNthen the result isDouble.POSITIVE_INFINITY. If it containsDouble.NEGATIVE_INFINITYand finite values only then the result is the highest finite value. If it containsDouble.NEGATIVE_INFINITYonly then the result isDouble.NEGATIVE_INFINITY.- Throws:
- IllegalStateException- if the dataset is empty
 
 
- 
 
-