|
SoftNet-Consult Java Utility Library | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.softnetConsult.utils.math.StatsTools
public final class StatsTools
This class is a collection of static statistical utility methods and functions.
This product includes software developed by the
SoftNet-Consult Java Utility Library project and its contributors.
(http://java-tools.sourceforge.net)
Copyright (c) 2007-2008 SoftNet-Consult.
Copyright (c) 2007-2008 G. Paperin.
All rights reserved.
File: StatsTools.java
Library API version: "2.02"
Java compliance version: "1.5"
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following terms and conditions are met:
1. Redistributions of source code must retain the above
acknowledgement of the SoftNet-Consult Java Utility Library project, the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above acknowledgement of the
SoftNet-Consult Java Utility Library project, the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
3. All advertising materials mentioning features or use of this software or any derived
software must display the following acknowledgement:
This product includes software developed by the SoftNet-Consult Java Utility Library
project and its contributors.
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Constructor Summary | |
---|---|
private |
StatsTools()
Prevents instances of this class from being created as this class contains only static utility methods. |
Method Summary | ||
---|---|---|
static double |
correlation(double[] X,
double[] Y)
Computes the linear resgression correlation of the specified data. |
|
static double |
covariance(double[] X,
double[] Y)
Computes the covariance of the specified data sequences. |
|
static double |
linearLeastSquaresDisplacement(double[] X,
double[] Y)
Computes the displacement of the linear least squares fit to the specified data. |
|
static double |
linearLeastSquaresDisplacement(double[] X,
double[] Y,
double slope)
Computes the displacement of the linear least squares fit to the specified data. |
|
static double |
linearLeastSquaresSlope(double[] X,
double[] Y)
Computes the slope of the linear least squares fit to the specified data. |
|
static Pair<double[],double[]> |
lnTransform(Distribution<? extends java.lang.Number> dist)
Computes a linear transform of the specified distribution sample by using the observed values as x-values and observation frequencies as y-values of a data series. |
|
static
|
lnTransform(T1[] X,
T2[] Y)
Computes a linear transform of the specified data. |
|
static double |
mean(double[] sequence)
Computes the mean of an double number sequence. |
|
static double |
mean(int[] sequence)
Computes the mean of an integer sequence. |
|
static double |
mean(java.lang.Iterable<? extends java.lang.Number> sequence)
Computes the mean of a specified number sequence. |
|
static double |
mean(java.util.Iterator<? extends java.lang.Number> iterator)
Computes the mean of a number sequence returned by the specified iterator. |
|
static double |
rSquared(double[] X,
double[] Y)
Computes "R-squared" - the coefficient of determination for a linear regression, in other words - the square of the linear correlation coefficient. |
|
static double |
stdDeviation(double[] sequence)
Computes the standard deviation of a specified sequence. |
|
static double |
stdDeviation(double[] sequence,
double mean)
Computes the standard deviation of a specified sequence. |
|
static double |
stdDeviation(int[] sequence)
Computes the standard deviation of a specified sequence. |
|
static double |
stdDeviation(int[] sequence,
double mean)
Computes the standard deviation of a specified sequence. |
|
static double |
stdDeviation(java.lang.Iterable<? extends java.lang.Number> sequence)
Computes the standard deviation of a specified sequence. |
|
static double |
stdDeviation(java.lang.Iterable<? extends java.lang.Number> sequence,
double mean)
Computes the standard deviation of a specified sequence. |
|
static double |
stdDeviation(java.util.Iterator<? extends java.lang.Number> iterator)
Computes the standard deviation of a number sequence returned by the specified iterator. |
|
static double |
stdDeviation(java.util.Iterator<? extends java.lang.Number> iterator,
double mean)
Computes the standard deviation of a number sequence returned by the specified iterator. |
|
static double |
variance(double[] sequence)
Computes the variance of a specified sequence. |
|
static double |
variance(double[] sequence,
double mean)
Computes the variance of a specified sequence. |
|
static double |
variance(int[] sequence)
Computes the variance of a specified sequence. |
|
static double |
variance(int[] sequence,
double mean)
Computes the variance of a specified sequence. |
|
static double |
variance(java.lang.Iterable<? extends java.lang.Number> sequence)
Computes the variance of a specified sequence. |
|
static double |
variance(java.lang.Iterable<? extends java.lang.Number> sequence,
double mean)
Computes the variance of a specified sequence assuming that the mean is already known. |
|
static double |
variance(java.util.Iterator<? extends java.lang.Number> iterator)
Computes the variance of a number sequence returned by the specified iterator. |
|
static double |
variance(java.util.Iterator<? extends java.lang.Number> iterator,
double mean)
Computes the variance of a number sequence returned by the specified iterator. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
private StatsTools()
Method Detail |
---|
public static double mean(java.lang.Iterable<? extends java.lang.Number> sequence)
Double.NaN
elements are ignored,
however elements that are Double.POSITIVE_INFINITY
or Double.NEGATIVE_INFINITY
are not ignored.
sequence
- A number sequence that must contain at least one element
that is not null
and not Double.NaN
.
java.lang.IllegalArgumentException
- if the specified sequence contains zero
elements that are not null
and not Double.NaN
.public static double mean(java.util.Iterator<? extends java.lang.Number> iterator)
Double.NaN
elements are ignored,
however elements that are Double.POSITIVE_INFINITY
or Double.NEGATIVE_INFINITY
are not ignored.
iterator
- An iterator over a number sequence that must contain at
least one element that is not null
and not Double.NaN
.
java.lang.IllegalArgumentException
- if the sequence specified by the iterator contains
zero elements that are not null
and not Double.NaN
.public static double mean(double[] sequence)
double
number sequence.
Double.NaN
-elements are ignored,
however elements that are Double.POSITIVE_INFINITY
or Double.NEGATIVE_INFINITY
are not ignored.
sequence
- A double
number sequence that must contain at
least one element that is not Double.NaN
.
java.lang.IllegalArgumentException
- If the specified sequence contains
zero elements that are not Double.NaN
.public static double mean(int[] sequence)
sequence
- An integer sequence that must be longer than zero.
java.lang.IllegalArgumentException
- If the specified sequence contains no elements.public static double variance(java.lang.Iterable<? extends java.lang.Number> sequence)
Double.NaN
elements are ignored,
however elements that are Double.POSITIVE_INFINITY
or Double.NEGATIVE_INFINITY
are not ignored.
sequence
- A number sequence that must contain two or more elements that
are not null
and not Double.NaN
.
java.lang.IllegalArgumentException
- If the specified sequence contains less than 2
elements that are not null
and not Double.NaN
.public static double variance(java.lang.Iterable<? extends java.lang.Number> sequence, double mean)
Double.NaN
elements are ignored,
however elements that are Double.POSITIVE_INFINITY
or Double.NEGATIVE_INFINITY
are not ignored.
This method does not attempt to compute the mean required for the
computation of the variance but uses a specified value instead;
if the mean is already known this may save a complete iteration over the sequence.
However, if the specified mean is incorrect, the result of this method is undefined.
sequence
- A number sequence that must contain two or more elements that
are not null
and not Double.NaN
.mean
- The mean of the specified sequence as computed by mean(Iterable)
.
java.lang.IllegalArgumentException
- If the specified sequence contains less than 2
elements that are not null
and not Double.NaN
.public static double variance(java.util.Iterator<? extends java.lang.Number> iterator)
Double.NaN
elements are ignored,
however elements that are Double.POSITIVE_INFINITY
or Double.NEGATIVE_INFINITY
are not ignored.
iterator
- An iterator over a number sequence that must contain two
or more elements that are not null
and not Double.NaN
.
java.lang.IllegalArgumentException
- If the specified sequence contains less than 2
elements that are not null
and not Double.NaN
.public static double variance(java.util.Iterator<? extends java.lang.Number> iterator, double mean)
Double.NaN
elements are ignored,
however elements that are Double.POSITIVE_INFINITY
or Double.NEGATIVE_INFINITY
are not ignored.
This method does not attempt to compute the mean required for the
computation of the variance but uses a specified value instead;
if the mean is already known this may save a complete iteration over the sequence.
However, if the specified mean is incorrect, the result of this method is undefined.
iterator
- An iterator over a number sequence that must contain two
or more elements that are not null
and not Double.NaN
.mean
- The mean of the specified sequence as computed by mean(Iterator)
.
java.lang.IllegalArgumentException
- If the specified sequence contains less than 2
elements that are not null
and not Double.NaN
.public static double variance(double[] sequence)
Double.NaN
-elements are ignored,
however elements that are Double.POSITIVE_INFINITY
or Double.NEGATIVE_INFINITY
are not ignored.
sequence
- A numer sequence that must contain at least two elements
that are not Double.NaN
.
java.lang.IllegalArgumentException
- If the specified sequence contains less than 2
elements that are not Double.NaN
.public static double variance(double[] sequence, double mean)
Double.NaN
-elements are ignored,
however elements that are Double.POSITIVE_INFINITY
or Double.NEGATIVE_INFINITY
are not ignored.
This method does not attempt to compute the mean required for the
computation of the variance but uses a specified value instead;
if the mean is already known this may save a complete iteration over the sequence.
However, if the specified mean is incorrect, the result of this method is undefined.
sequence
- A numer sequence that must contain at least two elements
that are not Double.NaN
.mean
- The mean of the specified sequence as computed by mean(double[])
.
java.lang.IllegalArgumentException
- If the specified sequence contains less than 2
elements that are not Double.NaN
.public static double variance(int[] sequence)
sequence
- A numer sequence that must contain at least two elements.
java.lang.IllegalArgumentException
- If the specified sequence contains less than 2
elements.public static double variance(int[] sequence, double mean)
sequence
- A numer sequence that must contain at least two elements.mean
- The mean of the specified sequence as computed by mean(int[])
.
java.lang.IllegalArgumentException
- If the specified sequence contains less than 2
elements.public static double stdDeviation(java.lang.Iterable<? extends java.lang.Number> sequence)
Double.NaN
elements are ignored,
however elements that are Double.POSITIVE_INFINITY
or Double.NEGATIVE_INFINITY
are not ignored.
sequence
- A number sequence that must contain two or more elements that
are not null
and not Double.NaN
.
java.lang.IllegalArgumentException
- If the specified sequence contains less than 2
elements that are not null
and not Double.NaN
.public static double stdDeviation(java.lang.Iterable<? extends java.lang.Number> sequence, double mean)
Double.NaN
elements are ignored,
however elements that are Double.POSITIVE_INFINITY
or Double.NEGATIVE_INFINITY
are not ignored.
This method does not attempt to compute the mean required for the
computation of the standard deviation but uses a specified value instead;
if the mean is already known this may save a complete iteration over the sequence.
However, if the specified mean is incorrect, the result of this method is undefined.
sequence
- A number sequence that must contain two or more elements that
are not null
and not Double.NaN
.mean
- The mean of the specified sequence as computed by mean(Iterable)
.
java.lang.IllegalArgumentException
- If the specified sequence contains less than 2
elements that are not null
and not Double.NaN
.public static double stdDeviation(java.util.Iterator<? extends java.lang.Number> iterator)
Double.NaN
elements are ignored,
however elements that are Double.POSITIVE_INFINITY
or Double.NEGATIVE_INFINITY
are not ignored.
iterator
- An iterator over a number sequence that must contain two
or more elements that are not null
and not Double.NaN
.
computation of the variance and uses this value instead; if the mean is already known
this may save a complete iteration over the sequence.
java.lang.IllegalArgumentException
- If the specified sequence contains less than 2
elements that are not null
and not Double.NaN
.public static double stdDeviation(java.util.Iterator<? extends java.lang.Number> iterator, double mean)
Double.NaN
elements are ignored,
however elements that are Double.POSITIVE_INFINITY
or Double.NEGATIVE_INFINITY
are not ignored.
This method does not attempt to compute the mean required for the
computation of the standard deviation but uses a specified value instead;
if the mean is already known this may save a complete iteration over the sequence.
However, if the specified mean is incorrect, the result of this method is undefined.
iterator
- An iterator over a number sequence that must contain two
or more elements that are not null
and not Double.NaN
.
computation of the variance and uses this value instead; if the mean is already known
this may save a complete iteration over the sequence.mean
- The mean of the specified sequence as computed by mean(Iterable)
.
java.lang.IllegalArgumentException
- If the specified sequence contains less than 2
elements that are not null
and not Double.NaN
.public static double stdDeviation(double[] sequence)
Double.NaN
-elements are ignored,
however elements that are Double.POSITIVE_INFINITY
or Double.NEGATIVE_INFINITY
are not ignored.
sequence
- A numer sequence that must contain at least two elements
that are not Double.NaN
.
java.lang.IllegalArgumentException
- If the specified sequence contains less than 2
elements that are not Double.NaN
.public static double stdDeviation(double[] sequence, double mean)
Double.NaN
-elements are ignored,
however elements that are Double.POSITIVE_INFINITY
or Double.NEGATIVE_INFINITY
are not ignored.
This method does not attempt to compute the mean required for the
computation of the standard deviation but uses a specified value instead;
if the mean is already known this may save a complete iteration over the sequence.
However, if the specified mean is incorrect, the result of this method is undefined.
sequence
- A numer sequence that must contain at least two elements
that are not Double.NaN
.mean
- The mean of the specified sequence as computed by mean(Iterable)
.
java.lang.IllegalArgumentException
- If the specified sequence contains less than 2
elements that are not Double.NaN
.public static double stdDeviation(int[] sequence)
sequence
- A numer sequence that must contain at least two elements.
java.lang.IllegalArgumentException
- If the specified sequence contains less than 2
elements.public static double stdDeviation(int[] sequence, double mean)
sequence
- A numer sequence that must contain at least two elements.mean
- The mean of the specified sequence as computed by mean(Iterable)
.
java.lang.IllegalArgumentException
- If the specified sequence contains less than 2
elements.public static double covariance(double[] X, double[] Y)
X
- x-values of a series of data points.Y
- y-values of a series of data points.
java.lang.NullPointerException
- If X
or Y
is null
.
java.lang.IllegalArgumentException
- If X
or Y
are not of equal length.public static double rSquared(double[] X, double[] Y)
X
- x-values of a series of data points.Y
- y-values of a series of data points.
java.lang.NullPointerException
- If X
or Y
is null
.
java.lang.IllegalArgumentException
- If X
or Y
are not of equal length.public static double correlation(double[] X, double[] Y)
X
- x-values of a series of data points.Y
- y-values of a series of data points.
java.lang.NullPointerException
- If X
or Y
is null
.
java.lang.IllegalArgumentException
- If X
or Y
are not of equal length.public static double linearLeastSquaresSlope(double[] X, double[] Y)
X
- x-values of a series of data points.Y
- y-values of a series of data points.
java.lang.NullPointerException
- If X
or Y
is null
.
java.lang.IllegalArgumentException
- If X
or Y
are not of equal length.public static double linearLeastSquaresDisplacement(double[] X, double[] Y, double slope)
X
- x-values of a series of data points.Y
- y-values of a series of data points.slope
- The slope of the of the linear least squares fit to the specified
data as computed by linearLeastSquaresSlope(double[], double[])
.
java.lang.NullPointerException
- If X
or Y
is null
.
java.lang.IllegalArgumentException
- If X
or Y
are not of equal length.public static double linearLeastSquaresDisplacement(double[] X, double[] Y)
X
- x-values of a series of data points.Y
- y-values of a series of data points.
java.lang.NullPointerException
- If X
or Y
is null
.
java.lang.IllegalArgumentException
- If X
or Y
are not of equal length.public static <T1 extends java.lang.Number,T2 extends java.lang.Number> Pair<double[],double[]> lnTransform(T1[] X, T2[] Y)
T1
- The specific Number
type of the x-values.T2
- The specific Number
type of the y-values.X
- x-values of a series of data points.Y
- y-values of a series of data points.
Pair
of two arrays - the first containing the natural logarithm
values of the specified x-values, the second containing the natural
logarithm values of the specified y-values. Both arrays will always have
the same lengths, but that length may be shorter than the length of the input data
arrays as each pair (X[i], Y[i])
where (X[i])
or (X[i])
is null
is discarded and not included in the result array (note that if
this happens, data indices of the input data do not correspond to data indices of
the result).
java.lang.NullPointerException
- If X
or Y
is null
.
java.lang.IllegalArgumentException
- If X
or Y
are not of equal length.public static Pair<double[],double[]> lnTransform(Distribution<? extends java.lang.Number> dist)
dist
- An observed distribution sample.
Pair
of two arrays - the first containing the natural logarithm
values of the specified x-values, the second containing the natural
logarithm values of the specified y-values. Both arrays will always have
the same lengths, but that length may be shorter than the length of the input data
arrays as each pair (X[i], Y[i])
where (X[i])
or (X[i])
is null
is discarded and not included in the result array (note that if
this happens, data indices of the input data do not correspond to data indices of
the result).
java.lang.NullPointerException
- If X
or Y
is null
.
java.lang.IllegalArgumentException
- If X
or Y
are not of equal length.
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |