public class DoubleArrayStat extends DoubleArrayMath
Modifier | Constructor and Description |
---|---|
protected |
DoubleArrayStat() |
Modifier and Type | Method and Description |
---|---|
protected static int |
_nonZeroLength(double[] array,
java.lang.String methodName)
Throw an exception if the array is null or length 0.
|
static double[] |
autoCorrelation(double[] x,
int N,
int startLag,
int endLag)
Return a new array that is the auto-correlation of the
argument array, starting and ending at user-specified lag values.
|
static double |
autoCorrelationAt(double[] x,
int N,
int lag)
Return the auto-correlation of an array at a certain lag value,
summing over a certain number of samples
defined by :
Rxx[d] = sum of i = 0 to N - 1 of x[i] * x[i + d]
N must be non-negative, but large numbers are ok because this
routine will not overrun reading of the arrays.
|
static double[] |
crossCorrelation(double[] x,
double[] y,
int N,
int startLag,
int endLag)
Return a new array that is the cross-correlation of the two
argument arrays, starting and ending at user-specified lag values.
|
static double |
crossCorrelationAt(double[] x,
double[] y,
int N,
int lag)
Return the cross-correlation of two arrays at a certain lag value.
|
static double |
entropy(double[] p)
Given an array of probabilities, treated as a probability mass
function (pmf), calculate the entropy (in bits).
|
static double |
geometricMean(double[] array)
Return the geometric mean of the elements in the array.
|
static double |
max(double[] array)
Return the maximum value in the array.
|
static java.lang.Object[] |
maxAndIndex(double[] array)
Return the maximum value of the array and the index at which the
maximum occurs in the array.
|
static double |
mean(double[] array)
Return the arithmetic mean of the elements in the array.
|
static double |
min(double[] array)
Return the minimum value in the array.
|
static java.lang.Object[] |
minAndIndex(double[] array)
Return the minimum value of the array and the index at which the
minimum occurs in the array.
|
static double |
productOfElements(double[] array)
Return the product of all of the elements in the array.
|
static double[] |
randomBernoulli(double p,
int N)
Return a new array of Bernoulli random variables with a given
probability of success p.
|
static double[] |
randomExponential(double lambda,
int N)
Return a new array of exponentially distributed doubles with parameter
lambda.
|
static double[] |
randomGaussian(double mean,
double standardDeviation,
int N)
Return a new array of Gaussian distributed doubles with a given
mean and standard deviation.
|
static double[] |
randomPoisson(double mean,
int N)
Return a new array of Poisson random variables (as doubles) with
a given mean.
|
static double[] |
randomUniform(double a,
double b,
int N)
Return a new array of uniformly distributed doubles ranging from
a to b.
|
static double |
relativeEntropy(double[] p,
double[] q)
Given two array's of probabilities, calculate the relative entropy
aka Kullback Leibler distance, D(p || q), (in bits) between the
two probability mass functions.
|
static double |
standardDeviation(double[] array)
Return the standard deviation of the elements in the array.
|
static double |
standardDeviation(double[] array,
boolean sample)
Return the standard deviation of the elements in the array.
|
static double |
sumOfElements(double[] array)
Return the sum of all of the elements in the array.
|
static double |
variance(double[] array)
Return the variance of the elements in the array, assuming
sufficient statistics.
|
static double |
variance(double[] array,
boolean sample)
Return the variance of the elements in the array, assuming
sufficient statistics.
|
_commonLength, add, add, allocCopy, append, append, applyBinaryOperation, applyBinaryOperation, applyBinaryOperation, applyUnaryOperation, divide, divideElements, dotProduct, l2norm, limit, modulo, multiply, multiply, negative, normalize, padMiddle, resize, resize, scale, subtract, sum, sumOfSquares, toComplexArray, toFloatArray, toIntegerArray, toLongArray, toString, toString, within, within
public static final double[] autoCorrelation(double[] x, int N, int startLag, int endLag)
x
- An array of doubles.N
- An integer indicating the number of samples to sum over.startLag
- An int indicating at which lag to start (may be
negative).endLag
- An int indicating at which lag to end.public static double autoCorrelationAt(double[] x, int N, int lag)
x
- An array of doubles.N
- An integer indicating the number of samples to sum over.lag
- An integer indicating the lag value (may be negative).public static final double[] crossCorrelation(double[] x, double[] y, int N, int startLag, int endLag)
x
- The first array of doubles.y
- The second array of doubles.N
- An integer indicating the number of samples to sum over.startLag
- An int indicating at which lag to start (may be
negative).endLag
- An int indicating at which lag to end.public static double crossCorrelationAt(double[] x, double[] y, int N, int lag)
x
- The first array of doubles.y
- The second array of doubles.N
- An integer indicating the number of samples to sum over.
This must be non-negative, but large numbers are ok because this
routine will not overrun reading of the arrays.lag
- An integer indicating the lag value (may be negative).public static final double entropy(double[] p)
H(p) = - sum (p[x] * log2(p[x]))
The entropy is always non-negative. Throw an IllegalArgumentException if the length of the array is 0, or a negative probability is encountered.p
- The array of probabilities.public static final double geometricMean(double[] array)
array
- An array of doubles.public static final double max(double[] array)
array
- The array of doubles.public static final java.lang.Object[] maxAndIndex(double[] array)
array
- An array of doubles.public static final double mean(double[] array)
array
- The array of doubles.public static final double min(double[] array)
array
- The array of doubles.public static final java.lang.Object[] minAndIndex(double[] array)
array
- An array of doubles.public static final double productOfElements(double[] array)
array
- The array of doubles.public static final double[] randomBernoulli(double p, int N)
p
- The probability, which should be a double between 0.0
and 1.0. The probability is compared to the output of
java.lang.Random.nextDouble(). If the output is less than p, then
the array element will be 1.0. If the output is greater than or
equal to p, then the array element will be 0.0.N
- The number of elements to allocate.public static final double[] randomExponential(double lambda, int N)
lambda
- The lambda, which may not by 0.0.N
- The number of elements to allocate.public static final double[] randomGaussian(double mean, double standardDeviation, int N)
mean
- The mean of the new array.standardDeviation
- The standard deviation of the new array.N
- The number of elements to allocate.public static final double[] randomPoisson(double mean, int N)
mean
- The mean of the new array.N
- The number of elements to allocate.public static double[] randomUniform(double a, double b, int N)
a
- A double indicating the lower bound.b
- A double indicating the upper bound.N
- An int indicating how many elements to generate.public static final double relativeEntropy(double[] p, double[] q)
D(p||q) = - sum (p[x] * log2(p[x]/q[x]))
Throw an IllegalArgumentException if either array has length 0. If the two arrays do not have the same length, throw an IllegalArgumentException.p
- An array of doubles representing the first pmf, p.q
- An array of doubles representing the second pmf, q.public static double standardDeviation(double[] array)
array
- The input array.public static double standardDeviation(double[] array, boolean sample)
stdDev = sqrt(variance)
The sample standard deviation is computed as follows
stdDev = sqrt(variancesample)
Throw an exception if the array is of length 0, or if the sample standard deviation is taken on an array of length less than 2.
array
- An array of doubles.sample
- True if the sample standard deviation is desired.public static final double sumOfElements(double[] array)
array
- An array of doubles.public static double variance(double[] array)
array
- An array of doubles.public static double variance(double[] array, boolean sample)
variance = (sum(X2) - (sum(X) / N)2) / N
The sample variance is computed as follows :
variancesample = (sum(X2) - (sum(X) / N)2) / (N - 1)
Throw a runtime exception if the array is of length 0, or if the sample variance is taken on an array of length less than 2.
array
- An array of doubles.sample
- True if the sample standard deviation is desired.protected static final int _nonZeroLength(double[] array, java.lang.String methodName)
array
- An array of doubles.methodName
- A String representing the method name of the caller,
without parentheses.