Class AbstractUnivariateStatistic
java.lang.Object
org.apache.commons.math.stat.descriptive.AbstractUnivariateStatistic
- All Implemented Interfaces:
UnivariateStatistic
- Direct Known Subclasses:
AbstractStorelessUnivariateStatistic,Percentile,SemiVariance
Abstract base class for all implementations of the
UnivariateStatistic interface.
Provides a default implementation of evaluate(double[]),
delegating to evaluate(double[], int, int) in the natural way.
Also includes a test method that performs generic parameter
validation for the evaluate methods.
- Version:
- $Revision: 1006299 $ $Date: 2010-10-10 16:47:17 +0200 (dim. 10 oct. 2010) $
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract UnivariateStatisticcopy()Returns a copy of the statistic with the same internal state.doubleevaluate()Returns the result of evaluating the statistic over the stored data.doubleevaluate(double[] values) Returns the result of evaluating the statistic over the input array.abstract doubleevaluate(double[] values, int begin, int length) Returns the result of evaluating the statistic over the specified entries in the input array.double[]getData()Get a copy of the stored data array.protected double[]Get a reference to the stored data array.voidsetData(double[] values) Set the data array.voidsetData(double[] values, int begin, int length) Set the data array.protected booleantest(double[] values, double[] weights, int begin, int length) This method is used byevaluate(double[], double[], int, int)methods to verify that the begin and length parameters designate a subarray of positive length and the weights are all non-negative, non-NaN, finite, and not all zero.protected booleantest(double[] values, int begin, int length) This method is used byevaluate(double[], int, int)methods to verify that the input parameters designate a subarray of positive length.
-
Constructor Details
-
AbstractUnivariateStatistic
public AbstractUnivariateStatistic()
-
-
Method Details
-
setData
public void setData(double[] values) Set the data array.The stored value is a copy of the parameter array, not the array itself
- Parameters:
values- data array to store (may be null to remove stored data)- See Also:
-
getData
public double[] getData()Get a copy of the stored data array.- Returns:
- copy of the stored data array (may be null)
-
getDataRef
protected double[] getDataRef()Get a reference to the stored data array.- Returns:
- reference to the stored data array (may be null)
-
setData
public void setData(double[] values, int begin, int length) Set the data array.- Parameters:
values- data array to storebegin- the index of the first element to includelength- the number of elements to include- See Also:
-
evaluate
public double evaluate()Returns the result of evaluating the statistic over the stored data.The stored array is the one which was set by previous calls to
- Returns:
- the value of the statistic applied to the stored data
-
evaluate
public double evaluate(double[] values) Returns the result of evaluating the statistic over the input array.- Specified by:
evaluatein interfaceUnivariateStatistic- Parameters:
values- input array- Returns:
- the value of the statistic applied to the input array
-
evaluate
public abstract double evaluate(double[] values, int begin, int length) Returns the result of evaluating the statistic over the specified entries in the input array.- Specified by:
evaluatein interfaceUnivariateStatistic- Parameters:
values- the input arraybegin- the index of the first element to includelength- the number of elements to include- Returns:
- the value of the statistic applied to the included array entries
-
copy
Returns a copy of the statistic with the same internal state.- Specified by:
copyin interfaceUnivariateStatistic- Returns:
- a copy of the statistic
-
test
protected boolean test(double[] values, int begin, int length) This method is used byevaluate(double[], int, int)methods to verify that the input parameters designate a subarray of positive length.- returns
trueiff the parameters designate a subarray of positive length - throws
IllegalArgumentExceptionif the array is null or or the indices are invalid - returns
false if the array is non-null, but
lengthis 0.- Parameters:
values- the input arraybegin- index of the first array element to includelength- the number of elements to include- Returns:
- true if the parameters are valid and designate a subarray of positive length
- Throws:
IllegalArgumentException- if the indices are invalid or the array is null
- returns
-
test
protected boolean test(double[] values, double[] weights, int begin, int length) This method is used byevaluate(double[], double[], int, int)methods to verify that the begin and length parameters designate a subarray of positive length and the weights are all non-negative, non-NaN, finite, and not all zero.- returns
trueiff the parameters designate a subarray of positive length and the weights array contains legitimate values. - throws
IllegalArgumentExceptionif any of the following are true:- the values array is null
- the weights array is null
- the weights array does not have the same length as the values array
- the weights array contains one or more infinite values
- the weights array contains one or more NaN values
- the weights array contains negative values
- the start and length arguments do not determine a valid array
- returns
false if the array is non-null, but
lengthis 0.- Parameters:
values- the input arrayweights- the weights arraybegin- index of the first array element to includelength- the number of elements to include- Returns:
- true if the parameters are valid and designate a subarray of positive length
- Throws:
IllegalArgumentException- if the indices are invalid or the array is null- Since:
- 2.1
- returns
-