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/29 23:49:53 UTC
svn commit: r990655 [5/10] - in /commons/proper/math/branches/MATH_2_X: ./
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/mai...
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java Sun Aug 29 21:49:40 2010
@@ -26,6 +26,7 @@ import org.apache.commons.math.exception
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.linear.BlockRealMatrix;
import org.apache.commons.math.stat.regression.SimpleRegression;
+import org.apache.commons.math.util.FastMath;
/**
* Computes Pearson's product-moment correlation coefficients for pairs of arrays
@@ -141,7 +142,7 @@ public class PearsonsCorrelation {
for (int i = 0; i < nVars; i++) {
for (int j = 0; j < nVars; j++) {
double r = correlationMatrix.getEntry(i, j);
- out[i][j] = Math.sqrt((1 - r * r) /(nObs - 2));
+ out[i][j] = FastMath.sqrt((1 - r * r) /(nObs - 2));
}
}
return new BlockRealMatrix(out);
@@ -170,7 +171,7 @@ public class PearsonsCorrelation {
out[i][j] = 0d;
} else {
double r = correlationMatrix.getEntry(i, j);
- double t = Math.abs(r * Math.sqrt((nObs - 2)/(1 - r * r)));
+ double t = FastMath.abs(r * FastMath.sqrt((nObs - 2)/(1 - r * r)));
out[i][j] = 2 * tDistribution.cumulativeProbability(-t);
}
}
@@ -254,11 +255,11 @@ public class PearsonsCorrelation {
int nVars = covarianceMatrix.getColumnDimension();
RealMatrix outMatrix = new BlockRealMatrix(nVars, nVars);
for (int i = 0; i < nVars; i++) {
- double sigma = Math.sqrt(covarianceMatrix.getEntry(i, i));
+ double sigma = FastMath.sqrt(covarianceMatrix.getEntry(i, i));
outMatrix.setEntry(i, i, 1d);
for (int j = 0; j < i; j++) {
double entry = covarianceMatrix.getEntry(i, j) /
- (sigma * Math.sqrt(covarianceMatrix.getEntry(j, j)));
+ (sigma * FastMath.sqrt(covarianceMatrix.getEntry(j, j)));
outMatrix.setEntry(i, j, entry);
outMatrix.setEntry(j, i, entry);
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java Sun Aug 29 21:49:40 2010
@@ -33,6 +33,7 @@ import org.apache.commons.math.stat.desc
import org.apache.commons.math.stat.descriptive.summary.Sum;
import org.apache.commons.math.stat.descriptive.summary.SumOfSquares;
import org.apache.commons.math.util.ResizableDoubleArray;
+import org.apache.commons.math.util.FastMath;
/**
@@ -207,7 +208,7 @@ public class DescriptiveStatistics imple
double stdDev = Double.NaN;
if (getN() > 0) {
if (getN() > 1) {
- stdDev = Math.sqrt(getVariance());
+ stdDev = FastMath.sqrt(getVariance());
} else {
stdDev = 0.0;
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java Sun Aug 29 21:49:40 2010
@@ -32,6 +32,7 @@ import org.apache.commons.math.stat.desc
import org.apache.commons.math.stat.descriptive.summary.SumOfLogs;
import org.apache.commons.math.stat.descriptive.summary.SumOfSquares;
import org.apache.commons.math.util.MathUtils;
+import org.apache.commons.math.util.FastMath;
/**
* <p>Computes summary statistics for a stream of n-tuples added using the
@@ -248,7 +249,7 @@ public class MultivariateSummaryStatisti
} else {
RealMatrix matrix = covarianceImpl.getResult();
for (int i = 0; i < k; ++i) {
- stdDev[i] = Math.sqrt(matrix.getEntry(i, i));
+ stdDev[i] = FastMath.sqrt(matrix.getEntry(i, i));
}
}
return stdDev;
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java Sun Aug 29 21:49:40 2010
@@ -17,6 +17,8 @@
package org.apache.commons.math.stat.descriptive;
import java.io.Serializable;
+
+import org.apache.commons.math.util.FastMath;
import org.apache.commons.math.util.MathUtils;
/**
@@ -108,7 +110,7 @@ public class StatisticalSummaryValues im
* @return Returns the standard deviation
*/
public double getStandardDeviation() {
- return Math.sqrt(variance);
+ return FastMath.sqrt(variance);
}
/**
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java Sun Aug 29 21:49:40 2010
@@ -30,6 +30,7 @@ import org.apache.commons.math.stat.desc
import org.apache.commons.math.stat.descriptive.summary.SumOfLogs;
import org.apache.commons.math.stat.descriptive.summary.SumOfSquares;
import org.apache.commons.math.util.MathUtils;
+import org.apache.commons.math.util.FastMath;
/**
* <p>
@@ -217,7 +218,7 @@ public class SummaryStatistics implement
double stdDev = Double.NaN;
if (getN() > 0) {
if (getN() > 1) {
- stdDev = Math.sqrt(getVariance());
+ stdDev = FastMath.sqrt(getVariance());
} else {
stdDev = 0.0;
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java Sun Aug 29 21:49:40 2010
@@ -23,6 +23,7 @@ import org.apache.commons.math.exception
import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic;
import org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic;
import org.apache.commons.math.stat.descriptive.summary.SumOfLogs;
+import org.apache.commons.math.util.FastMath;
/**
* Returns the <a href="http://www.xycoon.com/geometric_mean.htm">
@@ -106,7 +107,7 @@ public class GeometricMean extends Abstr
@Override
public double getResult() {
if (sumOfLogs.getN() > 0) {
- return Math.exp(sumOfLogs.getResult() / sumOfLogs.getN());
+ return FastMath.exp(sumOfLogs.getResult() / sumOfLogs.getN());
} else {
return Double.NaN;
}
@@ -139,7 +140,7 @@ public class GeometricMean extends Abstr
@Override
public double evaluate(
final double[] values, final int begin, final int length) {
- return Math.exp(
+ return FastMath.exp(
sumOfLogs.evaluate(values, begin, length) / length);
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java Sun Aug 29 21:49:40 2010
@@ -21,6 +21,7 @@ import java.io.Serializable;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic;
+import org.apache.commons.math.util.FastMath;
/**
@@ -170,15 +171,15 @@ public class Kurtosis extends AbstractSt
Variance variance = new Variance();
variance.incrementAll(values, begin, length);
double mean = variance.moment.m1;
- double stdDev = Math.sqrt(variance.getResult());
+ double stdDev = FastMath.sqrt(variance.getResult());
// Sum the ^4 of the distance from the mean divided by the
// standard deviation
double accum3 = 0.0;
for (int i = begin; i < begin + length; i++) {
- accum3 += Math.pow(values[i] - mean, 4.0);
+ accum3 += FastMath.pow(values[i] - mean, 4.0);
}
- accum3 /= Math.pow(stdDev, 4.0d);
+ accum3 /= FastMath.pow(stdDev, 4.0d);
// Get N
double n0 = length;
@@ -186,7 +187,7 @@ public class Kurtosis extends AbstractSt
double coefficientOne =
(n0 * (n0 + 1)) / ((n0 - 1) * (n0 - 2) * (n0 - 3));
double termTwo =
- (3 * Math.pow(n0 - 1, 2.0)) / ((n0 - 2) * (n0 - 3));
+ (3 * FastMath.pow(n0 - 1, 2.0)) / ((n0 - 2) * (n0 - 3));
// Calculate kurtosis
kurt = (coefficientOne * accum3) - termTwo;
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/moment/Skewness.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/moment/Skewness.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/moment/Skewness.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/moment/Skewness.java Sun Aug 29 21:49:40 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;
/**
* Computes the skewness of the available values.
@@ -109,7 +110,7 @@ public class Skewness extends AbstractSt
} else {
double n0 = moment.getN();
return (n0 * moment.m3) /
- ((n0 - 1) * (n0 -2) * Math.sqrt(variance) * variance);
+ ((n0 - 1) * (n0 -2) * FastMath.sqrt(variance) * variance);
}
}
@@ -175,7 +176,7 @@ public class Skewness extends AbstractSt
final double d = values[i] - m;
accum3 += d * d * d;
}
- accum3 /= variance * Math.sqrt(variance);
+ accum3 /= variance * FastMath.sqrt(variance);
// Get N
double n0 = length;
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.java Sun Aug 29 21:49:40 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;
/**
* Computes the sample standard deviation. The standard deviation
@@ -122,7 +123,7 @@ public class StandardDeviation extends A
*/
@Override
public double getResult() {
- return Math.sqrt(variance.getResult());
+ return FastMath.sqrt(variance.getResult());
}
/**
@@ -149,7 +150,7 @@ public class StandardDeviation extends A
*/
@Override
public double evaluate(final double[] values) {
- return Math.sqrt(variance.evaluate(values));
+ return FastMath.sqrt(variance.evaluate(values));
}
/**
@@ -172,7 +173,7 @@ public class StandardDeviation extends A
*/
@Override
public double evaluate(final double[] values, final int begin, final int length) {
- return Math.sqrt(variance.evaluate(values, begin, length));
+ return FastMath.sqrt(variance.evaluate(values, begin, length));
}
/**
@@ -201,7 +202,7 @@ public class StandardDeviation extends A
*/
public double evaluate(final double[] values, final double mean,
final int begin, final int length) {
- return Math.sqrt(variance.evaluate(values, mean, begin, length));
+ return FastMath.sqrt(variance.evaluate(values, mean, begin, length));
}
/**
@@ -226,7 +227,7 @@ public class StandardDeviation extends A
* @throws IllegalArgumentException if the array is null
*/
public double evaluate(final double[] values, final double mean) {
- return Math.sqrt(variance.evaluate(values, mean));
+ return FastMath.sqrt(variance.evaluate(values, mean));
}
/**
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java Sun Aug 29 21:49:40 2010
@@ -22,6 +22,7 @@ import java.util.Arrays;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.stat.descriptive.AbstractUnivariateStatistic;
+import org.apache.commons.math.util.FastMath;
/**
* Provides percentile computation.
@@ -210,7 +211,7 @@ public class Percentile extends Abstract
}
double n = length;
double pos = p * (n + 1) / 100;
- double fpos = Math.floor(pos);
+ double fpos = FastMath.floor(pos);
int intPos = (int) fpos;
double dif = pos - fpos;
double[] sorted = new double[length];
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/summary/Product.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/summary/Product.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/summary/Product.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/summary/Product.java Sun Aug 29 21:49:40 2010
@@ -20,6 +20,7 @@ import java.io.Serializable;
import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic;
import org.apache.commons.math.stat.descriptive.WeightedEvaluation;
+import org.apache.commons.math.util.FastMath;
/**
* Returns the product of the available values.
@@ -162,7 +163,7 @@ public class Product extends AbstractSto
if (test(values, weights, begin, length)) {
product = 1.0;
for (int i = begin; i < begin + length; i++) {
- product *= Math.pow(values[i], weights[i]);
+ product *= FastMath.pow(values[i], weights[i]);
}
}
return product;
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/summary/SumOfLogs.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/summary/SumOfLogs.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/summary/SumOfLogs.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/summary/SumOfLogs.java Sun Aug 29 21:49:40 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/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java Sun Aug 29 21:49:40 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/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/inference/TTestImpl.java Sun Aug 29 21:49:40 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/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/ranking/NaturalRanking.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/ranking/NaturalRanking.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/ranking/NaturalRanking.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/ranking/NaturalRanking.java Sun Aug 29 21:49:40 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/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java Sun Aug 29 21:49:40 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/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/regression/SimpleRegression.java Sun Aug 29 21:49:40 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/branches/MATH_2_X/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/transform/FastCosineTransformer.java Sun Aug 29 21:49:40 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/branches/MATH_2_X/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java Sun Aug 29 21:49:40 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/branches/MATH_2_X/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/transform/FastSineTransformer.java Sun Aug 29 21:49:40 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/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/ContinuedFraction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/ContinuedFraction.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/ContinuedFraction.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/ContinuedFraction.java Sun Aug 29 21:49:40 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;