From 3f5862a60e1045427b95fa44fdddfb0d4c11a771 Mon Sep 17 00:00:00 2001 From: Phil Steitz Date: Wed, 1 Sep 2004 15:54:39 +0000 Subject: [PATCH] Made assumption about precomputed mean explicit in javadoc. Added missing method. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141437 13f79535-47bb-0310-9956-ffa450edef68 --- .../univariate/moment/StandardDeviation.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/java/org/apache/commons/math/stat/univariate/moment/StandardDeviation.java b/src/java/org/apache/commons/math/stat/univariate/moment/StandardDeviation.java index a47065036..72844356a 100644 --- a/src/java/org/apache/commons/math/stat/univariate/moment/StandardDeviation.java +++ b/src/java/org/apache/commons/math/stat/univariate/moment/StandardDeviation.java @@ -30,7 +30,7 @@ import org.apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatis * one of the threads invokes the increment() or * clear() method, it must be synchronized externally. * - * @version $Revision: 1.22 $ $Date: 2004/07/18 04:42:02 $ + * @version $Revision: 1.23 $ $Date: 2004/09/01 15:54:39 $ */ public class StandardDeviation extends AbstractStorelessUnivariateStatistic implements Serializable { @@ -133,6 +133,11 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic *

* Returns 0 for a single-value (i.e. length = 1) sample. *

+ * The formula used assumes that the supplied mean value is the arithmetic + * mean of the sample data, not a known population parameter. This method + * is supplied only to save computation when the mean has already been + * computed. + *

* Throws IllegalArgumentException if the array is null. *

* Does not change the internal state of the statistic. @@ -149,4 +154,30 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic final int begin, final int length) { return Math.sqrt(variance.evaluate(values, mean, begin, length)); } + + /** + * Returns the Standard Deviation of the entries in the input array, using + * the precomputed mean value. Returns + * Double.NaN if the designated subarray is empty. + *

+ * Returns 0 for a single-value (i.e. length = 1) sample. + *

+ * The formula used assumes that the supplied mean value is the arithmetic + * mean of the sample data, not a known population parameter. This method + * is supplied only to save computation when the mean has already been + * computed. + *

+ * Throws IllegalArgumentException if the array is null. + *

+ * Does not change the internal state of the statistic. + * + * @param values the input array + * @param mean the precomputed mean value + * @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) { + return Math.sqrt(variance.evaluate(values, mean)); + } } \ No newline at end of file