You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ps...@apache.org on 2004/07/05 00:10:02 UTC
cvs commit: jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment StandardDeviation.java
psteitz 2004/07/04 15:10:02
Modified: math/src/java/org/apache/commons/math/stat/univariate/moment
StandardDeviation.java
Log:
Added evaluate method taking mean as a parameter. Changed implementation to wrap, rather than extend Variance.
Revision Changes Path
1.20 +71 -11 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/StandardDeviation.java
Index: StandardDeviation.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/StandardDeviation.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- StandardDeviation.java 4 Jul 2004 09:02:36 -0000 1.19
+++ StandardDeviation.java 4 Jul 2004 22:10:02 -0000 1.20
@@ -17,10 +17,13 @@
import java.io.Serializable;
+import org.apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatistic;
+
/**
* Computes the sample standard deviation. The standard deviation
* is the positive square root of the variance. See {@link Variance} for
- * more information.
+ * more information. This implementation wraps a {@link Variance}
+ * instance.
* <p>
* <strong>Note that this implementation is not synchronized.</strong> If
* multiple threads access an instance of this class concurrently, and at least
@@ -29,16 +32,20 @@
*
* @version $Revision$ $Date$
*/
-public class StandardDeviation extends Variance implements Serializable {
+public class StandardDeviation extends AbstractStorelessUnivariateStatistic
+ implements Serializable {
/** Serializable version identifier */
- static final long serialVersionUID = 5728716329662425188L;
+ static final long serialVersionUID = 5728716329662425188L;
+
+ /** Wrapped Variance instance */
+ protected Variance variance = null;
/**
* Constructs a StandardDeviation
*/
public StandardDeviation() {
- super();
+ variance = new Variance();
}
/**
@@ -47,36 +54,66 @@
* @param m2 the external moment
*/
public StandardDeviation(final SecondMoment m2) {
- super(m2);
+ variance = new Variance(m2);
}
/**
* @see org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
public void increment(final double d) {
- super.increment(d);
+ variance.increment(d);
+ }
+
+ /**
+ * @see org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getN()
+ */
+ public double getN() {
+ return variance.getN();
}
/**
* @see org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
- return Math.sqrt(super.getResult());
+ return Math.sqrt(variance.getResult());
}
/**
* @see org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#clear()
*/
public void clear() {
- super.clear();
+ variance.clear();
}
/**
+ * Returns the Standard Deviation of the entries in the input array, or
+ * <code>Double.NaN</code> if the array is empty.
+ * <p>
+ * Returns 0 for a single-value (i.e. length = 1) sample.
+ * <p>
+ * Throws <code>IllegalArgumentException</code> if the array is null.
+ * <p>
+ * Does not change the internal state of the statistic.
+ *
+ * @param values the input array
+ * @return the standard deviation of the values or Double.NaN if length = 0
+ * @throws IllegalArgumentException if the array is null
+ */
+ public double evaluate(final double[] values) {
+ return Math.sqrt(variance.evaluate(values));
+ }
+
+
+ /**
* Returns the Standard Deviation of the entries in the specified portion of
* the input array, or <code>Double.NaN</code> if the designated subarray
* is empty.
* <p>
* Returns 0 for a single-value (i.e. length = 1) sample.
+ * <p>
+ * Throws <code>IllegalArgumentException</code> if the array is null.
+ * <p>
+ * Does not change the internal state of the statistic.
*
* @param values the input array
* @param begin index of the first array element to include
@@ -86,7 +123,30 @@
* parameters are not valid
*/
public double evaluate(final double[] values, final int begin, final int length) {
- return Math.sqrt(super.evaluate(values, begin, length));
+ return Math.sqrt(variance.evaluate(values, begin, length));
+ }
+
+ /**
+ * Returns the Standard Deviation of the entries in the specified portion of
+ * the input array, using the precomputed mean value. Returns
+ * <code>Double.NaN</code> if the designated subarray is empty.
+ * <p>
+ * Returns 0 for a single-value (i.e. length = 1) sample.
+ * <p>
+ * Throws <code>IllegalArgumentException</code> if the array is null.
+ * <p>
+ * Does not change the internal state of the statistic.
+ *
+ * @param values the input array
+ * @param mean the precomputed mean value
+ * @param begin index of the first array element to include
+ * @param length the number of elements to include
+ * @return the standard deviation of the values or Double.NaN if length = 0
+ * @throws IllegalArgumentException if the array is null or the array index
+ * parameters are not valid
+ */
+ public double evaluate(final double[] values, final double mean,
+ final int begin, final int length) {
+ return Math.sqrt(variance.evaluate(values, mean, begin, length));
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org