Class AggregateSummaryStatistics
- java.lang.Object
-
- org.apache.commons.math4.legacy.stat.descriptive.AggregateSummaryStatistics
-
- All Implemented Interfaces:
StatisticalSummary
public class AggregateSummaryStatistics extends Object implements StatisticalSummary
An aggregator for
SummaryStatisticsfrom several data sets or data set partitions. In its simplest usage mode, the client creates an instance via the zero-argument constructor, then usescreateContributingStatistics()to obtain aSummaryStatisticsfor each individual data set / partition. The per-set statistics objects are used as normal, and at any time the aggregate statistics for all the contributors can be obtained from this object.Clients with specialized requirements can use alternative constructors to control the statistics implementations and initial values used by the contributing and the internal aggregate
SummaryStatisticsobjects.A static
aggregate(Collection)method is also included that computes aggregate statistics directly from a Collection of SummaryStatistics instances.When
createContributingStatistics()is used to create SummaryStatistics instances to be aggregated concurrently, the created instances'SummaryStatistics.addValue(double)methods must synchronize on the aggregating instance maintained by this class. In multithreaded environments, if the functionality provided byaggregate(Collection)is adequate, that method should be used to avoid unnecessary computation and synchronization delays.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description AggregateSummaryStatistics()Initializes a new AggregateSummaryStatistics with default statistics implementations.AggregateSummaryStatistics(SummaryStatistics prototypeStatistics)Initializes a new AggregateSummaryStatistics with the specified statistics object as a prototype for contributing statistics and for the internal aggregate statistics.AggregateSummaryStatistics(SummaryStatistics prototypeStatistics, SummaryStatistics initialStatistics)Initializes a new AggregateSummaryStatistics with the specified statistics object as a prototype for contributing statistics and for the internal aggregate statistics.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StatisticalSummaryValuesaggregate(Collection<? extends StatisticalSummary> statistics)Computes aggregate summary statistics.SummaryStatisticscreateContributingStatistics()Creates and returns aSummaryStatisticswhose data will be aggregated with those of thisAggregateSummaryStatistics.doublegetGeometricMean()Returns the geometric mean of all the aggregated data.doublegetMax()Returns the maximum of the available values.doublegetMean()Returns the arithmetic mean of the available values.doublegetMin()Returns the minimum of the available values.longgetN()Returns the number of available values.doublegetSecondMoment()Returns a statistic related to the Second Central Moment.doublegetStandardDeviation()Returns the standard deviation of the available values.doublegetSum()Returns the sum of the values that have been added to Univariate.StatisticalSummarygetSummary()Return aStatisticalSummaryValuesinstance reporting current aggregate statistics.doublegetSumOfLogs()Returns the sum of the logs of all the aggregated data.doublegetSumsq()Returns the sum of the squares of all the aggregated data.doublegetVariance()Returns the variance of the available values.
-
-
-
Constructor Detail
-
AggregateSummaryStatistics
public AggregateSummaryStatistics()
Initializes a new AggregateSummaryStatistics with default statistics implementations.
-
AggregateSummaryStatistics
public AggregateSummaryStatistics(SummaryStatistics prototypeStatistics) throws NullArgumentException
Initializes a new AggregateSummaryStatistics with the specified statistics object as a prototype for contributing statistics and for the internal aggregate statistics. This provides for customized statistics implementations to be used by contributing and aggregate statistics.- Parameters:
prototypeStatistics- aSummaryStatisticsserving as a prototype both for the internal aggregate statistics and for contributing statistics obtained via thecreateContributingStatistics()method. Being a prototype means that other objects are initialized by copying this object's state. Ifnull, a new, default statistics object is used. Any statistic values in the prototype are propagated to contributing statistics objects and (once) into these aggregate statistics.- Throws:
NullArgumentException- if prototypeStatistics is null- See Also:
createContributingStatistics()
-
AggregateSummaryStatistics
public AggregateSummaryStatistics(SummaryStatistics prototypeStatistics, SummaryStatistics initialStatistics)
Initializes a new AggregateSummaryStatistics with the specified statistics object as a prototype for contributing statistics and for the internal aggregate statistics. This provides for different statistics implementations to be used by contributing and aggregate statistics and for an initial state to be supplied for the aggregate statistics.- Parameters:
prototypeStatistics- aSummaryStatisticsserving as a prototype both for the internal aggregate statistics and for contributing statistics obtained via thecreateContributingStatistics()method. Being a prototype means that other objects are initialized by copying this object's state. Ifnull, a new, default statistics object is used. Any statistic values in the prototype are propagated to contributing statistics objects, but not into these aggregate statistics.initialStatistics- aSummaryStatisticsto serve as the internal aggregate statistics object. Ifnull, a new, default statistics object is used.- See Also:
createContributingStatistics()
-
-
Method Detail
-
getMax
public double getMax()
Returns the maximum of the available values.. This version returns the maximum over all the aggregated data.- Specified by:
getMaxin interfaceStatisticalSummary- Returns:
- The max or Double.NaN if no values have been added.
- See Also:
StatisticalSummary.getMax()
-
getMean
public double getMean()
Returns the arithmetic mean of the available values.. This version returns the mean of all the aggregated data.- Specified by:
getMeanin interfaceStatisticalSummary- Returns:
- The mean or Double.NaN if no values have been added.
- See Also:
StatisticalSummary.getMean()
-
getMin
public double getMin()
Returns the minimum of the available values.. This version returns the minimum over all the aggregated data.- Specified by:
getMinin interfaceStatisticalSummary- Returns:
- The min or Double.NaN if no values have been added.
- See Also:
StatisticalSummary.getMin()
-
getN
public long getN()
Returns the number of available values.. This version returns a count of all the aggregated data.- Specified by:
getNin interfaceStatisticalSummary- Returns:
- The number of available values
- See Also:
StatisticalSummary.getN()
-
getStandardDeviation
public double getStandardDeviation()
Returns the standard deviation of the available values.. This version returns the standard deviation of all the aggregated data.- Specified by:
getStandardDeviationin interfaceStatisticalSummary- Returns:
- The standard deviation, Double.NaN if no values have been added or 0.0 for a single value set.
- See Also:
StatisticalSummary.getStandardDeviation()
-
getSum
public double getSum()
Returns the sum of the values that have been added to Univariate.. This version returns a sum of all the aggregated data.- Specified by:
getSumin interfaceStatisticalSummary- Returns:
- The sum or Double.NaN if no values have been added
- See Also:
StatisticalSummary.getSum()
-
getVariance
public double getVariance()
Returns the variance of the available values.. This version returns the variance of all the aggregated data.- Specified by:
getVariancein interfaceStatisticalSummary- Returns:
- The variance, Double.NaN if no values have been added or 0.0 for a single value set.
- See Also:
StatisticalSummary.getVariance()
-
getSumOfLogs
public double getSumOfLogs()
Returns the sum of the logs of all the aggregated data.- Returns:
- the sum of logs
- See Also:
SummaryStatistics.getSumOfLogs()
-
getGeometricMean
public double getGeometricMean()
Returns the geometric mean of all the aggregated data.- Returns:
- the geometric mean
- See Also:
SummaryStatistics.getGeometricMean()
-
getSumsq
public double getSumsq()
Returns the sum of the squares of all the aggregated data.- Returns:
- The sum of squares
- See Also:
SummaryStatistics.getSumsq()
-
getSecondMoment
public double getSecondMoment()
Returns a statistic related to the Second Central Moment. Specifically, what is returned is the sum of squared deviations from the sample mean among the all of the aggregated data.- Returns:
- second central moment statistic
- See Also:
SummaryStatistics.getSecondMoment()
-
getSummary
public StatisticalSummary getSummary()
Return aStatisticalSummaryValuesinstance reporting current aggregate statistics.- Returns:
- Current values of aggregate statistics
-
createContributingStatistics
public SummaryStatistics createContributingStatistics()
Creates and returns aSummaryStatisticswhose data will be aggregated with those of thisAggregateSummaryStatistics.- Returns:
- a
SummaryStatisticswhose data will be aggregated with those of thisAggregateSummaryStatistics. The initial state is a copy of the configured prototype statistics.
-
aggregate
public static StatisticalSummaryValues aggregate(Collection<? extends StatisticalSummary> statistics)
Computes aggregate summary statistics. This method can be used to combine statistics computed over partitions or subsamples - i.e., the StatisticalSummaryValues returned should contain the same values that would have been obtained by computing a single StatisticalSummary over the combined dataset.Returns null if the collection is empty or null.
- Parameters:
statistics- collection of SummaryStatistics to aggregate- Returns:
- summary statistics for the combined dataset
-
-