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 2006/07/06 07:10:49 UTC
svn commit: r419439 - in /jakarta/commons/proper/math/trunk:
src/java/org/apache/commons/math/stat/regression/SimpleRegression.java
src/test/org/apache/commons/math/stat/regression/SimpleRegressionTest.java
xdocs/changes.xml
Author: psteitz
Date: Wed Jul 5 22:10:49 2006
New Revision: 419439
URL: http://svn.apache.org/viewvc?rev=419439&view=rev
Log:
Modified getSumSquaredErrors method in SimpleRegression to always
return a non-negative result.
JIRA: MATH-85
Reported by Mark Osborn
Patched by Luc Maisonobe
Modified:
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/SimpleRegressionTest.java
jakarta/commons/proper/math/trunk/xdocs/changes.xml
Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java?rev=419439&r1=419438&r2=419439&view=diff
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java Wed Jul 5 22:10:49 2006
@@ -236,6 +236,21 @@
* sum of squared errors</a> (SSE) associated with the regression
* model.
* <p>
+ * The sum is computed using the computational formula
+ * <p>
+ * <code>SSE = SYY - (SXY * SXY / SXX)</code>
+ * <p>
+ * where <code>SYY</code> is the sum of the squared deviations of the y
+ * values about their mean, <code>SXX</code> is similarly defined and
+ * <code>SXY</code> is the sum of the products of x and y mean deviations.
+ * <p>
+ * The sums are accumulated using the updating algorithm referenced in
+ * {@link #addData}.
+ * <p>
+ * The return value is constrained to be non-negative - i.e., if due to
+ * rounding errors the computational formula returns a negative result,
+ * 0 is returned.
+ * <p>
* <strong>Preconditions</strong>: <ul>
* <li>At least two observations (with at least two different x values)
* must have been added before invoking this method. If this method is
@@ -246,7 +261,7 @@
* @return sum of squared errors associated with the regression model
*/
public double getSumSquaredErrors() {
- return sumYY - sumXY * sumXY / sumXX;
+ return Math.max(0d, sumYY - sumXY * sumXY / sumXX);
}
/**
Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/SimpleRegressionTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/SimpleRegressionTest.java?rev=419439&r1=419438&r2=419439&view=diff
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/SimpleRegressionTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/SimpleRegressionTest.java Wed Jul 5 22:10:49 2006
@@ -237,6 +237,7 @@
}
assertEquals(0.0, regression.getSignificance(), 1.0e-5);
assertTrue(regression.getSlope() > 0.0);
+ assertTrue(regression.getSumSquaredErrors() >= 0.0);
}
public void testPerfectNegative() throws Exception {
@@ -261,4 +262,16 @@
assertTrue( 0.0 < regression.getSignificance()
&& regression.getSignificance() < 1.0);
}
+
+
+ // Jira MATH-85 = Bugzilla 39432
+ public void testSSENonNegative() {
+ double[] y = { 8915.102, 8919.302, 8923.502 };
+ double[] x = { 1.107178495E2, 1.107264895E2, 1.107351295E2 };
+ SimpleRegression reg = new SimpleRegression();
+ for (int i = 0; i < x.length; i++) {
+ reg.addData(x[i], y[i]);
+ }
+ assertTrue(reg.getSumSquaredErrors() >= 0.0);
+ }
}
Modified: jakarta/commons/proper/math/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/xdocs/changes.xml?rev=419439&r1=419438&r2=419439&view=diff
==============================================================================
--- jakarta/commons/proper/math/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/math/trunk/xdocs/changes.xml Wed Jul 5 22:10:49 2006
@@ -62,6 +62,10 @@
<action dev="psteitz" type="update" issue="MATH-140" due-to="Xiaogang Zhang">
Added Fast Fourier Transform implementation.
</action>
+ <action dev="psteitz" type="fix" issue="MATH-85" due-to="Mark Osborn, Luc Maisonobe">
+ Modified getSumSquaredErrors method in SimpleRegression to always
+ return a non-negative result.
+ </action>
</release>
<release version="1.1" date="2005-12-17"
description="This is a maintenance release containing bug fixes and enhancements.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org