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/06/29 17:39:16 UTC
cvs commit: jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary Sum.java SumOfSquares.java
psteitz 2004/06/29 08:39:16
Modified: math/src/java/org/apache/commons/math/stat/univariate/summary
Sum.java SumOfSquares.java
Log:
Fixed, documented NaN handling; changed internal counter to long; replaced pow with *.
Revision Changes Path
1.22 +2 -2 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary/Sum.java
Index: Sum.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary/Sum.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- Sum.java 29 Jun 2004 14:50:21 -0000 1.21
+++ Sum.java 29 Jun 2004 15:39:15 -0000 1.22
@@ -33,7 +33,7 @@
static final long serialVersionUID = -8231831954703408316L;
/** */
- private int n = 0;
+ private long n = 0;
/**
* The currently running sum.
1.19 +11 -16 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary/SumOfSquares.java
Index: SumOfSquares.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary/SumOfSquares.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- SumOfSquares.java 23 Jun 2004 16:26:16 -0000 1.18
+++ SumOfSquares.java 29 Jun 2004 15:39:15 -0000 1.19
@@ -17,17 +17,14 @@
import java.io.Serializable;
-import org
- .apache
- .commons
- .math
- .stat
- .univariate
- .AbstractStorelessUnivariateStatistic;
+import org .apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatistic;
/**
* Returns the sum of the squares of the available values.
- *
+ * <p>
+ * If there are no values in the dataset, or any of the values are
+ * <code>NaN</code>, then <code>NaN</code> is returned.
+ *
* @version $Revision$ $Date$
*/
public class SumOfSquares extends AbstractStorelessUnivariateStatistic implements Serializable {
@@ -36,7 +33,7 @@
static final long serialVersionUID = 1460986908574398008L;
/** */
- private int n = 0;
+ private long n = 0;
/**
* The currently running sumSq
@@ -47,7 +44,7 @@
* @see org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
public void increment(final double d) {
- if (Double.isNaN(value)) {
+ if (n == 0) {
value = d * d;
} else {
value += d * d;
@@ -79,21 +76,19 @@
/**
* Returns the sum of the squares of the available values.
+ *
* @param values Is a double[] containing the values
* @param begin processing at this point in the array
* @param length the number of elements to include
* @return the sum of the squared values or Double.NaN if the array is empty
* @see org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int, int)
*/
- public double evaluate(
- final double[] values,
- final int begin,
- final int length) {
+ public double evaluate(final double[] values,final int begin, final int length) {
double sumSq = Double.NaN;
if (test(values, begin, length)) {
sumSq = 0.0;
for (int i = begin; i < begin + length; i++) {
- sumSq += Math.pow(values[i], 2.0);
+ sumSq += values[i] * values[i];
}
}
return sumSq;
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org