You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2010/08/30 00:04:15 UTC

svn commit: r990658 [5/10] - in /commons/proper/math/trunk: ./ src/main/java/org/apache/commons/math/analysis/ src/main/java/org/apache/commons/math/analysis/integration/ src/main/java/org/apache/commons/math/analysis/interpolation/ src/main/java/org/a...

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/summary/SumOfLogs.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/summary/SumOfLogs.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/summary/SumOfLogs.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/summary/SumOfLogs.java Sun Aug 29 22:04:09 2010
@@ -19,6 +19,7 @@ package org.apache.commons.math.stat.des
 import java.io.Serializable;
 
 import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic;
+import org.apache.commons.math.util.FastMath;
 
 /**
  * Returns the sum of the natural logs for this collection of values.
@@ -77,7 +78,7 @@ public class SumOfLogs extends AbstractS
      */
     @Override
     public void increment(final double d) {
-        value += Math.log(d);
+        value += FastMath.log(d);
         n++;
     }
 
@@ -132,7 +133,7 @@ public class SumOfLogs extends AbstractS
         if (test(values, begin, length)) {
             sumLog = 0.0;
             for (int i = begin; i < begin + length; i++) {
-                sumLog += Math.log(values[i]);
+                sumLog += FastMath.log(values[i]);
             }
         }
         return sumLog;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java Sun Aug 29 22:04:09 2010
@@ -21,6 +21,7 @@ import org.apache.commons.math.MathRunti
 import org.apache.commons.math.distribution.ChiSquaredDistribution;
 import org.apache.commons.math.distribution.ChiSquaredDistributionImpl;
 import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.util.FastMath;
 
 /**
  * Implements Chi-Square test statistics defined in the
@@ -82,7 +83,7 @@ public class ChiSquareTestImpl implement
         }
         double ratio = 1.0d;
         boolean rescale = false;
-        if (Math.abs(sumExpected - sumObserved) > 10E-6) {
+        if (FastMath.abs(sumExpected - sumObserved) > 10E-6) {
             ratio = sumObserved / sumExpected;
             rescale = true;
         }
@@ -256,7 +257,7 @@ public class ChiSquareTestImpl implement
         // Compare and compute weight only if different
         unequalCounts = countSum1 != countSum2;
         if (unequalCounts) {
-            weight = Math.sqrt((double) countSum1 / (double) countSum2);
+            weight = FastMath.sqrt((double) countSum1 / (double) countSum2);
         }
         // Compute ChiSquare statistic
         double sumSq = 0.0d;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java Sun Aug 29 22:04:09 2010
@@ -23,6 +23,7 @@ import org.apache.commons.math.distribut
 import org.apache.commons.math.exception.util.LocalizedFormats;
 import org.apache.commons.math.stat.StatUtils;
 import org.apache.commons.math.stat.descriptive.StatisticalSummary;
+import org.apache.commons.math.util.FastMath;
 
 /**
  * Implements t-test statistics defined in the {@link TTest} interface.
@@ -905,7 +906,7 @@ public class TTestImpl implements TTest 
      * @return t test statistic
      */
     protected double t(double m, double mu, double v, double n) {
-        return (m - mu) / Math.sqrt(v / n);
+        return (m - mu) / FastMath.sqrt(v / n);
     }
 
     /**
@@ -923,7 +924,7 @@ public class TTestImpl implements TTest 
      */
     protected double t(double m1, double m2,  double v1, double v2, double n1,
             double n2)  {
-            return (m1 - m2) / Math.sqrt((v1 / n1) + (v2 / n2));
+            return (m1 - m2) / FastMath.sqrt((v1 / n1) + (v2 / n2));
     }
 
     /**
@@ -941,7 +942,7 @@ public class TTestImpl implements TTest 
     protected double homoscedasticT(double m1, double m2,  double v1,
             double v2, double n1, double n2)  {
             double pooledVariance = ((n1  - 1) * v1 + (n2 -1) * v2 ) / (n1 + n2 - 2);
-            return (m1 - m2) / Math.sqrt(pooledVariance * (1d / n1 + 1d / n2));
+            return (m1 - m2) / FastMath.sqrt(pooledVariance * (1d / n1 + 1d / n2));
     }
 
     /**
@@ -956,7 +957,7 @@ public class TTestImpl implements TTest 
      */
     protected double tTest(double m, double mu, double v, double n)
     throws MathException {
-        double t = Math.abs(t(m, mu, v, n));
+        double t = FastMath.abs(t(m, mu, v, n));
         distribution.setDegreesOfFreedom(n - 1);
         return 2.0 * distribution.cumulativeProbability(-t);
     }
@@ -979,7 +980,7 @@ public class TTestImpl implements TTest 
     protected double tTest(double m1, double m2, double v1, double v2,
             double n1, double n2)
     throws MathException {
-        double t = Math.abs(t(m1, m2, v1, v2, n1, n2));
+        double t = FastMath.abs(t(m1, m2, v1, v2, n1, n2));
         double degreesOfFreedom = 0;
         degreesOfFreedom = df(v1, v2, n1, n2);
         distribution.setDegreesOfFreedom(degreesOfFreedom);
@@ -1004,7 +1005,7 @@ public class TTestImpl implements TTest 
     protected double homoscedasticTTest(double m1, double m2, double v1,
             double v2, double n1, double n2)
     throws MathException {
-        double t = Math.abs(homoscedasticT(m1, m2, v1, v2, n1, n2));
+        double t = FastMath.abs(homoscedasticT(m1, m2, v1, v2, n1, n2));
         double degreesOfFreedom = n1 + n2 - 2;
         distribution.setDegreesOfFreedom(degreesOfFreedom);
         return 2.0 * distribution.cumulativeProbability(-t);

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/ranking/NaturalRanking.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/ranking/NaturalRanking.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/ranking/NaturalRanking.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/ranking/NaturalRanking.java Sun Aug 29 22:04:09 2010
@@ -26,6 +26,7 @@ import org.apache.commons.math.MathRunti
 import org.apache.commons.math.random.RandomData;
 import org.apache.commons.math.random.RandomDataImpl;
 import org.apache.commons.math.random.RandomGenerator;
+import org.apache.commons.math.util.FastMath;
 
 
 /**
@@ -342,7 +343,7 @@ public class NaturalRanking implements R
                 break;
             case RANDOM:    // Fill with random integral values in [c, c + length - 1]
                 Iterator<Integer> iterator = tiesTrace.iterator();
-                long f = Math.round(c);
+                long f = FastMath.round(c);
                 while (iterator.hasNext()) {
                     ranks[iterator.next()] =
                         randomData.nextLong(f, f + length - 1);
@@ -351,7 +352,7 @@ public class NaturalRanking implements R
             case SEQUENTIAL:  // Fill sequentially from c to c + length - 1
                 // walk and fill
                 iterator = tiesTrace.iterator();
-                f = Math.round(c);
+                f = FastMath.round(c);
                 int i = 0;
                 while (iterator.hasNext()) {
                     ranks[iterator.next()] = f + i++;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java Sun Aug 29 22:04:09 2010
@@ -23,6 +23,7 @@ import org.apache.commons.math.linear.Ar
 import org.apache.commons.math.linear.RealVector;
 import org.apache.commons.math.linear.ArrayRealVector;
 import org.apache.commons.math.stat.descriptive.moment.Variance;
+import org.apache.commons.math.util.FastMath;
 
 /**
  * Abstract base class for implementations of MultipleLinearRegression.
@@ -153,7 +154,7 @@ public abstract class AbstractMultipleLi
         int length = betaVariance[0].length;
         double[] result = new double[length];
         for (int i = 0; i < length; i++) {
-            result[i] = Math.sqrt(sigma * betaVariance[i][i]);
+            result[i] = FastMath.sqrt(sigma * betaVariance[i][i]);
         }
         return result;
     }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java Sun Aug 29 22:04:09 2010
@@ -23,6 +23,7 @@ import org.apache.commons.math.MathRunti
 import org.apache.commons.math.distribution.TDistribution;
 import org.apache.commons.math.distribution.TDistributionImpl;
 import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.util.FastMath;
 
 /**
  * Estimates an ordinary least squares regression model
@@ -299,7 +300,7 @@ public class SimpleRegression implements
         if (n < 2) {
             return Double.NaN; //not enough data
         }
-        if (Math.abs(sumXX) < 10 * Double.MIN_VALUE) {
+        if (FastMath.abs(sumXX) < 10 * Double.MIN_VALUE) {
             return Double.NaN; //not enough variation in x
         }
         return sumXY / sumXX;
@@ -335,7 +336,7 @@ public class SimpleRegression implements
      * @return sum of squared errors associated with the regression model
      */
     public double getSumSquaredErrors() {
-        return Math.max(0d, sumYY - sumXY * sumXY / sumXX);
+        return FastMath.max(0d, sumYY - sumXY * sumXY / sumXX);
     }
 
     /**
@@ -431,7 +432,7 @@ public class SimpleRegression implements
      */
     public double getR() {
         double b1 = getSlope();
-        double result = Math.sqrt(getRSquare());
+        double result = FastMath.sqrt(getRSquare());
         if (b1 < 0) {
             result = -result;
         }
@@ -469,7 +470,7 @@ public class SimpleRegression implements
      * @return standard error associated with intercept estimate
      */
     public double getInterceptStdErr() {
-        return Math.sqrt(
+        return FastMath.sqrt(
             getMeanSquareError() * ((1d / (double) n) + (xbar * xbar) / sumXX));
     }
 
@@ -485,7 +486,7 @@ public class SimpleRegression implements
      * @return standard error associated with slope estimate
      */
     public double getSlopeStdErr() {
-        return Math.sqrt(getMeanSquareError() / sumXX);
+        return FastMath.sqrt(getMeanSquareError() / sumXX);
     }
 
     /**
@@ -579,7 +580,7 @@ public class SimpleRegression implements
      */
     public double getSignificance() throws MathException {
         return 2d * (1.0 - distribution.cumulativeProbability(
-                    Math.abs(getSlope()) / getSlopeStdErr()));
+                    FastMath.abs(getSlope()) / getSlopeStdErr()));
     }
 
     // ---------------------Private methods-----------------------------------

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java Sun Aug 29 22:04:09 2010
@@ -21,6 +21,7 @@ import org.apache.commons.math.MathRunti
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 import org.apache.commons.math.complex.Complex;
 import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.util.FastMath;
 
 /**
  * Implements the <a href="http://documents.wolfram.com/v5/Add-onsLinks/
@@ -99,7 +100,7 @@ public class FastCosineTransformer imple
      */
     public double[] transform2(double f[]) throws IllegalArgumentException {
 
-        double scaling_coefficient = Math.sqrt(2.0 / (f.length-1));
+        double scaling_coefficient = FastMath.sqrt(2.0 / (f.length-1));
         return FastFourierTransformer.scaleArray(fct(f), scaling_coefficient);
     }
 
@@ -125,7 +126,7 @@ public class FastCosineTransformer imple
         throws FunctionEvaluationException, IllegalArgumentException {
 
         double data[] = FastFourierTransformer.sample(f, min, max, n);
-        double scaling_coefficient = Math.sqrt(2.0 / (n-1));
+        double scaling_coefficient = FastMath.sqrt(2.0 / (n-1));
         return FastFourierTransformer.scaleArray(fct(data), scaling_coefficient);
     }
 
@@ -240,8 +241,8 @@ public class FastCosineTransformer imple
         double t1 = 0.5 * (f[0] - f[n]);   // temporary variable for transformed[1]
         for (int i = 1; i < (n >> 1); i++) {
             final double a = 0.5 * (f[i] + f[n-i]);
-            final double b = Math.sin(i * Math.PI / n) * (f[i] - f[n-i]);
-            final double c = Math.cos(i * Math.PI / n) * (f[i] - f[n-i]);
+            final double b = FastMath.sin(i * FastMath.PI / n) * (f[i] - f[n-i]);
+            final double c = FastMath.cos(i * FastMath.PI / n) * (f[i] - f[n-i]);
             x[i] = a - b;
             x[n-i] = a + b;
             t1 += c;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java Sun Aug 29 22:04:09 2010
@@ -24,6 +24,7 @@ import org.apache.commons.math.MathRunti
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 import org.apache.commons.math.complex.Complex;
 import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.util.FastMath;
 
 /**
  * Implements the <a href="http://mathworld.wolfram.com/FastFourierTransform.html">
@@ -125,7 +126,7 @@ public class FastFourierTransformer impl
     public Complex[] transform2(double f[])
         throws IllegalArgumentException {
 
-        double scaling_coefficient = 1.0 / Math.sqrt(f.length);
+        double scaling_coefficient = 1.0 / FastMath.sqrt(f.length);
         return scaleArray(fft(f, false), scaling_coefficient);
     }
 
@@ -149,7 +150,7 @@ public class FastFourierTransformer impl
         throws FunctionEvaluationException, IllegalArgumentException {
 
         double data[] = sample(f, min, max, n);
-        double scaling_coefficient = 1.0 / Math.sqrt(n);
+        double scaling_coefficient = 1.0 / FastMath.sqrt(n);
         return scaleArray(fft(data, false), scaling_coefficient);
     }
 
@@ -167,7 +168,7 @@ public class FastFourierTransformer impl
         throws IllegalArgumentException {
 
         roots.computeOmega(f.length);
-        double scaling_coefficient = 1.0 / Math.sqrt(f.length);
+        double scaling_coefficient = 1.0 / FastMath.sqrt(f.length);
         return scaleArray(fft(f), scaling_coefficient);
     }
 
@@ -243,7 +244,7 @@ public class FastFourierTransformer impl
     public Complex[] inversetransform2(double f[])
         throws IllegalArgumentException {
 
-        double scaling_coefficient = 1.0 / Math.sqrt(f.length);
+        double scaling_coefficient = 1.0 / FastMath.sqrt(f.length);
         return scaleArray(fft(f, true), scaling_coefficient);
     }
 
@@ -267,7 +268,7 @@ public class FastFourierTransformer impl
         throws FunctionEvaluationException, IllegalArgumentException {
 
         double data[] = sample(f, min, max, n);
-        double scaling_coefficient = 1.0 / Math.sqrt(n);
+        double scaling_coefficient = 1.0 / FastMath.sqrt(n);
         return scaleArray(fft(data, true), scaling_coefficient);
     }
 
@@ -285,7 +286,7 @@ public class FastFourierTransformer impl
         throws IllegalArgumentException {
 
         roots.computeOmega(-f.length);    // pass negative argument
-        double scaling_coefficient = 1.0 / Math.sqrt(f.length);
+        double scaling_coefficient = 1.0 / FastMath.sqrt(f.length);
         return scaleArray(fft(f), scaling_coefficient);
     }
 
@@ -837,16 +838,16 @@ public class FastFourierTransformer impl
         isForward = n > 0;
 
         // avoid repetitive calculations
-        final int absN = Math.abs(n);
+        final int absN = FastMath.abs(n);
 
         if (absN == omegaCount) {
             return;
         }
 
         // calculate everything from scratch, for both forward and inverse versions
-        final double t    = 2.0 * Math.PI / absN;
-        final double cosT = Math.cos(t);
-        final double sinT = Math.sin(t);
+        final double t    = 2.0 * FastMath.PI / absN;
+        final double cosT = FastMath.cos(t);
+        final double sinT = FastMath.sin(t);
         omegaReal             = new double[absN];
         omegaImaginaryForward = new double[absN];
         omegaImaginaryInverse = new double[absN];

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java Sun Aug 29 22:04:09 2010
@@ -21,6 +21,7 @@ import org.apache.commons.math.MathRunti
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 import org.apache.commons.math.complex.Complex;
 import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.util.FastMath;
 
 /**
  * Implements the <a href="http://documents.wolfram.com/v5/Add-onsLinks/
@@ -99,7 +100,7 @@ public class FastSineTransformer impleme
      */
     public double[] transform2(double f[]) throws IllegalArgumentException {
 
-        double scaling_coefficient = Math.sqrt(2.0 / f.length);
+        double scaling_coefficient = FastMath.sqrt(2.0 / f.length);
         return FastFourierTransformer.scaleArray(fst(f), scaling_coefficient);
     }
 
@@ -124,7 +125,7 @@ public class FastSineTransformer impleme
 
         double data[] = FastFourierTransformer.sample(f, min, max, n);
         data[0] = 0.0;
-        double scaling_coefficient = Math.sqrt(2.0 / n);
+        double scaling_coefficient = FastMath.sqrt(2.0 / n);
         return FastFourierTransformer.scaleArray(fst(data), scaling_coefficient);
     }
 
@@ -232,7 +233,7 @@ public class FastSineTransformer impleme
         x[0] = 0.0;
         x[n >> 1] = 2.0 * f[n >> 1];
         for (int i = 1; i < (n >> 1); i++) {
-            final double a = Math.sin(i * Math.PI / n) * (f[i] + f[n-i]);
+            final double a = FastMath.sin(i * FastMath.PI / n) * (f[i] + f[n-i]);
             final double b = 0.5 * (f[i] - f[n-i]);
             x[i]     = a + b;
             x[n - i] = a - b;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/ContinuedFraction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/ContinuedFraction.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/ContinuedFraction.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/ContinuedFraction.java Sun Aug 29 22:04:09 2010
@@ -149,7 +149,7 @@ public abstract class ContinuedFraction 
                 double scaleFactor = 1d;
                 double lastScaleFactor = 1d;
                 final int maxPower = 5;
-                final double scale = Math.max(a,b);
+                final double scale = FastMath.max(a,b);
                 if (scale <= 0) {  // Can't scale
                     throw new ConvergenceException(
                             LocalizedFormats.CONTINUED_FRACTION_INFINITY_DIVERGENCE,
@@ -187,7 +187,7 @@ public abstract class ContinuedFraction 
                   LocalizedFormats.CONTINUED_FRACTION_NAN_DIVERGENCE,
                   x);
             }
-            relativeError = Math.abs(r / c - 1.0);
+            relativeError = FastMath.abs(r / c - 1.0);
 
             // prepare for next iteration
             c = p2 / q2;