Return-Path:
- * Provides default
- * Note that these implementations are not synchronized.
- * Note that this implementation changes the internal state of the
- * statistic. Its side effects are the same as invoking {@link #clear} and
- * then {@link #incrementAll(double[])}.
- * Implementations may override this method with a more efficient and
- * possibly more accurate implementation that works directly with the
- * input array.
- * If the array is null, a MathIllegalArgumentException is thrown.
- * Note that this implementation changes the internal state of the
- * statistic. Its side effects are the same as invoking {@link #clear} and
- * then {@link #incrementAll(double[], int, int)}.
- * Implementations may override this method with a more efficient and
- * possibly more accurate implementation that works directly with the
- * input array.
* If the array is null or the index parameters are not valid, an
- * MathIllegalArgumentException is thrown.
- * Throws IllegalArgumentException if the input values array is null.
- * Throws IllegalArgumentException if the input values array is null.
* Provides a default implementation of
- * Also includes a
* The stored value is a copy of the parameter array, not the array itself.
@@ -80,7 +96,7 @@ public abstract class AbstractUnivariateStatistic
* @see #evaluate()
*/
public void setData(final double[] values, final int begin, final int length)
- throws MathIllegalArgumentException {
+ throws MathIllegalArgumentException {
if (values == null) {
throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
}
@@ -113,154 +129,4 @@ public abstract class AbstractUnivariateStatistic
return evaluate(storedData);
}
- /**
- * {@inheritDoc}
- */
- @Override
- public double evaluate(final double[] values) throws MathIllegalArgumentException {
- test(values, 0, 0);
- return evaluate(values, 0, values.length);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public abstract double evaluate(final double[] values, final int begin, final int length)
- throws MathIllegalArgumentException;
-
- /**
- * {@inheritDoc}
- */
- @Override
- public abstract UnivariateStatistic copy();
-
- /**
- * This method is used by
- * evaluate()
and incrementAll(double[])
- * implementations.object
is an
- * AbstractStorelessUnivariateStatistic
returning the same
- * values as this for getResult()
and getN()
+ * Returns true iff object
is the same type of
+ * {@link StorelessUnivariateStatistic} (the object's class equals this
+ * instance) returning the same values as this for getResult()
+ * and getN()
.
+ *
* @param object object to test equality against.
* @return true if object returns the same value as this
*/
@@ -171,22 +171,22 @@ public abstract class AbstractStorelessUnivariateStatistic
if (object == this ) {
return true;
}
- if (object instanceof AbstractStorelessUnivariateStatistic == false) {
+ if (object == null || object.getClass() != this.getClass()) {
return false;
}
- AbstractStorelessUnivariateStatistic stat = (AbstractStorelessUnivariateStatistic) object;
+ StorelessUnivariateStatistic stat = (StorelessUnivariateStatistic) object;
return Precision.equalsIncludingNaN(stat.getResult(), this.getResult()) &&
Precision.equalsIncludingNaN(stat.getN(), this.getN());
}
/**
- * Returns hash code based on getResult() and getN()
+ * Returns hash code based on getResult() and getN().
*
* @return hash code
*/
@Override
public int hashCode() {
- return 31* (31 + MathUtils.hash(getResult())) + MathUtils.hash(getN());
+ return 31 * (31 + MathUtils.hash(getResult())) + MathUtils.hash(getN());
}
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/845e1d54/src/main/java/org/apache/commons/math4/stat/descriptive/AbstractUnivariateStatistic.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/AbstractUnivariateStatistic.java b/src/main/java/org/apache/commons/math4/stat/descriptive/AbstractUnivariateStatistic.java
index ab8e02d..e953aed 100644
--- a/src/main/java/org/apache/commons/math4/stat/descriptive/AbstractUnivariateStatistic.java
+++ b/src/main/java/org/apache/commons/math4/stat/descriptive/AbstractUnivariateStatistic.java
@@ -24,16 +24,10 @@ import org.apache.commons.math4.exception.util.LocalizedFormats;
import org.apache.commons.math4.util.MathArrays;
/**
- * Abstract base class for all implementations of the
- * {@link UnivariateStatistic} interface.
+ * Abstract base class for implementations of the {@link UnivariateStatistic} interface.
* evaluate(double[]),
* delegating to evaluate(double[], int, int)
in the natural way.
- * test
method that performs generic parameter
- * validation for the evaluate
methods.evaluate(double[], int, int)
methods
- * to verify that the input parameters designate a subarray of positive length.
- *
- *
true
iff the parameters designate a subarray of
- * positive lengthMathIllegalArgumentException
if the array is null or
- * or the indices are invalidfalse
length
is 0.
- *
evaluate(double[], int, int)
methods
- * to verify that the input parameters designate a subarray of positive length.
- * - *
true
iff the parameters designate a subarray of
- * non-negative lengthIllegalArgumentException
if the array is null or
- * or the indices are invalidfalse
length
is 0 unless allowEmpty
is true
- * true
then zero length arrays are allowed
- * @return true if the parameters are valid
- * @throws MathIllegalArgumentException if the indices are invalid or the array is null
- * @since 3.0
- */
- protected boolean test(final double[] values, final int begin,
- final int length, final boolean allowEmpty) throws MathIllegalArgumentException {
- return MathArrays.verifyValues(values, begin, length, allowEmpty);
- }
-
- /**
- * This method is used by evaluate(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.
- * - *
true
iff the parameters designate a subarray of
- * positive length and the weights array contains legitimate values.IllegalArgumentException
if any of the following are true:
- * false
length
is 0.
- * evaluate(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.
- * - *
true
iff the parameters designate a subarray of
- * non-negative length and the weights array contains legitimate values.MathIllegalArgumentException
if any of the following are true:
- * false
length
is 0 unless allowEmpty
is true
.
- * * This interface is designed to be used for calculating statistics that can be * computed in one pass through the data without storing the full array of - * sample values.
- * + * sample values. + *
+ * Note: unless otherwise stated, the {@link #evaluate(double[])} and
+ * {@link #evaluate(double[], int, int)} methods do NOT alter the internal
+ * state of the respective statistic.
*/
public interface StorelessUnivariateStatistic extends UnivariateStatistic {
http://git-wip-us.apache.org/repos/asf/commons-math/blob/845e1d54/src/main/java/org/apache/commons/math4/stat/descriptive/UnivariateStatistic.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/UnivariateStatistic.java b/src/main/java/org/apache/commons/math4/stat/descriptive/UnivariateStatistic.java
index 03228be..3a07a92 100644
--- a/src/main/java/org/apache/commons/math4/stat/descriptive/UnivariateStatistic.java
+++ b/src/main/java/org/apache/commons/math4/stat/descriptive/UnivariateStatistic.java
@@ -22,7 +22,6 @@ import org.apache.commons.math4.util.MathArrays;
/**
* Base interface implemented by all statistics.
- *
*/
public interface UnivariateStatistic extends MathArrays.Function {
/**
http://git-wip-us.apache.org/repos/asf/commons-math/blob/845e1d54/src/main/java/org/apache/commons/math4/stat/descriptive/moment/FirstMoment.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/FirstMoment.java b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/FirstMoment.java
index 00d8513..a1eb340 100644
--- a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/FirstMoment.java
+++ b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/FirstMoment.java
@@ -46,14 +46,12 @@ import org.apache.commons.math4.util.MathUtils;
* multiple threads access an instance of this class concurrently, and at least
* one of the threads invokes the increment()
or
* clear()
method, it must be synchronized externally.
increment()
or
* clear()
method, it must be synchronized externally.
- *
*/
class FourthMoment extends ThirdMoment implements Serializable{
/** Serializable version identifier */
- private static final long serialVersionUID = 4763990447117157611L;
+ private static final long serialVersionUID = 20150412L;
/** fourth moment of values that have been added */
private double m4;
@@ -72,7 +71,7 @@ class FourthMoment extends ThirdMoment implements Serializable{
/**
* Copy constructor, creates a new {@code FourthMoment} identical
- * to the {@code original}
+ * to the {@code original}.
*
* @param original the {@code FourthMoment} instance to copy
* @throws NullArgumentException if original is null
http://git-wip-us.apache.org/repos/asf/commons-math/blob/845e1d54/src/main/java/org/apache/commons/math4/stat/descriptive/moment/GeometricMean.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/GeometricMean.java b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/GeometricMean.java
index ab628de..938930b 100644
--- a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/GeometricMean.java
+++ b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/GeometricMean.java
@@ -48,19 +48,17 @@ import org.apache.commons.math4.util.MathUtils;
* multiple threads access an instance of this class concurrently, and at least
* one of the threads invokes the increment()
or
* clear()
method, it must be synchronized externally.
- *
- *
*/
public class GeometricMean extends AbstractStorelessUnivariateStatistic implements Serializable {
/** Serializable version identifier */
- private static final long serialVersionUID = -8178734905303459453L;
+ private static final long serialVersionUID = 20150412L;
/** Wrapped SumOfLogs instance */
private StorelessUnivariateStatistic sumOfLogs;
/**
- * Create a GeometricMean instance
+ * Create a GeometricMean instance.
*/
public GeometricMean() {
sumOfLogs = new SumOfLogs();
@@ -68,7 +66,7 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen
/**
* Copy constructor, creates a new {@code GeometricMean} identical
- * to the {@code original}
+ * to the {@code original}.
*
* @param original the {@code GeometricMean} instance to copy
* @throws NullArgumentException if original is null
@@ -80,7 +78,7 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen
/**
* Create a GeometricMean instance using the given SumOfLogs instance
- * @param sumOfLogs sum of logs instance to use for computation
+ * @param sumOfLogs sum of logs instance to use for computation.
*/
public GeometricMean(SumOfLogs sumOfLogs) {
this.sumOfLogs = sumOfLogs;
@@ -142,11 +140,9 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen
* index parameters are not valid
*/
@Override
- public double evaluate(
- final double[] values, final int begin, final int length)
- throws MathIllegalArgumentException {
- return FastMath.exp(
- sumOfLogs.evaluate(values, begin, length) / length);
+ public double evaluate(final double[] values, final int begin, final int length)
+ throws MathIllegalArgumentException {
+ return FastMath.exp(sumOfLogs.evaluate(values, begin, length) / length);
}
/**
@@ -169,13 +165,13 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen
* (i.e if n > 0)
*/
public void setSumLogImpl(StorelessUnivariateStatistic sumLogImpl)
- throws MathIllegalStateException {
+ throws MathIllegalStateException {
checkEmpty();
this.sumOfLogs = sumLogImpl;
}
/**
- * Returns the currently configured sum of logs implementation
+ * Returns the currently configured sum of logs implementation.
*
* @return the StorelessUnivariateStatistic implementing the log sum
*/
@@ -195,11 +191,9 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen
throws NullArgumentException {
MathUtils.checkNotNull(source);
MathUtils.checkNotNull(dest);
- dest.setData(source.getDataRef());
dest.sumOfLogs = source.sumOfLogs.copy();
}
-
/**
* Throws MathIllegalStateException if n > 0.
* @throws MathIllegalStateException if data has been added to this statistic
http://git-wip-us.apache.org/repos/asf/commons-math/blob/845e1d54/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Kurtosis.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Kurtosis.java b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Kurtosis.java
index 2164ed9..8e5f280 100644
--- a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Kurtosis.java
+++ b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Kurtosis.java
@@ -22,6 +22,7 @@ import org.apache.commons.math4.exception.MathIllegalArgumentException;
import org.apache.commons.math4.exception.NullArgumentException;
import org.apache.commons.math4.stat.descriptive.AbstractStorelessUnivariateStatistic;
import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.math4.util.MathArrays;
import org.apache.commons.math4.util.MathUtils;
@@ -29,27 +30,26 @@ import org.apache.commons.math4.util.MathUtils;
* Computes the Kurtosis of the available values.
* * We use the following (unbiased) formula to define kurtosis:
- *- * kurtosis = { [n(n+1) / (n -1)(n - 2)(n-3)] sum[(x_i - mean)^4] / std^4 } - [3(n-1)^2 / (n-2)(n-3)] - *
- * where n is the number of values, mean is the {@link Mean} and std is the + *
+ * kurtosis = { [n(n+1) / (n -1)(n - 2)(n-3)] sum[(x_i - mean)^4] / std^4 } - [3(n-1)^2 / (n-2)(n-3)] + *
+ * where n is the number of values, mean is the {@link Mean} and std is the * {@link StandardDeviation}
*
- * Note that this statistic is undefined for n < 4. Double.Nan
- * is returned when there is not sufficient data to compute the statistic.
- * Note that Double.NaN may also be returned if the input includes NaN
- * and / or infinite values.
Double.Nan
+ * is returned when there is not sufficient data to compute the statistic.
+ * Note that Double.NaN may also be returned if the input includes NaN
+ * and / or infinite values.
*
* Note that this implementation is not synchronized. If
* multiple threads access an instance of this class concurrently, and at least
* one of the threads invokes the increment()
or
* clear()
method, it must be synchronized externally.
* Statistics based on (constructed from) external moments cannot * be incremented or cleared.
- */ + */ protected boolean incMoment; /** - * Construct a Kurtosis + * Construct a Kurtosis. */ public Kurtosis() { incMoment = true; @@ -71,7 +71,7 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S } /** - * Construct a Kurtosis from an external moment + * Construct a Kurtosis from an external moment. * * @param m4 external Moment */ @@ -82,7 +82,7 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S /** * Copy constructor, creates a new {@code Kurtosis} identical - * to the {@code original} + * to the {@code original}. * * @param original the {@code Kurtosis} instance to copy * @throws NullArgumentException if original is null @@ -161,13 +161,13 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S * index parameters are not valid */ @Override - public double evaluate(final double[] values,final int begin, final int length) - throws MathIllegalArgumentException { + public double evaluate(final double[] values, final int begin, final int length) + throws MathIllegalArgumentException { + // Initialize the kurtosis double kurt = Double.NaN; - if (test(values, begin, length) && length > 3) { - + if (MathArrays.verifyValues(values, begin, length) && length > 3) { // Compute the mean and standard deviation Variance variance = new Variance(); variance.incrementAll(values, begin, length); @@ -219,7 +219,6 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S throws NullArgumentException { MathUtils.checkNotNull(source); MathUtils.checkNotNull(dest); - dest.setData(source.getDataRef()); dest.moment = source.moment.copy(); dest.incMoment = source.incMoment; } http://git-wip-us.apache.org/repos/asf/commons-math/blob/845e1d54/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Mean.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Mean.java b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Mean.java index 46a4551..4a23b0e 100644 --- a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Mean.java +++ b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Mean.java @@ -23,11 +23,12 @@ import org.apache.commons.math4.exception.NullArgumentException; import org.apache.commons.math4.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math4.stat.descriptive.WeightedEvaluation; import org.apache.commons.math4.stat.descriptive.summary.Sum; +import org.apache.commons.math4.util.MathArrays; import org.apache.commons.math4.util.MathUtils; /** - *Computes the arithmetic mean of a set of values. Uses the definitional - * formula:
+ * Computes the arithmetic mean of a set of values. Uses the definitional + * formula: ** mean = sum(x_i) / n *
@@ -58,13 +59,12 @@ import org.apache.commons.math4.util.MathUtils; * multiple threads access an instance of this class concurrently, and at least * one of the threads invokes theincrement()
or
* clear()
method, it must be synchronized externally.
- *
*/
public class Mean extends AbstractStorelessUnivariateStatistic
implements Serializable, WeightedEvaluation {
/** Serializable version identifier */
- private static final long serialVersionUID = -1296043746617791564L;
+ private static final long serialVersionUID = 20150412L;
/** First moment on which this statistic is based. */
protected FirstMoment moment;
@@ -95,7 +95,7 @@ public class Mean extends AbstractStorelessUnivariateStatistic
/**
* Copy constructor, creates a new {@code Mean} identical
- * to the {@code original}
+ * to the {@code original}.
*
* @param original the {@code Mean} instance to copy
* @throws NullArgumentException if original is null
@@ -160,9 +160,10 @@ public class Mean extends AbstractStorelessUnivariateStatistic
* parameters are not valid
*/
@Override
- public double evaluate(final double[] values,final int begin, final int length)
- throws MathIllegalArgumentException {
- if (test(values, begin, length)) {
+ public double evaluate(final double[] values, final int begin, final int length)
+ throws MathIllegalArgumentException {
+
+ if (MathArrays.verifyValues(values, begin, length)) {
Sum sum = new Sum();
double sampleSize = length;
@@ -211,7 +212,7 @@ public class Mean extends AbstractStorelessUnivariateStatistic
@Override
public double evaluate(final double[] values, final double[] weights,
final int begin, final int length) throws MathIllegalArgumentException {
- if (test(values, weights, begin, length)) {
+ if (MathArrays.verifyValues(values, weights, begin, length)) {
Sum sum = new Sum();
// Compute initial estimate using definitional formula
@@ -254,7 +255,7 @@ public class Mean extends AbstractStorelessUnivariateStatistic
*/
@Override
public double evaluate(final double[] values, final double[] weights)
- throws MathIllegalArgumentException {
+ throws MathIllegalArgumentException {
return evaluate(values, weights, 0, values.length);
}
@@ -269,7 +270,6 @@ public class Mean extends AbstractStorelessUnivariateStatistic
return result;
}
-
/**
* Copies source to dest.
* Neither source nor dest can be null.
@@ -282,7 +282,6 @@ public class Mean extends AbstractStorelessUnivariateStatistic throws NullArgumentException { MathUtils.checkNotNull(source); MathUtils.checkNotNull(dest); - dest.setData(source.getDataRef()); dest.incMoment = source.incMoment; dest.moment = source.moment.copy(); } http://git-wip-us.apache.org/repos/asf/commons-math/blob/845e1d54/src/main/java/org/apache/commons/math4/stat/descriptive/moment/SecondMoment.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/SecondMoment.java b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/SecondMoment.java index e617ada..6cab875 100644 --- a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/SecondMoment.java +++ b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/SecondMoment.java @@ -44,18 +44,17 @@ import org.apache.commons.math4.util.MathUtils; * multiple threads access an instance of this class concurrently, and at least * one of the threads invokes theincrement()
or
* clear()
method, it must be synchronized externally.
- *
*/
public class SecondMoment extends FirstMoment implements Serializable {
/** Serializable version identifier */
- private static final long serialVersionUID = 3942403127395076445L;
+ private static final long serialVersionUID = 20150412L;
/** second moment of values that have been added */
protected double m2;
/**
- * Create a SecondMoment instance
+ * Create a SecondMoment instance.
*/
public SecondMoment() {
super();
@@ -64,13 +63,12 @@ public class SecondMoment extends FirstMoment implements Serializable {
/**
* Copy constructor, creates a new {@code SecondMoment} identical
- * to the {@code original}
+ * to the {@code original}.
*
* @param original the {@code SecondMoment} instance to copy
* @throws NullArgumentException if original is null
*/
- public SecondMoment(SecondMoment original)
- throws NullArgumentException {
+ public SecondMoment(SecondMoment original) throws NullArgumentException {
super(original);
this.m2 = original.m2;
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/845e1d54/src/main/java/org/apache/commons/math4/stat/descriptive/moment/SemiVariance.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/SemiVariance.java b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/SemiVariance.java
index 10c8659..2c8f840 100644
--- a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/SemiVariance.java
+++ b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/SemiVariance.java
@@ -22,6 +22,7 @@ import java.io.Serializable;
import org.apache.commons.math4.exception.MathIllegalArgumentException;
import org.apache.commons.math4.exception.NullArgumentException;
import org.apache.commons.math4.stat.descriptive.AbstractUnivariateStatistic;
+import org.apache.commons.math4.util.MathArrays;
import org.apache.commons.math4.util.MathUtils;
/**
@@ -66,11 +67,11 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali
public static final Direction DOWNSIDE_VARIANCE = Direction.DOWNSIDE;
/** Serializable version identifier */
- private static final long serialVersionUID = -2653430366886024994L;
+ private static final long serialVersionUID = 20150412L;
/**
* Determines whether or not bias correction is applied when computing the
- * value of the statisic. True means that bias is corrected.
+ * value of the statistic. True means that bias is corrected.
*/
private boolean biasCorrected = true;
@@ -98,7 +99,6 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali
this.biasCorrected = biasCorrected;
}
-
/**
* Constructs a SemiVariance with the specified Direction
property
* and default (true) biasCorrected
property
@@ -110,7 +110,6 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali
this.varianceDirection = direction;
}
-
/**
* Constructs a SemiVariance with the specified isBiasCorrected
* property and the specified Direction
property.
@@ -127,10 +126,9 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali
this.varianceDirection = direction;
}
-
/**
* Copy constructor, creates a new {@code SemiVariance} identical
- * to the {@code original}
+ * to the {@code original}.
*
* @param original the {@code SemiVariance} instance to copy
* @throws NullArgumentException if original is null
@@ -139,7 +137,6 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali
copy(original, this);
}
-
/**
* {@inheritDoc}
*/
@@ -151,7 +148,6 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali
return result;
}
-
/**
* Copies source to dest.
* Neither source nor dest can be null.
@@ -164,84 +160,81 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali throws NullArgumentException { MathUtils.checkNotNull(source); MathUtils.checkNotNull(dest); - dest.setData(source.getDataRef()); dest.biasCorrected = source.biasCorrected; dest.varianceDirection = source.varianceDirection; } /** - *Returns the {@link SemiVariance} of the designated values against the mean, using - * instance properties varianceDirection and biasCorrection.
+ *Returns the {@link SemiVariance} of the designated values against the mean, using + * instance properties varianceDirection and biasCorrection.
+ * + *Returns NaN
if the array is empty and throws
+ * IllegalArgumentException
if the array is null.
Returns the {@link SemiVariance} of the designated values against the cutoff, using + * instance properties variancDirection and biasCorrection.
* *Returns NaN
if the array is empty and throws
- * IllegalArgumentException
if the array is null.
MathIllegalArgumentException
if the array is null.
*
* @param values the input array
- * @param start index of the first array element to include
- * @param length the number of elements to include
+ * @param cutoff the reference point
* @return the SemiVariance
- * @throws MathIllegalArgumentException if the parameters are not valid
- *
+ * @throws MathIllegalArgumentException if values is null
*/
- @Override
- public double evaluate(final double[] values, final int start, final int length)
- throws MathIllegalArgumentException {
- double m = (new Mean()).evaluate(values, start, length);
- return evaluate(values, m, varianceDirection, biasCorrected, 0, values.length);
- }
-
-
- /**
- * This method calculates {@link SemiVariance} for the entire array against the mean, using
- * the current value of the biasCorrection instance property.
- *
- * @param values the input array
- * @param direction the {@link Direction} of the semivariance
- * @return the SemiVariance
- * @throws MathIllegalArgumentException if values is null
- *
- */
- public double evaluate(final double[] values, Direction direction)
- throws MathIllegalArgumentException {
- double m = (new Mean()).evaluate(values);
- return evaluate (values, m, direction, biasCorrected, 0, values.length);
- }
-
- /**
- * Returns the {@link SemiVariance} of the designated values against the cutoff, using - * instance properties variancDirection and biasCorrection.
- * - *Returns NaN
if the array is empty and throws
- * MathIllegalArgumentException
if the array is null.
Returns the {@link SemiVariance} of the designated values against the cutoff in the - * given direction, using the current value of the biasCorrection instance property.
- * - *Returns NaN
if the array is empty and throws
- * MathIllegalArgumentException
if the array is null.
Returns the {@link SemiVariance} of the designated values against the cutoff in the + * given direction, using the current value of the biasCorrection instance property.
+ * + *Returns NaN
if the array is empty and throws
+ * MathIllegalArgumentException
if the array is null.
Returns the {@link SemiVariance} of the designated values against the cutoff
@@ -260,110 +253,111 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali
* @throws MathIllegalArgumentException if the parameters are not valid
*
*/
- public double evaluate (final double[] values, final double cutoff, final Direction direction,
- final boolean corrected, final int start, final int length) throws MathIllegalArgumentException {
-
- test(values, start, length);
- if (values.length == 0) {
- return Double.NaN;
- } else {
- if (values.length == 1) {
- return 0.0;
- } else {
- final boolean booleanDirection = direction.getDirection();
-
- double dev = 0.0;
- double sumsq = 0.0;
- for (int i = start; i < length; i++) {
- if ((values[i] > cutoff) == booleanDirection) {
- dev = values[i] - cutoff;
- sumsq += dev * dev;
- }
- }
-
- if (corrected) {
- return sumsq / (length - 1.0);
- } else {
- return sumsq / length;
- }
- }
- }
- }
+ public double evaluate (final double[] values, final double cutoff, final Direction direction,
+ final boolean corrected, final int start, final int length)
+ throws MathIllegalArgumentException {
+
+ MathArrays.verifyValues(values, start, length);
+ if (values.length == 0) {
+ return Double.NaN;
+ } else {
+ if (values.length == 1) {
+ return 0.0;
+ } else {
+ final boolean booleanDirection = direction.getDirection();
+
+ double dev = 0.0;
+ double sumsq = 0.0;
+ for (int i = start; i < length; i++) {
+ if ((values[i] > cutoff) == booleanDirection) {
+ dev = values[i] - cutoff;
+ sumsq += dev * dev;
+ }
+ }
+
+ if (corrected) {
+ return sumsq / (length - 1.0);
+ } else {
+ return sumsq / length;
+ }
+ }
+ }
+ }
- /**
- * Returns true iff biasCorrected property is set to true.
- *
- * @return the value of biasCorrected.
- */
- public boolean isBiasCorrected() {
- return biasCorrected;
- }
+ /**
+ * Returns true iff biasCorrected property is set to true.
+ *
+ * @return the value of biasCorrected.
+ */
+ public boolean isBiasCorrected() {
+ return biasCorrected;
+ }
- /**
- * Sets the biasCorrected property.
- *
- * @param biasCorrected new biasCorrected property value
- */
- public void setBiasCorrected(boolean biasCorrected) {
- this.biasCorrected = biasCorrected;
- }
+ /**
+ * Sets the biasCorrected property.
+ *
+ * @param biasCorrected new biasCorrected property value
+ */
+ public void setBiasCorrected(boolean biasCorrected) {
+ this.biasCorrected = biasCorrected;
+ }
- /**
- * Returns the varianceDirection property.
- *
- * @return the varianceDirection
- */
- public Direction getVarianceDirection () {
- return varianceDirection;
- }
+ /**
+ * Returns the varianceDirection property.
+ *
+ * @return the varianceDirection
+ */
+ public Direction getVarianceDirection () {
+ return varianceDirection;
+ }
- /**
- * Sets the variance direction
- *
- * @param varianceDirection the direction of the semivariance
- */
- public void setVarianceDirection(Direction varianceDirection) {
- this.varianceDirection = varianceDirection;
- }
+ /**
+ * Sets the variance direction
+ *
+ * @param varianceDirection the direction of the semivariance
+ */
+ public void setVarianceDirection(Direction varianceDirection) {
+ this.varianceDirection = varianceDirection;
+ }
- /**
- * The direction of the semivariance - either upside or downside. The direction
- * is represented by boolean, with true corresponding to UPSIDE semivariance.
- */
- public enum Direction {
- /**
- * The UPSIDE Direction is used to specify that the observations above the
- * cutoff point will be used to calculate SemiVariance
- */
- UPSIDE (true),
-
- /**
- * The DOWNSIDE Direction is used to specify that the observations below
- * the cutoff point will be used to calculate SemiVariance
- */
- DOWNSIDE (false);
-
- /**
- * boolean value UPSIDE <-> true
- */
- private boolean direction;
-
- /**
- * Create a Direction with the given value.
- *
- * @param b boolean value representing the Direction. True corresponds to UPSIDE.
- */
- Direction (boolean b) {
- direction = b;
- }
-
- /**
- * Returns the value of this Direction. True corresponds to UPSIDE.
- *
- * @return true if direction is UPSIDE; false otherwise
- */
- boolean getDirection () {
- return direction;
- }
- }
+ /**
+ * The direction of the semivariance - either upside or downside. The direction
+ * is represented by boolean, with true corresponding to UPSIDE semivariance.
+ */
+ public enum Direction {
+ /**
+ * The UPSIDE Direction is used to specify that the observations above the
+ * cutoff point will be used to calculate SemiVariance
+ */
+ UPSIDE (true),
+
+ /**
+ * The DOWNSIDE Direction is used to specify that the observations below
+ * the cutoff point will be used to calculate SemiVariance
+ */
+ DOWNSIDE (false);
+
+ /**
+ * boolean value UPSIDE <-> true
+ */
+ private boolean direction;
+
+ /**
+ * Create a Direction with the given value.
+ *
+ * @param b boolean value representing the Direction. True corresponds to UPSIDE.
+ */
+ Direction (boolean b) {
+ direction = b;
+ }
+
+ /**
+ * Returns the value of this Direction. True corresponds to UPSIDE.
+ *
+ * @return true if direction is UPSIDE; false otherwise
+ */
+ boolean getDirection () {
+ return direction;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/845e1d54/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Skewness.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Skewness.java b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Skewness.java
index 3b488c9..8dca668 100644
--- a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Skewness.java
+++ b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Skewness.java
@@ -22,6 +22,7 @@ import org.apache.commons.math4.exception.MathIllegalArgumentException;
import org.apache.commons.math4.exception.NullArgumentException;
import org.apache.commons.math4.stat.descriptive.AbstractStorelessUnivariateStatistic;
import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.math4.util.MathArrays;
import org.apache.commons.math4.util.MathUtils;
/**
@@ -38,12 +39,11 @@ import org.apache.commons.math4.util.MathUtils;
* multiple threads access an instance of this class concurrently, and at least
* one of the threads invokes the increment()
or
* clear()
method, it must be synchronized externally.
* See {@link Skewness} for the definition used in the computation.
@@ -149,19 +149,18 @@ public class Skewness extends AbstractStorelessUnivariateStatistic implements Se * @param values the input array * @param begin the index of the first array element to include * @param length the number of elements to include - * @return the skewness of the values or Double.NaN if length is less than - * 3 + * @return the skewness of the values or Double.NaN if length is less than 3 * @throws MathIllegalArgumentException if the array is null or the array index * parameters are not valid */ @Override - public double evaluate(final double[] values,final int begin, - final int length) throws MathIllegalArgumentException { + public double evaluate(final double[] values,final int begin, final int length) + throws MathIllegalArgumentException { // Initialize the skewness double skew = Double.NaN; - if (test(values, begin, length) && length > 2 ){ + if (MathArrays.verifyValues(values, begin, length) && length > 2 ) { Mean mean = new Mean(); // Get the mean and the standard deviation double m = mean.evaluate(values, begin, length); @@ -217,7 +216,6 @@ public class Skewness extends AbstractStorelessUnivariateStatistic implements Se throws NullArgumentException { MathUtils.checkNotNull(source); MathUtils.checkNotNull(dest); - dest.setData(source.getDataRef()); dest.moment = new ThirdMoment(source.moment.copy()); dest.incMoment = source.incMoment; } http://git-wip-us.apache.org/repos/asf/commons-math/blob/845e1d54/src/main/java/org/apache/commons/math4/stat/descriptive/moment/StandardDeviation.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/StandardDeviation.java b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/StandardDeviation.java index 0d86be2..d2f5e8b 100644 --- a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/StandardDeviation.java +++ b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/StandardDeviation.java @@ -38,13 +38,12 @@ import org.apache.commons.math4.util.MathUtils; * multiple threads access an instance of this class concurrently, and at least * one of the threads invokes theincrement()
or
* clear()
method, it must be synchronized externally.
- *
*/
public class StandardDeviation extends AbstractStorelessUnivariateStatistic
implements Serializable {
/** Serializable version identifier */
- private static final long serialVersionUID = 5728716329662425188L;
+ private static final long serialVersionUID = 20150412L;
/** Wrapped Variance instance */
private Variance variance = null;
@@ -68,7 +67,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic
/**
* Copy constructor, creates a new {@code StandardDeviation} identical
- * to the {@code original}
+ * to the {@code original}.
*
* @param original the {@code StandardDeviation} instance to copy
* @throws NullArgumentException if original is null
@@ -78,7 +77,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic
}
/**
- * Contructs a StandardDeviation with the specified value for the
+ * Constructs a StandardDeviation with the specified value for the
* isBiasCorrected
property. If this property is set to
* true
, the {@link Variance} used in computing results will
* use the bias-corrected, or "sample" formula. See {@link Variance} for
@@ -92,7 +91,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic
}
/**
- * Contructs a StandardDeviation with the specified value for the
+ * Constructs a StandardDeviation with the specified value for the
* isBiasCorrected
property and the supplied external moment.
* If isBiasCorrected
is set to true
, the
* {@link Variance} used in computing results will use the bias-corrected,
@@ -177,8 +176,8 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic
*/
@Override
public double evaluate(final double[] values, final int begin, final int length)
- throws MathIllegalArgumentException {
- return FastMath.sqrt(variance.evaluate(values, begin, length));
+ throws MathIllegalArgumentException {
+ return FastMath.sqrt(variance.evaluate(values, begin, length));
}
/**
@@ -206,7 +205,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic
* parameters are not valid
*/
public double evaluate(final double[] values, final double mean,
- final int begin, final int length) throws MathIllegalArgumentException {
+ final int begin, final int length) throws MathIllegalArgumentException {
return FastMath.sqrt(variance.evaluate(values, mean, begin, length));
}
@@ -232,7 +231,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic
* @throws MathIllegalArgumentException if the array is null
*/
public double evaluate(final double[] values, final double mean)
- throws MathIllegalArgumentException {
+ throws MathIllegalArgumentException {
return FastMath.sqrt(variance.evaluate(values, mean));
}
@@ -261,7 +260,6 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic
return result;
}
-
/**
* Copies source to dest.
* Neither source nor dest can be null.
@@ -270,11 +268,9 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic * @param dest StandardDeviation to copy to * @throws NullArgumentException if either source or dest is null */ - public static void copy(StandardDeviation source, StandardDeviation dest) - throws NullArgumentException { + public static void copy(StandardDeviation source, StandardDeviation dest) throws NullArgumentException { MathUtils.checkNotNull(source); MathUtils.checkNotNull(dest); - dest.setData(source.getDataRef()); dest.variance = source.variance.copy(); } http://git-wip-us.apache.org/repos/asf/commons-math/blob/845e1d54/src/main/java/org/apache/commons/math4/stat/descriptive/moment/ThirdMoment.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/ThirdMoment.java b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/ThirdMoment.java index ba74055..b26b77f 100644 --- a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/ThirdMoment.java +++ b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/ThirdMoment.java @@ -51,12 +51,12 @@ import org.apache.commons.math4.util.MathUtils; class ThirdMoment extends SecondMoment implements Serializable { /** Serializable version identifier */ - private static final long serialVersionUID = -7818711964045118679L; + private static final long serialVersionUID = 20150412L; /** third moment of values that have been added */ protected double m3; - /** + /** * Square of deviation of most recently added value from previous first * moment, normalized by previous sample size. Retained to prevent * repeated computation in higher order moments. nDevSq = nDev * nDev. @@ -64,7 +64,7 @@ class ThirdMoment extends SecondMoment implements Serializable { protected double nDevSq; /** - * Create a FourthMoment instance + * Create a FourthMoment instance. */ public ThirdMoment() { super(); @@ -74,10 +74,10 @@ class ThirdMoment extends SecondMoment implements Serializable { /** * Copy constructor, creates a new {@code ThirdMoment} identical - * to the {@code original} + * to the {@code original}. * * @param original the {@code ThirdMoment} instance to copy - * @throws NullArgumentException if orginal is null + * @throws NullArgumentException if original is null */ public ThirdMoment(ThirdMoment original) throws NullArgumentException { copy(original, this); http://git-wip-us.apache.org/repos/asf/commons-math/blob/845e1d54/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Variance.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Variance.java b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Variance.java index c7602ae..d88f952 100644 --- a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Variance.java +++ b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/Variance.java @@ -23,6 +23,7 @@ import org.apache.commons.math4.exception.NullArgumentException; import org.apache.commons.math4.exception.util.LocalizedFormats; import org.apache.commons.math4.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math4.stat.descriptive.WeightedEvaluation; +import org.apache.commons.math4.util.MathArrays; import org.apache.commons.math4.util.MathUtils; /** @@ -64,12 +65,11 @@ import org.apache.commons.math4.util.MathUtils; * multiple threads access an instance of this class concurrently, and at least * one of the threads invokes theincrement()
or
* clear()
method, it must be synchronized externally.
- *
*/
public class Variance extends AbstractStorelessUnivariateStatistic implements Serializable, WeightedEvaluation {
/** Serializable version identifier */
- private static final long serialVersionUID = -9111962718267217978L;
+ private static final long serialVersionUID = 20150412L;
/** SecondMoment is used in incremental calculation of Variance*/
protected SecondMoment moment = null;
@@ -100,13 +100,13 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
/**
* Constructs a Variance based on an external second moment.
+ *
* When this constructor is used, the statistic may only be
* incremented via the moment, i.e., {@link #increment(double)}
* does nothing; whereas {@code m2.increment(value)} increments
* both {@code m2} and the Variance instance constructed from it.
*
- * @param m2 the SecondMoment (Third or Fourth moments work
- * here as well.)
+ * @param m2 the SecondMoment (Third or Fourth moments work here as well.)
*/
public Variance(final SecondMoment m2) {
incMoment = false;
@@ -115,7 +115,7 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
/**
* Constructs a Variance with the specified isBiasCorrected
- * property
+ * property.
*
* @param isBiasCorrected setting for bias correction - true means
* bias will be corrected and is equivalent to using the argumentless
@@ -143,7 +143,7 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
/**
* Copy constructor, creates a new {@code Variance} identical
- * to the {@code original}
+ * to the {@code original}.
*
* @param original the {@code Variance} instance to copy
* @throws NullArgumentException if original is null
@@ -177,17 +177,17 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
*/
@Override
public double getResult() {
- if (moment.n == 0) {
- return Double.NaN;
- } else if (moment.n == 1) {
- return 0d;
+ if (moment.n == 0) {
+ return Double.NaN;
+ } else if (moment.n == 1) {
+ return 0d;
+ } else {
+ if (isBiasCorrected) {
+ return moment.m2 / (moment.n - 1d);
} else {
- if (isBiasCorrected) {
- return moment.m2 / (moment.n - 1d);
- } else {
- return moment.m2 / (moment.n);
- }
+ return moment.m2 / (moment.n);
}
+ }
}
/**
@@ -255,12 +255,11 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
*/
@Override
public double evaluate(final double[] values, final int begin, final int length)
- throws MathIllegalArgumentException {
+ throws MathIllegalArgumentException {
double var = Double.NaN;
- if (test(values, begin, length)) {
- clear();
+ if (MathArrays.verifyValues(values, begin, length)) {
if (length == 1) {
var = 0.0;
} else if (length > 1) {
@@ -320,8 +319,7 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
double var = Double.NaN;
- if (test(values, weights,begin, length)) {
- clear();
+ if (MathArrays.verifyValues(values, weights,begin, length)) {
if (length == 1) {
var = 0.0;
} else if (length > 1) {
@@ -373,7 +371,7 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
*/
@Override
public double evaluate(final double[] values, final double[] weights)
- throws MathIllegalArgumentException {
+ throws MathIllegalArgumentException {
return evaluate(values, weights, 0, values.length);
}
@@ -404,11 +402,11 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
* parameters are not valid
*/
public double evaluate(final double[] values, final double mean,
- final int begin, final int length) throws MathIllegalArgumentException {
+ final int begin, final int length) throws MathIllegalArgumentException {
double var = Double.NaN;
- if (test(values, begin, length)) {
+ if (MathArrays.verifyValues(values, begin, length)) {
if (length == 1) {
var = 0.0;
} else if (length > 1) {
@@ -506,12 +504,12 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
* @since 2.1
*/
public double evaluate(final double[] values, final double[] weights,
- final double mean, final int begin, final int length)
- throws MathIllegalArgumentException {
+ final double mean, final int begin, final int length)
+ throws MathIllegalArgumentException {
double var = Double.NaN;
- if (test(values, weights, begin, length)) {
+ if (MathArrays.verifyValues(values, weights, begin, length)) {
if (length == 1) {
var = 0.0;
} else if (length > 1) {
@@ -581,7 +579,7 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
* @since 2.1
*/
public double evaluate(final double[] values, final double[] weights, final double mean)
- throws MathIllegalArgumentException {
+ throws MathIllegalArgumentException {
return evaluate(values, weights, mean, 0, values.length);
}
@@ -622,7 +620,6 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se
throws NullArgumentException {
MathUtils.checkNotNull(source);
MathUtils.checkNotNull(dest);
- dest.setData(source.getDataRef());
dest.moment = source.moment.copy();
dest.isBiasCorrected = source.isBiasCorrected;
dest.incMoment = source.incMoment;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/845e1d54/src/main/java/org/apache/commons/math4/stat/descriptive/rank/Max.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/rank/Max.java b/src/main/java/org/apache/commons/math4/stat/descriptive/rank/Max.java
index 60efe1b..502d2d4 100644
--- a/src/main/java/org/apache/commons/math4/stat/descriptive/rank/Max.java
+++ b/src/main/java/org/apache/commons/math4/stat/descriptive/rank/Max.java
@@ -21,6 +21,7 @@ import java.io.Serializable;
import org.apache.commons.math4.exception.MathIllegalArgumentException;
import org.apache.commons.math4.exception.NullArgumentException;
import org.apache.commons.math4.stat.descriptive.AbstractStorelessUnivariateStatistic;
+import org.apache.commons.math4.util.MathArrays;
import org.apache.commons.math4.util.MathUtils;
/**
@@ -37,12 +38,11 @@ import org.apache.commons.math4.util.MathUtils;
* multiple threads access an instance of this class concurrently, and at least
* one of the threads invokes the increment()
or
* clear()
method, it must be synchronized externally.
increment()
or
* clear()
method, it must be synchronized externally.
- *
*/
public class Median extends Percentile implements Serializable {
/** Serializable version identifier */
- private static final long serialVersionUID = -3961477041290915687L;
+ private static final long serialVersionUID = 20150412L;
/** Fixed quantile. */
private static final double FIXED_QUANTILE_50 = 50.0;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/845e1d54/src/main/java/org/apache/commons/math4/stat/descriptive/rank/Min.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/rank/Min.java b/src/main/java/org/apache/commons/math4/stat/descriptive/rank/Min.java
index 0152e48..72eaef4 100644
--- a/src/main/java/org/apache/commons/math4/stat/descriptive/rank/Min.java
+++ b/src/main/java/org/apache/commons/math4/stat/descriptive/rank/Min.java
@@ -21,6 +21,7 @@ import java.io.Serializable;
import org.apache.commons.math4.exception.MathIllegalArgumentException;
import org.apache.commons.math4.exception.NullArgumentException;
import org.apache.commons.math4.stat.descriptive.AbstractStorelessUnivariateStatistic;
+import org.apache.commons.math4.util.MathArrays;
import org.apache.commons.math4.util.MathUtils;
/**
@@ -37,12 +38,11 @@ import org.apache.commons.math4.util.MathUtils;
* multiple threads access an instance of this class concurrently, and at least
* one of the threads invokes the increment()
or
* clear()
method, it must be synchronized externally.
- *
*/
public class Min extends AbstractStorelessUnivariateStatistic implements Serializable {
/** Serializable version identifier */
- private static final long serialVersionUID = -2941995784909003131L;
+ private static final long serialVersionUID = 20150412L;
/**Number of values that have been added */
private long n;
@@ -51,7 +51,7 @@ public class Min extends AbstractStorelessUnivariateStatistic implements Seriali
private double value;
/**
- * Create a Min instance
+ * Create a Min instance.
*/
public Min() {
n = 0;
@@ -60,7 +60,7 @@ public class Min extends AbstractStorelessUnivariateStatistic implements Seriali
/**
* Copy constructor, creates a new {@code Min} identical
- * to the {@code original}
+ * to the {@code original}.
*
* @param original the {@code Min} instance to copy
* @throws NullArgumentException if original is null
@@ -129,9 +129,10 @@ public class Min extends AbstractStorelessUnivariateStatistic implements Seriali
*/
@Override
public double evaluate(final double[] values,final int begin, final int length)
- throws MathIllegalArgumentException {
+ throws MathIllegalArgumentException {
+
double min = Double.NaN;
- if (test(values, begin, length)) {
+ if (MathArrays.verifyValues(values, begin, length)) {
min = values[begin];
for (int i = begin; i < begin + length; i++) {
if (!Double.isNaN(values[i])) {
@@ -165,7 +166,6 @@ public class Min extends AbstractStorelessUnivariateStatistic implements Seriali
throws NullArgumentException {
MathUtils.checkNotNull(source);
MathUtils.checkNotNull(dest);
- dest.setData(source.getDataRef());
dest.n = source.n;
dest.value = source.value;
}