Repository: commons-math
Updated Branches:
  refs/heads/master 1f07a0bf7 -> 60bcdd450


Revert "MATH-1441: Cache instance of "TDistribution"."

This reverts commit 1f07a0bf70049cb0a2f6b52ea7c261da5adb1abb.

Caching does not seem to provide any perfomance improvement.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/60bcdd45
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/60bcdd45
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/60bcdd45

Branch: refs/heads/master
Commit: 60bcdd450d6950da981d70b8b08379bdd744c82d
Parents: 1f07a0b
Author: Gilles <er...@apache.org>
Authored: Sat Jan 27 00:39:45 2018 +0100
Committer: Gilles <er...@apache.org>
Committed: Sat Jan 27 00:39:45 2018 +0100

----------------------------------------------------------------------
 .../math4/stat/regression/SimpleRegression.java | 26 ++++----------------
 1 file changed, 5 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/60bcdd45/src/main/java/org/apache/commons/math4/stat/regression/SimpleRegression.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/math4/stat/regression/SimpleRegression.java 
b/src/main/java/org/apache/commons/math4/stat/regression/SimpleRegression.java
index f7340a3..7fc823d 100644
--- 
a/src/main/java/org/apache/commons/math4/stat/regression/SimpleRegression.java
+++ 
b/src/main/java/org/apache/commons/math4/stat/regression/SimpleRegression.java
@@ -91,9 +91,6 @@ public class SimpleRegression implements Serializable, 
UpdatingMultipleLinearReg
 
     /** include an intercept or not */
     private final boolean hasIntercept;
-
-    /** Cache (performance optimization). */
-    private transient TDistribution distribution;
     // ---------------------Public 
methods--------------------------------------
 
     /**
@@ -700,8 +697,9 @@ public class SimpleRegression implements Serializable, 
UpdatingMultipleLinearReg
                                           alpha, 0, 1);
         }
         // No advertised NotStrictlyPositiveException here - will return NaN 
above
+        TDistribution distribution = new TDistribution(n - 2);
         return getSlopeStdErr() *
-            getDistribution().inverseCumulativeProbability(1d - alpha / 2d);
+            distribution.inverseCumulativeProbability(1d - alpha / 2d);
     }
 
     /**
@@ -731,28 +729,14 @@ public class SimpleRegression implements Serializable, 
UpdatingMultipleLinearReg
             return Double.NaN;
         }
         // No advertised NotStrictlyPositiveException here - will return NaN 
above
-        return 2d * (1.0 - getDistribution()
-                     .cumulativeProbability(FastMath.abs(getSlope()) / 
getSlopeStdErr()));
+        TDistribution distribution = new TDistribution(n - 2);
+        return 2d * (1.0 - distribution.cumulativeProbability(
+                    FastMath.abs(getSlope()) / getSlopeStdErr()));
     }
 
     // ---------------------Private methods-----------------------------------
 
     /**
-     * Computes or return a cached distribution.
-     *
-     * @return the distribution.
-     */
-    private TDistribution getDistribution() {
-        final double numDeg = n - 2;
-        if (distribution == null ||
-            distribution.getDegreesOfFreedom() != numDeg) {
-            distribution = new TDistribution(numDeg);
-        }
-
-        return distribution;
-    }
-
-    /**
     * Returns the intercept of the estimated regression line, given the slope.
     * <p>
     * Will return <code>NaN</code> if slope is <code>NaN</code>.</p>

Reply via email to