You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sebb <se...@gmail.com> on 2009/04/14 13:32:40 UTC
Re: svn commit: r764208 - /commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java
On 11/04/2009, psteitz@apache.org <ps...@apache.org> wrote:
> Author: psteitz
> Date: Sat Apr 11 15:30:02 2009
> New Revision: 764208
>
> URL: http://svn.apache.org/viewvc?rev=764208&view=rev
> Log:
> Restored some double casts to improve ensure correctness does not depend on order of operations or literal conversion, dropped uneccesary parens.
>
> Modified:
> commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java
>
> Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java?rev=764208&r1=764207&r2=764208&view=diff
> ==============================================================================
> --- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java (original)
> +++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java Sat Apr 11 15:30:02 2009
> @@ -124,9 +124,9 @@
> } else {
> double dx = x - xbar;
> double dy = y - ybar;
> - sumXX += dx * dx * n / (n + 1.0);
> - sumYY += dy * dy * n / (n + 1.0);
> - sumXY += dx * dy * n / (n + 1.0);
> + sumXX += dx * dx * (double) n / (n + 1d);
> + sumYY += dy * dy * (double) n / (n + 1d);
> + sumXY += dx * dy * (double) n / (n + 1d);
AFAICT these casts are not necessary, regardless of order.
See:
http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.6.2
Numeric promotion for binary operands (such as * and /) will always
convert the other operand to double if one operand is double.
> xbar += dx / (n + 1.0);
> ybar += dy / (n + 1.0);
> }
> @@ -157,9 +157,9 @@
> if (n > 0) {
> double dx = x - xbar;
> double dy = y - ybar;
> - sumXX -= dx * dx * n / (n - 1.0);
> - sumYY -= dy * dy * n / (n - 1.0);
> - sumXY -= dx * dy * n / (n - 1.0);
> + sumXX -= dx * dx * (double) n / (n - 1d);
> + sumYY -= dy * dy * (double) n / (n - 1d);
> + sumXY -= dx * dy * (double) n / (n - 1d);
Ditto
> xbar -= dx / (n - 1.0);
> ybar -= dy / (n - 1.0);
> sumX -= x;
> @@ -468,7 +468,7 @@
> */
> public double getInterceptStdErr() {
> return Math.sqrt(
> - getMeanSquareError() * ((1d / n) + (xbar * xbar) / sumXX));
> + getMeanSquareError() * ((1d / (double) n) + (xbar * xbar) / sumXX));
Ditto.
> }
>
> /**
> @@ -589,7 +589,7 @@
> * @return the intercept of the regression line
> */
> private double getIntercept(double slope) {
> - return (sumY - slope * sumX) / (n);
> + return (sumY - slope * sumX) / n;
> }
>
> /**
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org