Class MultivariateSummaryStatistics

  • All Implemented Interfaces:
    java.io.Serializable, StatisticalMultivariateSummary
    Direct Known Subclasses:
    SynchronizedMultivariateSummaryStatistics

    public class MultivariateSummaryStatistics
    extends java.lang.Object
    implements StatisticalMultivariateSummary, java.io.Serializable

    Computes summary statistics for a stream of n-tuples added using the addValue method. The data values are not stored in memory, so this class can be used to compute statistics for very large n-tuple streams.

    The StorelessUnivariateStatistic instances used to maintain summary state and compute statistics are configurable via setters. For example, the default implementation for the mean can be overridden by calling setMeanImpl(StorelessUnivariateStatistic[]). Actual parameters to these methods must implement the StorelessUnivariateStatistic interface and configuration must be completed before addValue is called. No configuration is necessary to use the default, commons-math provided implementations.

    To compute statistics for a stream of n-tuples, construct a MultivariateStatistics instance with dimension n and then use addValue(double[]) to add n-tuples. The getXxx methods where Xxx is a statistic return an array of double values, where for i = 0,...,n-1 the ith array element is the value of the given statistic for data range consisting of the ith element of each of the input n-tuples. For example, if addValue is called with actual parameters {0, 1, 2}, then {3, 4, 5} and finally {6, 7, 8}, getSum will return a three-element array with values {0+3+6, 1+4+7, 2+5+8}

    Note: This class is not thread-safe. Use SynchronizedMultivariateSummaryStatistics if concurrent access from multiple threads is required.

    Since:
    1.2
    See Also:
    Serialized Form
    • Constructor Detail

      • MultivariateSummaryStatistics

        public MultivariateSummaryStatistics​(int k,
                                             boolean isCovarianceBiasCorrected)
        Construct a MultivariateSummaryStatistics instance
        Parameters:
        k - dimension of the data
        isCovarianceBiasCorrected - if true, the unbiased sample covariance is computed, otherwise the biased population covariance is computed
    • Method Detail

      • addValue

        public void addValue​(double[] value)
                      throws DimensionMismatchException
        Add an n-tuple to the data
        Parameters:
        value - the n-tuple to add
        Throws:
        DimensionMismatchException - if the length of the array does not match the one used at construction
      • getN

        public long getN()
        Returns the number of available values
        Specified by:
        getN in interface StatisticalMultivariateSummary
        Returns:
        The number of available values
      • getResults

        private double[] getResults​(StorelessUnivariateStatistic[] stats)
        Returns an array of the results of a statistic.
        Parameters:
        stats - univariate statistic array
        Returns:
        results array
      • getSumSq

        public double[] getSumSq()
        Returns an array whose ith entry is the sum of squares of the ith entries of the arrays that have been added using addValue(double[])
        Specified by:
        getSumSq in interface StatisticalMultivariateSummary
        Returns:
        the array of component sums of squares
      • toString

        public java.lang.String toString()
        Generates a text report displaying summary statistics from values that have been added.
        Overrides:
        toString in class java.lang.Object
        Returns:
        String with line feeds displaying statistics
      • append

        private void append​(java.lang.StringBuilder buffer,
                            double[] data,
                            java.lang.String prefix,
                            java.lang.String separator,
                            java.lang.String suffix)
        Append a text representation of an array to a buffer.
        Parameters:
        buffer - buffer to fill
        data - data array
        prefix - text prefix
        separator - elements separator
        suffix - text suffix
      • clear

        public void clear()
        Resets all statistics and storage
      • equals

        public boolean equals​(java.lang.Object object)
        Returns true iff object is a MultivariateSummaryStatistics instance and all statistics have the same values as this.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        object - the object to test equality against.
        Returns:
        true if object equals this
      • hashCode

        public int hashCode()
        Returns hash code based on values of statistics
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        hash code
      • getSumImpl

        public StorelessUnivariateStatistic[] getSumImpl()
        Returns the currently configured Sum implementation
        Returns:
        the StorelessUnivariateStatistic implementing the sum
      • getSumsqImpl

        public StorelessUnivariateStatistic[] getSumsqImpl()
        Returns the currently configured sum of squares implementation
        Returns:
        the StorelessUnivariateStatistic implementing the sum of squares
      • getMinImpl

        public StorelessUnivariateStatistic[] getMinImpl()
        Returns the currently configured minimum implementation
        Returns:
        the StorelessUnivariateStatistic implementing the minimum
      • getMaxImpl

        public StorelessUnivariateStatistic[] getMaxImpl()
        Returns the currently configured maximum implementation
        Returns:
        the StorelessUnivariateStatistic implementing the maximum
      • getSumLogImpl

        public StorelessUnivariateStatistic[] getSumLogImpl()
        Returns the currently configured sum of logs implementation
        Returns:
        the StorelessUnivariateStatistic implementing the log sum
      • getGeoMeanImpl

        public StorelessUnivariateStatistic[] getGeoMeanImpl()
        Returns the currently configured geometric mean implementation
        Returns:
        the StorelessUnivariateStatistic implementing the geometric mean
      • getMeanImpl

        public StorelessUnivariateStatistic[] getMeanImpl()
        Returns the currently configured mean implementation
        Returns:
        the StorelessUnivariateStatistic implementing the mean