Class Distributions

Object
Distributions

public class Distributions extends Object
Collection of convenience methods for mathematical operations dealing with distributions.
Author:
Christoph Hauert
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Ensure non-instantiability with private default constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    bimodality(double[] x)
    Bimodality coefficient of data points x[i] stored in double vector x.
    static double
    bimodality(double[] x, double m1)
    Bimodality coefficient of data points x[i] stored in double vector x with known mean m1.
    static double
    centralMoment(double[] x, double m1, int m)
    m-th centralized moment of data points x[i] stored in double vector x with known mean m1.
    static double
    centralMoment(double[] x, int m)
    m-th centralized moment of data points x[i] stored in double vector x.
    static double
    correlation(double[] x, double[] y)
    Pearson correlation coefficient between data points x[i], y[i] stored in double vectors x and y using one-pass algorithm based on Welford's algorithm.
    static double
    correlation(double[] x, double meanx, double varx, double[] y, double meany, double vary)
    Pearson correlation coefficient between data points x[i], y[i] stored in double vectors x and y with known means meanx, meany and variances varx, vary.
    static double
    covariance(double[] x, double[] y)
    Sample covariance of data points x[i], y[i] stored in double vectors x and y using one-pass algorithm based on Welford's algorithm.
    static double
    covariance(double[] x, double meanx, double[] y, double meany)
    Sample covariance of data points x[i], y[i] stored in double vectors x and y with known means meanx and meany.
    static double
    distrCentralMoment(double[] w, int m)
    m-th central moment of probability distribution with weights w[i] stored in double vector w.
    static double
    distrCentralMoment(double[] w, int m, double m1)
    m-th central moment of probability distribution with weights w[i] stored in double vector w with known mean m1.
    static double
    distrMean(double[] w)
    Mean of probability distribution with weights w[i] stored in double vector w.
    static double
    distrMoment(double[] w, int m)
    m-th moment of probability distribution with weights w[i] stored in double vector w.
    static double
    distrStdev(double[] w)
    Standard deviation of probability distribution with weights w[i] stored in double vector w.
    static double
    distrStdev(double[] w, double m1)
    Standard deviation of probability distribution with weights w[i] stored in double vector w with known mean m1.
    static double
    distrVariance(double[] w)
    Variance of probability distribution with weights w[i] stored in double vector w.
    static double
    distrVariance(double[] w, double m1)
    Variance of probability distribution with weights w[i] stored in double vector w with known mean m1.
    static double
    kurtosis(double[] x)
    Sample kurtosis of data points x[i] stored in double vector x.
    static double
    kurtosis(double[] x, double m1)
    Sample kurtosis of data points x[i] stored in double vector x with known mean m1.
    static double
    mean(double[] x)
    Mean of data points x[i] stored in double vector x.
    static float
    mean(float[] x)
    Mean of data points x[i] stored in float vector x.
    static double
    mean(int[] x)
    Mean of data points x[i] stored in integer vector x.
    static double
    moment(double[] x, int m)
    m-th moment of data points x[i] stored in double vector x.
    static void
    popMeanVar(double[] meanvar, double x)
    Remove sample x from running (or online) mean and variance.
    static void
    pushMeanVar(double[] meanvar, double x)
    Add sample x to running (or online) mean and variance.
    static double
    skewness(double[] x)
    Sample skewness of data points x[i] stored in double vector x.
    static double
    skewness(double[] x, double m1)
    Sample skewness of data points x[i] stored in double vector x with known mean m1.
    static double
    stdev(double[] x)
    (Sample) Standard deviation of data points x[i] stored in double vector x.
    static double
    stdev(double[] x, double mean)
    (Sample) Standard deviation of data points x[i] stored in double vector x.
    static double
    variance(double[] x)
    Sample variance of data points x[i] stored in double vector x using one-pass algorithm based on Welford's algorithm.
    static double
    variance(double[] x, double mean)
    Sample variance of data points x[i] stored in double vector x with known mean.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Distributions

      private Distributions()
      Ensure non-instantiability with private default constructor
  • Method Details

    • variance

      public static double variance(double[] x)
      Sample variance of data points x[i] stored in double vector x using one-pass algorithm based on Welford's algorithm.

      Note: if the mean is known/needed, it's more efficient to use variance(double[], double) instead.

      Parameters:
      x - data vector
      Returns:
      sample variance of x
      See Also:
    • variance

      public static double variance(double[] x, double mean)
      Sample variance of data points x[i] stored in double vector x with known mean. This corresponds to the second pass of a two-pass algorithm.
      Parameters:
      x - data vector
      mean - of x
      Returns:
      sample variance of x
    • stdev

      public static double stdev(double[] x)
      (Sample) Standard deviation of data points x[i] stored in double vector x.
      Parameters:
      x - data vector
      Returns:
      sample standard deviation of x
      See Also:
    • stdev

      public static double stdev(double[] x, double mean)
      (Sample) Standard deviation of data points x[i] stored in double vector x.
      Parameters:
      x - data vector
      mean - of data vector x
      Returns:
      sample standard deviation of x
      See Also:
    • covariance

      public static double covariance(double[] x, double[] y)
      Sample covariance of data points x[i], y[i] stored in double vectors x and y using one-pass algorithm based on Welford's algorithm.

      Note: if the means are known/needed, it's more efficient to use covariance(double[], double, double[], double) instead.

      Parameters:
      x - first data vector
      y - second data vector
      Returns:
      sample covariance of x and y
      See Also:
    • covariance

      public static double covariance(double[] x, double meanx, double[] y, double meany)
      Sample covariance of data points x[i], y[i] stored in double vectors x and y with known means meanx and meany. This corresponds to the second pass of a two-pass algorithm.
      Parameters:
      x - first data vector
      meanx - the mean of x
      y - second data vector
      meany - the mean of y
      Returns:
      sample covariance of x and y
    • correlation

      public static double correlation(double[] x, double[] y)
      Pearson correlation coefficient between data points x[i], y[i] stored in double vectors x and y using one-pass algorithm based on Welford's algorithm.

      Note: if the means and variances are known/needed, it's more efficient to use correlation(double[], double, double, double[], double, double) instead.

      Parameters:
      x - first data vector
      y - second data vector
      Returns:
      Pearson correlation coefficient of x and y
      See Also:
    • correlation

      public static double correlation(double[] x, double meanx, double varx, double[] y, double meany, double vary)
      Pearson correlation coefficient between data points x[i], y[i] stored in double vectors x and y with known means meanx, meany and variances varx, vary.
      Parameters:
      x - first data vector
      meanx - the mean of x
      varx - the variance of x
      y - second data vector
      meany - the mean of y
      vary - the variance of y
      Returns:
      Pearson correlation coefficient of x and y
      See Also:
    • centralMoment

      public static double centralMoment(double[] x, int m)
      m-th centralized moment of data points x[i] stored in double vector x. Central moments are moments about the mean. For example, the second central moment is the variance.
      Parameters:
      x - data vector
      m - moment
      Returns:
      m-th centralized moment of x
    • centralMoment

      public static double centralMoment(double[] x, double m1, int m)
      m-th centralized moment of data points x[i] stored in double vector x with known mean m1. Central moments are moments about the mean. For example, the second central moment is the variance.
      Parameters:
      x - data vector
      m1 - mean of x
      m - moment
      Returns:
      m-th centralized moment of x
    • skewness

      public static double skewness(double[] x)
      Sample skewness of data points x[i] stored in double vector x.
      Parameters:
      x - data vector
      Returns:
      skewness of x
    • skewness

      public static double skewness(double[] x, double m1)
      Sample skewness of data points x[i] stored in double vector x with known mean m1.
      Parameters:
      x - data vector
      m1 - mean ofx
      Returns:
      skewness of x
    • kurtosis

      public static double kurtosis(double[] x)
      Sample kurtosis of data points x[i] stored in double vector x.
      Parameters:
      x - data vector
      Returns:
      kurtosis of x
    • kurtosis

      public static double kurtosis(double[] x, double m1)
      Sample kurtosis of data points x[i] stored in double vector x with known mean m1.
      Parameters:
      x - data vector
      m1 - mean ofx
      Returns:
      kurtosis of x
    • bimodality

      public static double bimodality(double[] x)
      Bimodality coefficient of data points x[i] stored in double vector x. Coefficient lies between 5/9, for uniform and exponential distributions, and 1, for Bernoulli distributions with two distinct values or the sum of two Dirac delta functions. Values >5/9 may indicate bimodal or multimodal distributions.
      Parameters:
      x - data vector
      Returns:
      bimodality coefficient
      See Also:
    • bimodality

      public static double bimodality(double[] x, double m1)
      Bimodality coefficient of data points x[i] stored in double vector x with known mean m1. Coefficient lies between 5/9, for uniform and exponential distributions, and 1, for Bernoulli distributions with two distinct values or the sum of two Dirac delta functions. Values >5/9 may indicate bimodal or multimodal distributions.
      Parameters:
      x - data vector
      m1 - mean ofx
      Returns:
      bimodality coefficient
      See Also:
    • distrMean

      public static double distrMean(double[] w)
      Mean of probability distribution with weights w[i] stored in double vector w. This is the same as the center of mass.

      Note: range of events is assumed to be in [0, 1], i.e. first bin at 0 and last bin at 1.

      Parameters:
      w - probability distribution
      Returns:
      mean of w
    • distrVariance

      public static double distrVariance(double[] w)
      Variance of probability distribution with weights w[i] stored in double vector w. This is the same as the second central moment of the distribution.

      Note: range of events is assumed to be in [0, 1], i.e. first bin at 0 and last bin at 1.

      Parameters:
      w - probability distribution
      Returns:
      variance of w
      See Also:
    • distrVariance

      public static double distrVariance(double[] w, double m1)
      Variance of probability distribution with weights w[i] stored in double vector w with known mean m1. This is the same as the second central moment of the distribution.

      Note: range of events is assumed to be in [0, 1], i.e. first bin at 0 and last bin at 1.

      Parameters:
      w - probability distribution
      m1 - mean of w
      Returns:
      variance of w
      See Also:
    • distrStdev

      public static double distrStdev(double[] w)
      Standard deviation of probability distribution with weights w[i] stored in double vector w.

      Note: range of events is assumed to be in [0, 1], i.e. first bin at 0 and last bin at 1.

      Parameters:
      w - probability distribution
      Returns:
      standard deviation of w
      See Also:
    • distrStdev

      public static double distrStdev(double[] w, double m1)
      Standard deviation of probability distribution with weights w[i] stored in double vector w with known mean m1.

      Note: range of events is assumed to be in [0, 1], i.e. first bin at 0 and last bin at 1.

      Parameters:
      w - probability distribution
      m1 - mean of w
      Returns:
      standard deviation of w
      See Also:
    • distrMoment

      public static double distrMoment(double[] w, int m)
      m-th moment of probability distribution with weights w[i] stored in double vector w.

      Note: range of events is assumed to be in [0, 1], i.e. first bin at 0 and last bin at 1.

      Parameters:
      w - probability distribution
      m - moment
      Returns:
      m-th moment of w
    • distrCentralMoment

      public static double distrCentralMoment(double[] w, int m)
      m-th central moment of probability distribution with weights w[i] stored in double vector w.

      Note: range of events is assumed to be in [0, 1], i.e. first bin at 0 and last bin at 1.

      Parameters:
      w - probability distribution
      m - moment
      Returns:
      m-th moment of w
    • distrCentralMoment

      public static double distrCentralMoment(double[] w, int m, double m1)
      m-th central moment of probability distribution with weights w[i] stored in double vector w with known mean m1.

      Note: range of events is assumed to be in [0, 1], i.e. first bin at 0 and last bin at 1.

      Parameters:
      w - probability distribution
      m - moment
      m1 - mean of w
      Returns:
      m-th moment of w
      See Also:
    • mean

      public static double mean(int[] x)
      Mean of data points x[i] stored in integer vector x.
      Parameters:
      x - data vector
      Returns:
      mean of x
    • mean

      public static float mean(float[] x)
      Mean of data points x[i] stored in float vector x.
      Parameters:
      x - data vector
      Returns:
      mean of x
    • mean

      public static double mean(double[] x)
      Mean of data points x[i] stored in double vector x.
      Parameters:
      x - data vector
      Returns:
      mean of x
    • moment

      public static double moment(double[] x, int m)
      m-th moment of data points x[i] stored in double vector x.
      Parameters:
      x - data vector
      m - moment
      Returns:
      m-th moment of x
    • pushMeanVar

      public static void pushMeanVar(double[] meanvar, double x)
      Add sample x to running (or online) mean and variance. The entries in the meanvar array are [mean, M2, count], where M2 refers to the second central moment such that M2/(count-1) is the sample variance.
      Parameters:
      meanvar - the array with the running values
      x - the sample
      See Also:
    • popMeanVar

      public static void popMeanVar(double[] meanvar, double x)
      Remove sample x from running (or online) mean and variance. The entries in the meanvar array are [mean, M2, count], where M2 refers to the second central moment such that M2/(count-1) is the sample variance.
      Parameters:
      meanvar - the array with the running values
      x - the sample
      See Also: