public final class StatUtils extends Object
Modifier and Type | Method and Description |
---|---|
static double |
geometricMean(double[] values)
Returns the geometric mean of the entries in the input array, or
Double.NaN if the array is empty. |
static double |
geometricMean(double[] values,
int begin,
int length)
Returns the geometric mean of the entries in the specified portion of
the input array, or
Double.NaN if the designated subarray
is empty. |
static double |
max(double[] values)
Returns the maximum of the entries in the input array, or
Double.NaN if the array is empty. |
static double |
max(double[] values,
int begin,
int length)
Returns the maximum of the entries in the specified portion of
the input array, or
Double.NaN if the designated subarray
is empty. |
static double |
mean(double[] values)
Returns the arithmetic mean of the entries in the input array, or
Double.NaN if the array is empty. |
static double |
mean(double[] values,
int begin,
int length)
Returns the arithmetic mean of the entries in the specified portion of
the input array, or
Double.NaN if the designated subarray
is empty. |
static double |
meanDifference(double[] sample1,
double[] sample2)
Returns the mean of the (signed) differences between corresponding elements of the
input arrays -- i.e., sum(sample1[i] - sample2[i]) / sample1.length.
|
static double |
median(double[] values)
Returns an estimate of the median of the values in the
values array. |
static double |
median(double[] values,
int begin,
int length)
Returns an estimate of the median of the values in the
values array, starting with the element in
(0-based) position begin in the array and including length values
Returns Double.NaN if length = 0
Returns values[begin] if length = 1
Throws IllegalArgumentException if values is null , begin or
length is invalid
See Percentile for a description of the percentile
estimation algorithm used. |
static double |
min(double[] values)
Returns the minimum of the entries in the input array, or
Double.NaN if the array is empty. |
static double |
min(double[] values,
int begin,
int length)
Returns the minimum of the entries in the specified portion of
the input array, or
Double.NaN if the designated subarray
is empty. |
static double[] |
normalize(double[] sample)
Normalize (standardize) the sample, so it is has a mean of 0 and a standard deviation of 1.
|
static double |
percentile(double[] values,
double p)
Returns an estimate of the
p th percentile of the values
in the values array. |
static double |
percentile(double[] values,
int begin,
int length,
double p)
Returns an estimate of the
p th percentile of the values
in the values array, starting with the element in (0-based)
position begin in the array and including length values. |
static double |
populationVariance(double[] values)
Returns the
population variance of the entries in the input array, or
Double.NaN if the array is empty. |
static double |
populationVariance(double[] values,
double mean)
Returns the
population variance of the entries in the input array, using the
precomputed mean value.
|
static double |
populationVariance(double[] values,
double mean,
int begin,
int length)
Returns the
population variance of the entries in the specified portion of
the input array, using the precomputed mean value.
|
static double |
populationVariance(double[] values,
int begin,
int length)
Returns the
population variance of the entries in the specified portion of
the input array, or
Double.NaN if the designated subarray
is empty. |
static double |
product(double[] values)
Returns the product of the entries in the input array, or
Double.NaN if the array is empty. |
static double |
product(double[] values,
int begin,
int length)
Returns the product of the entries in the specified portion of
the input array, or
Double.NaN if the designated subarray
is empty. |
static double |
quadraticMean(double[] values)
Returns the quadratic mean of the entries in the input array, or
Double.NaN if the array is empty. |
static double |
quadraticMean(double[] values,
int begin,
int length)
Returns the quadratic mean of the entries in the specified portion of
the input array, or
Double.NaN if the designated subarray
is empty. |
static double |
standardDeviation(double[] values)
Returns the standard deviation of the entries in the input array, or
Double.NaN if the array is
empty. |
static double |
standardDeviation(double[] values,
double mean)
Returns the standard deviation of the entries in the input array, using the
precomputed mean value.
|
static double |
standardDeviation(double[] values,
double mean,
int begin,
int length)
Returns the standard deviation of the entries in the specified portion of
the input array, using the precomputed mean value.
|
static double |
standardDeviation(double[] values,
int begin,
int length)
Returns the standard deviation of the entries in the specified portion of
the input array, or
Double.NaN if the designated subarray
is empty. |
static double |
sum(double[] values)
Returns the sum of the values in the input array, or
Double.NaN if the array is empty. |
static double |
sum(double[] values,
int begin,
int length)
Returns the sum of the entries in the specified portion of
the input array, or
Double.NaN if the designated subarray
is empty. |
static double |
sumDifference(double[] sample1,
double[] sample2)
Returns the sum of the (signed) differences between corresponding elements of the
input arrays -- i.e., sum(sample1[i] - sample2[i]).
|
static double |
sumLog(double[] values)
Returns the sum of the natural logs of the entries in the input array, or
Double.NaN if the array is
empty. |
static double |
sumLog(double[] values,
int begin,
int length)
Returns the sum of the natural logs of the entries in the specified portion of
the input array, or
Double.NaN if the designated subarray
is empty. |
static double |
sumSq(double[] values)
Returns the sum of the squares of the entries in the input array, or
Double.NaN if the array is
empty. |
static double |
sumSq(double[] values,
int begin,
int length)
Returns the sum of the squares of the entries in the specified portion of
the input array, or
Double.NaN if the designated subarray
is empty. |
static double |
variance(double[] values)
Returns the variance of the entries in the input array, or
Double.NaN if the array is empty. |
static double |
variance(double[] values,
double mean)
Returns the variance of the entries in the input array, using the
precomputed mean value.
|
static double |
variance(double[] values,
double mean,
int begin,
int length)
Returns the variance of the entries in the specified portion of
the input array, using the precomputed mean value.
|
static double |
variance(double[] values,
int begin,
int length)
Returns the variance of the entries in the specified portion of
the input array, or
Double.NaN if the designated subarray
is empty. |
static double |
varianceDifference(double[] sample1,
double[] sample2,
double meanDifference)
Returns the variance of the (signed) differences between corresponding elements of the
input arrays -- i.e., var(sample1[i] - sample2[i]).
|
public static double sum(double[] values)
Double.NaN
if the array is empty.
Throws IllegalArgumentException
if the input array is null.
values
- array of values to sumDouble.NaN
if the array
is emptyMathIllegalArgumentException
- if the array is nullpublic static double sum(double[] values, int begin, int length)
Double.NaN
if the designated subarray
is empty.
Throws IllegalArgumentException
if the array is null.
values
- the input arraybegin
- index of the first array element to includelength
- the number of elements to includeMathIllegalArgumentException
- if the array is null or the array index
parameters are not validpublic static double sumSq(double[] values)
Double.NaN
if the array is
empty.
Throws IllegalArgumentException
if the array is null.
values
- input arrayDouble.NaN
if the
array is emptyMathIllegalArgumentException
- if the array is nullpublic static double sumSq(double[] values, int begin, int length)
Double.NaN
if the designated subarray
is empty.
Throws IllegalArgumentException
if the array is null.
values
- the input arraybegin
- index of the first array element to includelength
- the number of elements to includeMathIllegalArgumentException
- if the array is null or the array index
parameters are not validpublic static double product(double[] values)
Double.NaN
if the array is empty.
Throws IllegalArgumentException
if the array is null.
values
- the input arrayMathIllegalArgumentException
- if the array is nullpublic static double product(double[] values, int begin, int length)
Double.NaN
if the designated subarray
is empty.
Throws IllegalArgumentException
if the array is null.
values
- the input arraybegin
- index of the first array element to includelength
- the number of elements to includeMathIllegalArgumentException
- if the array is null or the array index
parameters are not validpublic static double sumLog(double[] values)
Double.NaN
if the array is
empty.
Throws IllegalArgumentException
if the array is null.
See SumOfLogs
.
values
- the input arrayMathIllegalArgumentException
- if the array is nullpublic static double sumLog(double[] values, int begin, int length)
Double.NaN
if the designated subarray
is empty.
Throws IllegalArgumentException
if the array is null.
See SumOfLogs
.
values
- the input arraybegin
- index of the first array element to includelength
- the number of elements to includeMathIllegalArgumentException
- if the array is null or the array index
parameters are not validpublic static double mean(double[] values)
Double.NaN
if the array is empty.
Throws IllegalArgumentException
if the array is null.
See Mean
for details on the computing algorithm.
values
- the input arrayMathIllegalArgumentException
- if the array is nullpublic static double mean(double[] values, int begin, int length)
Double.NaN
if the designated subarray
is empty.
Throws IllegalArgumentException
if the array is null.
See Mean
for details on the computing algorithm.
values
- the input arraybegin
- index of the first array element to includelength
- the number of elements to includeMathIllegalArgumentException
- if the array is null or the array index
parameters are not validpublic static double quadraticMean(double[] values)
Double.NaN
if the array is empty.
Throws IllegalArgumentException
if the array is null.
values
- the input arrayIllegalArgumentException
- if the array is nullpublic static double quadraticMean(double[] values, int begin, int length)
Double.NaN
if the designated subarray
is empty.
Throws IllegalArgumentException
if the array is null or the array index parameters are not valid
values
- the input arraybegin
- index of the first array element to includelength
- the number of elements to includeIllegalArgumentException
- if the array is null or the array index
parameters are not validpublic static double geometricMean(double[] values)
Double.NaN
if the array is empty.
Throws IllegalArgumentException
if the array is null.
See GeometricMean
for details on the computing
algorithm.
values
- the input arrayMathIllegalArgumentException
- if the array is nullpublic static double geometricMean(double[] values, int begin, int length)
Double.NaN
if the designated subarray
is empty.
Throws IllegalArgumentException
if the array is null.
See GeometricMean
for details on the computing
algorithm.
values
- the input arraybegin
- index of the first array element to includelength
- the number of elements to includeMathIllegalArgumentException
- if the array is null or the array index
parameters are not validpublic static double variance(double[] values)
Double.NaN
if the array is empty.
This method returns the bias-corrected sample variance (using n - 1
in the denominator). Use
populationVariance(double[])
for the non-bias-corrected population variance.
See Variance
for details on the computing algorithm.
Returns 0 for a single-value (i.e. length = 1) sample.
Throws MathIllegalArgumentException
if the array is null.
values
- the input arrayMathIllegalArgumentException
- if the array is nullpublic static double variance(double[] values, int begin, int length)
Double.NaN
if the designated subarray
is empty.
This method returns the bias-corrected sample variance (using n - 1
in the denominator). Use
populationVariance(double[], int, int)
for the non-bias-corrected population variance.
See Variance
for details on the computing algorithm.
Returns 0 for a single-value (i.e. length = 1) sample.
Throws MathIllegalArgumentException
if the array is null or the array index parameters are not
valid.
values
- the input arraybegin
- index of the first array element to includelength
- the number of elements to includeMathIllegalArgumentException
- if the array is null or the array index
parameters are not validpublic static double variance(double[] values, double mean, int begin, int length)
Double.NaN
if the designated subarray is
empty.
This method returns the bias-corrected sample variance (using n - 1
in the denominator). Use
populationVariance(double[], double, int, int)
for the non-bias-corrected population variance.
See Variance
for details on the computing algorithm.
The formula used assumes that the supplied mean value is the arithmetic mean of the sample data, not a known population parameter. This method is supplied only to save computation when the mean has already been computed.
Returns 0 for a single-value (i.e. length = 1) sample.
Throws MathIllegalArgumentException
if the array is null or the array index parameters are not
valid.
values
- the input arraymean
- the precomputed mean valuebegin
- index of the first array element to includelength
- the number of elements to includeMathIllegalArgumentException
- if the array is null or the array index
parameters are not validpublic static double variance(double[] values, double mean)
Double.NaN
if the array
is empty.
This method returns the bias-corrected sample variance (using n - 1
in the denominator). Use
populationVariance(double[], double)
for the non-bias-corrected population variance.
See Variance
for details on the computing algorithm.
The formula used assumes that the supplied mean value is the arithmetic mean of the sample data, not a known population parameter. This method is supplied only to save computation when the mean has already been computed.
Returns 0 for a single-value (i.e. length = 1) sample.
Throws MathIllegalArgumentException
if the array is null.
values
- the input arraymean
- the precomputed mean valueMathIllegalArgumentException
- if the array is nullpublic static double standardDeviation(double[] values)
Double.NaN
if the array is
empty.
See StandardDeviation
for details on the computing
algorithm.
Returns 0 for a single-value (i.e. length = 1) sample.
Throws IllegalArgumentException
if the array is null.
values
- the input arrayIllegalArgumentException
- if the array is nullpublic static double standardDeviation(double[] values, int begin, int length)
Double.NaN
if the designated subarray
is empty.
See StandardDeviation
for details on the computing
algorithm.
Returns 0 for a single-value (i.e. length = 1) sample.
Throws IllegalArgumentException
if the array is null or the array index parameters are not valid.
values
- the input arraybegin
- index of the first array element to includelength
- the number of elements to includeIllegalArgumentException
- if the array is null or the array index
parameters are not validpublic static double standardDeviation(double[] values, double mean, int begin, int length)
Double.NaN
if the designated subarray is
empty.
See StandardDeviation
for details on the computing
algorithm.
The formula used assumes that the supplied mean value is the arithmetic mean of the sample data, not a known population parameter. This method is supplied only to save computation when the mean has already been computed.
Returns 0 for a single-value (i.e. length = 1) sample.
Throws IllegalArgumentException
if the array is null or the array index parameters are not valid.
values
- the input arraymean
- the precomputed mean valuebegin
- index of the first array element to includelength
- the number of elements to includeIllegalArgumentException
- if the array is null or the array index
parameters are not validpublic static double standardDeviation(double[] values, double mean)
Double.NaN
if the array
is empty.
See StandardDeviation
for details on the computing
algorithm.
The formula used assumes that the supplied mean value is the arithmetic mean of the sample data, not a known population parameter. This method is supplied only to save computation when the mean has already been computed.
Returns 0 for a single-value (i.e. length = 1) sample.
Throws IllegalArgumentException
if the array is null.
values
- the input arraymean
- the precomputed mean valueIllegalArgumentException
- if the array is nullpublic static double populationVariance(double[] values)
Double.NaN
if the array is empty.
See Variance
for details on the formula and computing
algorithm.
Returns 0 for a single-value (i.e. length = 1) sample.
Throws MathIllegalArgumentException
if the array is null.
values
- the input arrayMathIllegalArgumentException
- if the array is nullpublic static double populationVariance(double[] values, int begin, int length)
Double.NaN
if the designated subarray
is empty.
See Variance
for details on the computing algorithm.
Returns 0 for a single-value (i.e. length = 1) sample.
Throws MathIllegalArgumentException
if the array is null or the array index parameters are not
valid.
values
- the input arraybegin
- index of the first array element to includelength
- the number of elements to includeMathIllegalArgumentException
- if the array is null or the array index
parameters are not validpublic static double populationVariance(double[] values, double mean, int begin, int length)
Double.NaN
if the designated subarray is
empty.
See Variance
for details on the computing algorithm.
The formula used assumes that the supplied mean value is the arithmetic mean of the sample data, not a known population parameter. This method is supplied only to save computation when the mean has already been computed.
Returns 0 for a single-value (i.e. length = 1) sample.
Throws MathIllegalArgumentException
if the array is null or the array index parameters are not
valid.
values
- the input arraymean
- the precomputed mean valuebegin
- index of the first array element to includelength
- the number of elements to includeMathIllegalArgumentException
- if the array is null or the array index
parameters are not validpublic static double populationVariance(double[] values, double mean)
Double.NaN
if the array
is empty.
See Variance
for details on the computing algorithm.
The formula used assumes that the supplied mean value is the arithmetic mean of the sample data, not a known population parameter. This method is supplied only to save computation when the mean has already been computed.
Returns 0 for a single-value (i.e. length = 1) sample.
Throws MathIllegalArgumentException
if the array is null.
values
- the input arraymean
- the precomputed mean valueMathIllegalArgumentException
- if the array is nullpublic static double max(double[] values)
Double.NaN
if the array is empty.
Throws MathIllegalArgumentException
if the array is null.
NaN
iff all values are NaN
(i.e. NaN
values have no
impact on the value of the statistic).Double.POSITIVE_INFINITY
, the result is
Double.POSITIVE_INFINITY.
values
- the input arrayMathIllegalArgumentException
- if the array is nullpublic static double max(double[] values, int begin, int length)
Double.NaN
if the designated subarray
is empty.
Throws MathIllegalArgumentException
if the array is null or the array index parameters are not
valid.
NaN
iff all values are NaN
(i.e. NaN
values have no
impact on the value of the statistic).Double.POSITIVE_INFINITY
, the result is
Double.POSITIVE_INFINITY.
values
- the input arraybegin
- index of the first array element to includelength
- the number of elements to includeMathIllegalArgumentException
- if the array is null or the array index
parameters are not validpublic static double min(double[] values)
Double.NaN
if the array is empty.
Throws MathIllegalArgumentException
if the array is null.
NaN
iff all values are NaN
(i.e. NaN
values have no
impact on the value of the statistic).Double.NEGATIVE_INFINITY
, the result is
Double.NEGATIVE_INFINITY.
values
- the input arrayMathIllegalArgumentException
- if the array is nullpublic static double min(double[] values, int begin, int length)
Double.NaN
if the designated subarray
is empty.
Throws MathIllegalArgumentException
if the array is null or the array index parameters are not
valid.
NaN
iff all values are NaN
(i.e. NaN
values have no
impact on the value of the statistic).Double.NEGATIVE_INFINITY
, the result is
Double.NEGATIVE_INFINITY.
values
- the input arraybegin
- index of the first array element to includelength
- the number of elements to includeMathIllegalArgumentException
- if the array is null or the array index
parameters are not validpublic static double percentile(double[] values, double p)
p
th percentile of the values
in the values
array.
Double.NaN
if values
has length 0
p
) values[0]
if values
has length
1
IllegalArgumentException
if values
is null or p is not a valid quantile
value (p must be greater than 0 and less than or equal to 100)
See Percentile
for a description of the percentile
estimation algorithm used.
values
- input array of valuesp
- the percentile value to computeMathIllegalArgumentException
- if values
is null
or p is invalidpublic static double percentile(double[] values, int begin, int length, double p)
p
th percentile of the values
in the values
array, starting with the element in (0-based)
position begin
in the array and including length
values.
Double.NaN
if length = 0
p
) values[begin]
if length = 1
MathIllegalArgumentException
if values
is null , begin
or
length
is invalid, or p
is not a valid quantile value (p must be greater than 0 and
less than or equal to 100)
See Percentile
for a description of the percentile
estimation algorithm used.
values
- array of input valuesp
- the percentile to computebegin
- the first (0-based) element to include in the computationlength
- the number of array elements to includeMathIllegalArgumentException
- if the parameters are not valid or the
input array is nullpublic static double median(double[] values)
values
array.
Double.NaN
if values
has length 0
values[0]
if values
has length 1
IllegalArgumentException
if values
is null
See Percentile
for a description of the median
estimation algorithm used.
values
- input array of valuesIllegalArgumentException
- if values
is null
or p is invalidpublic static double median(double[] values, int begin, int length)
values
array, starting with the element in
(0-based) position begin
in the array and including length
values
Double.NaN
if length = 0
values[begin]
if length = 1
IllegalArgumentException
if values
is null , begin
or
length
is invalid
See Percentile
for a description of the percentile
estimation algorithm used.
values
- array of input valuesbegin
- the first (0-based) element to include in the computationlength
- the number of array elements to includeIllegalArgumentException
- if the parameters are not valid or the
input array is nullpublic static double sumDifference(double[] sample1, double[] sample2)
sample1
- the first arraysample2
- the second arrayDimensionMismatchException
- if the arrays do not have the same
(positive) length.NoDataException
- if the sample arrays are empty.public static double meanDifference(double[] sample1, double[] sample2)
sample1
- the first arraysample2
- the second arrayDimensionMismatchException
- if the arrays do not have the same
(positive) length.NoDataException
- if the sample arrays are empty.public static double varianceDifference(double[] sample1, double[] sample2, double meanDifference)
sample1
- the first arraysample2
- the second arraymeanDifference
- the mean difference between corresponding entriesDimensionMismatchException
- if the arrays do not have the same
length.NumberIsTooSmallException
- if the arrays length is less than 2.meanDifference(double[],double[])
public static double[] normalize(double[] sample)
sample
- Sample to normalize.Copyright © 2019 CNES. All rights reserved.