Class BasicStats.Population

java.lang.Object
org.bzdev.math.stats.BasicStats
org.bzdev.math.stats.BasicStats.Population
All Implemented Interfaces:
Cloneable
Enclosing class:
BasicStats

public static class BasicStats.Population extends BasicStats
BasicStats specialized to compute a population mean and variance.
  • Constructor Details

    • Population

      public Population()
      Constructor. The method BasicStats.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 value
      variance - the variance
      n - 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 for Stream.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:

      
       BasicStats stats = rv.parallelStream(1000000)
         .mapToObj(Double::valueOf)
         .reduce(BasicStats.Population.identity(),
                  BasicStats::add,
                  BasicStats::addAll);
       
      The method mapToObj is needed because the reduce method is a method of Stream but not DoubleStream. 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 class BasicStats
      Returns:
      the correction factor