jhpro.stat
Class StatUtils
- java.lang.Object
-
- jhpro.stat.StatUtils
-
public class StatUtils extends java.lang.ObjectCommon statistical methods.
-
-
Constructor Summary
Constructors Constructor and Description StatUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static double[]autocorr(double[] data, int maxk)Computes autocorrelation up to maxk for the time series data.static double[]autoCorrelate(double[] signal, int windowlength, int windowshift)This static class does the autocorrelation for the given float vector.static double[]autocov(double[] data, int maxk)Computes autocovariance up to maxk for the time series data.static doubleavg(double[] v)Compute average of all values in vector v.static doublecorrel(double[] a, double[] b)Compute the correlation of a vector with another vector b.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 doublecrossCorrelationAt(double[] x, double[] y, int N, int lag)Return the cross-correlation of two arrays at a certain lag value.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 float[]residuals(float[] a, float[] b)Compute residuals of b versus a.static doublestdev(double[] v)Compute stdev (SQRT(var)) of all values in vector v.static doublesum(double[] v)Compute average of all values in vector v.static doublesum(float[] v)sum(1) computes summation of all values in vector v.static doublesum(float[][] m)sum(1) computes summation of all values in matrix m.static doublesum(float[] v, float[] mask)sum(2) computes the sum of the elements of vector v only where the mask value is not 0.static doublevar(double[] v)Compute variance of all elements in vector v.static double[]zeromean(double[] v)Zero the mean of all elements of v.
-
-
-
Method Detail
-
autoCorrelate
public static double[] autoCorrelate(double[] signal, int windowlength, int windowshift)This static class does the autocorrelation for the given float vector. It uses the function: autocorrelation[lag] = SUM(n=0,N) (signal[n]*signal[n+lag]) with n is the input sample index, and 0signal at different times n are the same values of the same signal delays by lag samples determines the magnitude of autocorrelation[lag]. The output of an autocorrelation shows the magnitude for different lag times. Note that the array length of the signal vector must have a length from at least window length + window shift (signal.length >= N+lag-max). If the length is smaller a null float array will be given back. - Parameters:
float[]- signal - the signal vector.int- windowlength - the length of correlation build with the summaration loop. Corresponds to lag-maxint- windowshift - the length of the summaration lopp. Corresponds to N- Returns:
- float[] - the autocorrelated signal vector.
-
avg
public static double avg(double[] v)
Compute average of all values in vector v.- Parameters:
v- a vector of float[]- Returns:
- the average of all elements in v.
-
sum
public static double sum(float[] v)
sum(1) computes summation of all values in vector v.- Parameters:
v- a vector of float[]- Returns:
- the average of all elements in v.
-
sum
public static double sum(float[][] m)
sum(1) computes summation of all values in matrix m.- Parameters:
v- a vector of float[]- Returns:
- the average of all elements in v.
-
sum
public static double sum(float[] v, float[] mask)sum(2) computes the sum of the elements of vector v only where the mask value is not 0.- Parameters:
v- a float[] vector.mask- a float[] with a value of ! 0 for all elements of v that are valid.- Returns:
- the avg of the masked elements in v.
-
sum
public static double sum(double[] v)
Compute average of all values in vector v.- Parameters:
v- a vector of float[]- Returns:
- the average of all elements in v.
-
stdev
public static double stdev(double[] v)
Compute stdev (SQRT(var)) of all values in vector v.- Parameters:
v- a vector of float[]
-
correl
public static double correl(double[] a, double[] b)Compute the correlation of a vector with another vector b. The mean of a and b is subtracted before further processing. a and b therefore do not have to be zero-mean.- Parameters:
a- a float[] vector.b- a float[] vector of same length.- Returns:
- r, the correlation coefficient.
-
var
public static double var(double[] v)
Compute variance of all elements in vector v.- Parameters:
v- a vector of float[]
-
residuals
public static float[] residuals(float[] a, float[] b) throws java.lang.IllegalArgumentExceptionCompute residuals of b versus a.- Parameters:
a- a float[] vectorb- a float[] vector.- Returns:
- a float[] that contains the residuals for each b-a.
- Throws:
java.lang.IllegalArgumentException
-
autocov
public static double[] autocov(double[] data, int maxk)Computes autocovariance up to maxk for the time series data.
-
autocorr
public static double[] autocorr(double[] data, int maxk)Computes autocorrelation up to maxk for the time series data.
-
zeromean
public static double[] zeromean(double[] v)
Zero the mean of all elements of v.- Parameters:
v- a vector.- Returns:
- a vector with zero mean and same variance as v.
-
crossCorrelation
public static final 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. The output array will have length (endLag - startLag + 1). The first element of the output will have the cross-correlation at a lag of startLag. The last element of the output will have the cross-correlation at a lag of endLag.- Parameters:
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.- Returns:
- A new array of doubles.
-
crossCorrelationAt
public static double crossCorrelationAt(double[] x, double[] y, int N, int lag)Return the cross-correlation of two arrays at a certain lag value. The cross-correlation is defined by : Rxy[d] = sum of i = 0 to N - 1 of x[i] * y[i + d]- Parameters:
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).- Returns:
- A double, Rxy[lag].
-
randomBernoulli
public static final double[] randomBernoulli(double p, int N)Return a new array of Bernoulli random variables with a given probability of success p. On success, the random variable has value 1.0; on failure the random variable has value 0.0.- Parameters:
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.- Returns:
- The array of Bernoulli random variables.
-
randomExponential
public static final double[] randomExponential(double lambda, int N)Return a new array of exponentially distributed doubles with parameter lambda. The number of elements to allocate is given by N.- Parameters:
lambda- The lambda, which may not by 0.0.N- The number of elements to allocate.- Returns:
- The array of exponential random variables.
-
randomGaussian
public static final double[] randomGaussian(double mean, double standardDeviation, int N)Return a new array of Gaussian distributed doubles with a given mean and standard deviation. The number of elements to allocate is given by N. This algorithm is from [1].- Parameters:
mean- The mean of the new array.standardDeviation- The standard deviation of the new array.N- The number of elements to allocate.- Returns:
- The array of random Gaussian variables.
-
randomPoisson
public static final double[] randomPoisson(double mean, int N)Return a new array of Poisson random variables (as doubles) with a given mean. The number of elements to allocate is given by N. This algorithm is from [1].- Parameters:
mean- The mean of the new array.N- The number of elements to allocate.- Returns:
- The array of random Poisson variables.
-
randomUniform
public static double[] randomUniform(double a, double b, int N)Return a new array of uniformly distributed doubles ranging from a to b. The number of elements to allocate is given by N.- Parameters:
a- A double indicating the lower bound.b- A double indicating the upper bound.N- An int indicating how many elements to generate.- Returns:
- A new array of doubles.
-
-
DMelt 3.0 © DataMelt by jWork.ORG