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 [4/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/ode/nonstiff/GillIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GillIntegrator.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GillIntegrator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GillIntegrator.java Sun Aug 29 22:04:09 2010
@@ -17,6 +17,8 @@
package org.apache.commons.math.ode.nonstiff;
+import org.apache.commons.math.util.FastMath;
+
/**
* This class implements the Gill fourth order Runge-Kutta
@@ -52,13 +54,13 @@ public class GillIntegrator extends Rung
/** Internal weights Butcher array. */
private static final double[][] STATIC_A = {
{ 1.0 / 2.0 },
- { (Math.sqrt(2.0) - 1.0) / 2.0, (2.0 - Math.sqrt(2.0)) / 2.0 },
- { 0.0, -Math.sqrt(2.0) / 2.0, (2.0 + Math.sqrt(2.0)) / 2.0 }
+ { (FastMath.sqrt(2.0) - 1.0) / 2.0, (2.0 - FastMath.sqrt(2.0)) / 2.0 },
+ { 0.0, -FastMath.sqrt(2.0) / 2.0, (2.0 + FastMath.sqrt(2.0)) / 2.0 }
};
/** Propagation weights Butcher array. */
private static final double[] STATIC_B = {
- 1.0 / 6.0, (2.0 - Math.sqrt(2.0)) / 6.0, (2.0 + Math.sqrt(2.0)) / 6.0, 1.0 / 6.0
+ 1.0 / 6.0, (2.0 - FastMath.sqrt(2.0)) / 6.0, (2.0 + FastMath.sqrt(2.0)) / 6.0, 1.0 / 6.0
};
/** Simple constructor.
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GillStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GillStepInterpolator.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GillStepInterpolator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GillStepInterpolator.java Sun Aug 29 22:04:09 2010
@@ -19,6 +19,7 @@ package org.apache.commons.math.ode.nons
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.sampling.StepInterpolator;
+import org.apache.commons.math.util.FastMath;
/**
* This class implements a step interpolator for the Gill fourth
@@ -48,10 +49,10 @@ class GillStepInterpolator
extends RungeKuttaStepInterpolator {
/** First Gill coefficient. */
- private static final double TWO_MINUS_SQRT_2 = 2 - Math.sqrt(2.0);
+ private static final double TWO_MINUS_SQRT_2 = 2 - FastMath.sqrt(2.0);
/** Second Gill coefficient. */
- private static final double TWO_PLUS_SQRT_2 = 2 + Math.sqrt(2.0);
+ private static final double TWO_PLUS_SQRT_2 = 2 + FastMath.sqrt(2.0);
/** Serializable version identifier */
private static final long serialVersionUID = -107804074496313322L;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java Sun Aug 29 22:04:09 2010
@@ -24,6 +24,7 @@ import org.apache.commons.math.ode.event
import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
import org.apache.commons.math.ode.sampling.DummyStepInterpolator;
import org.apache.commons.math.ode.sampling.StepHandler;
+import org.apache.commons.math.util.FastMath;
/**
* This class implements a Gragg-Bulirsch-Stoer integrator for
@@ -434,12 +435,12 @@ public class GraggBulirschStoerIntegrato
private void rescale(final double[] y1, final double[] y2, final double[] scale) {
if (vecAbsoluteTolerance == null) {
for (int i = 0; i < scale.length; ++i) {
- final double yi = Math.max(Math.abs(y1[i]), Math.abs(y2[i]));
+ final double yi = FastMath.max(FastMath.abs(y1[i]), FastMath.abs(y2[i]));
scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * yi;
}
} else {
for (int i = 0; i < scale.length; ++i) {
- final double yi = Math.max(Math.abs(y1[i]), Math.abs(y2[i]));
+ final double yi = FastMath.max(FastMath.abs(y1[i]), FastMath.abs(y2[i]));
scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * yi;
}
}
@@ -509,7 +510,7 @@ public class GraggBulirschStoerIntegrato
final double ratio = (f[j+1][l] - f[0][l]) / scale[l];
deltaNorm += ratio * ratio;
}
- if (deltaNorm > 4 * Math.max(1.0e-15, initialNorm)) {
+ if (deltaNorm > 4 * FastMath.max(1.0e-15, initialNorm)) {
return false;
}
}
@@ -613,10 +614,10 @@ public class GraggBulirschStoerIntegrato
// initial order selection
final double tol =
(vecRelativeTolerance == null) ? scalRelativeTolerance : vecRelativeTolerance[0];
- final double log10R = Math.log(Math.max(1.0e-10, tol)) / Math.log(10.0);
- int targetIter = Math.max(1,
- Math.min(sequence.length - 2,
- (int) Math.floor(0.5 - 0.6 * log10R)));
+ final double log10R = FastMath.log(FastMath.max(1.0e-10, tol)) / FastMath.log(10.0);
+ int targetIter = FastMath.max(1,
+ FastMath.min(sequence.length - 2,
+ (int) FastMath.floor(0.5 - 0.6 * log10R)));
// set up an interpolator sharing the integrator arrays
AbstractStepInterpolator interpolator = null;
if (denseOutput || (! eventsHandlersManager.isEmpty())) {
@@ -693,7 +694,7 @@ public class GraggBulirschStoerIntegrato
yTmp)) {
// the stability check failed, we reduce the global step
- hNew = Math.abs(filterStep(stepSize * stabilityReduction, forward, false));
+ hNew = FastMath.abs(filterStep(stepSize * stabilityReduction, forward, false));
reject = true;
loop = false;
@@ -710,26 +711,26 @@ public class GraggBulirschStoerIntegrato
// estimate the error at the end of the step.
error = 0;
for (int j = 0; j < mainSetDimension; ++j) {
- final double e = Math.abs(y1[j] - y1Diag[0][j]) / scale[j];
+ final double e = FastMath.abs(y1[j] - y1Diag[0][j]) / scale[j];
error += e * e;
}
- error = Math.sqrt(error / mainSetDimension);
+ error = FastMath.sqrt(error / mainSetDimension);
if ((error > 1.0e15) || ((k > 1) && (error > maxError))) {
// error is too big, we reduce the global step
- hNew = Math.abs(filterStep(stepSize * stabilityReduction, forward, false));
+ hNew = FastMath.abs(filterStep(stepSize * stabilityReduction, forward, false));
reject = true;
loop = false;
} else {
- maxError = Math.max(4 * error, 1.0);
+ maxError = FastMath.max(4 * error, 1.0);
// compute optimal stepsize for this order
final double exp = 1.0 / (2 * k + 1);
- double fac = stepControl2 / Math.pow(error / stepControl1, exp);
- final double pow = Math.pow(stepControl3, exp);
- fac = Math.max(pow / stepControl4, Math.min(1 / pow, fac));
- optimalStep[k] = Math.abs(filterStep(stepSize * fac, forward, true));
+ double fac = stepControl2 / FastMath.pow(error / stepControl1, exp);
+ final double pow = FastMath.pow(stepControl3, exp);
+ fac = FastMath.max(pow / stepControl4, FastMath.min(1 / pow, fac));
+ optimalStep[k] = FastMath.abs(filterStep(stepSize * fac, forward, true));
costPerTimeUnit[k] = costPerStep[k] / optimalStep[k];
// check convergence
@@ -833,13 +834,13 @@ public class GraggBulirschStoerIntegrato
// derivative at middle point of the step
final int l2 = l / 2;
- double factor = Math.pow(0.5 * sequence[l2], l);
+ double factor = FastMath.pow(0.5 * sequence[l2], l);
int middleIndex = fk[l2].length / 2;
for (int i = 0; i < y0.length; ++i) {
yMidDots[l+1][i] = factor * fk[l2][middleIndex + l][i];
}
for (int j = 1; j <= k - l2; ++j) {
- factor = Math.pow(0.5 * sequence[j + l2], l);
+ factor = FastMath.pow(0.5 * sequence[j + l2], l);
middleIndex = fk[l2+j].length / 2;
for (int i = 0; i < y0.length; ++i) {
diagonal[j-1][i] = factor * fk[l2+j][middleIndex+l][i];
@@ -871,7 +872,7 @@ public class GraggBulirschStoerIntegrato
if (useInterpolationError) {
// use the interpolation error to limit stepsize
final double interpError = gbsInterpolator.estimateError(scale);
- hInt = Math.abs(stepSize / Math.max(Math.pow(interpError, 1.0 / (mu+4)),
+ hInt = FastMath.abs(stepSize / FastMath.max(FastMath.pow(interpError, 1.0 / (mu+4)),
0.01));
if (interpError > 10.0) {
hNew = hInt;
@@ -884,9 +885,9 @@ public class GraggBulirschStoerIntegrato
interpolator.storeTime(stepStart + stepSize);
if (eventsHandlersManager.evaluateStep(interpolator)) {
final double dt = eventsHandlersManager.getEventTime() - stepStart;
- if (Math.abs(dt) > Math.ulp(stepStart)) {
+ if (FastMath.abs(dt) > FastMath.ulp(stepStart)) {
// reject the step to match exactly the next switch time
- hNew = Math.abs(dt);
+ hNew = FastMath.abs(dt);
reject = true;
}
}
@@ -937,7 +938,7 @@ public class GraggBulirschStoerIntegrato
if (costPerTimeUnit[k-1] < orderControl1 * costPerTimeUnit[k]) {
optimalIter = k-1;
} else if (costPerTimeUnit[k] < orderControl2 * costPerTimeUnit[k-1]) {
- optimalIter = Math.min(k+1, sequence.length - 2);
+ optimalIter = FastMath.min(k+1, sequence.length - 2);
}
} else {
optimalIter = k - 1;
@@ -946,15 +947,15 @@ public class GraggBulirschStoerIntegrato
optimalIter = k - 2;
}
if (costPerTimeUnit[k] < orderControl2 * costPerTimeUnit[optimalIter]) {
- optimalIter = Math.min(k, sequence.length - 2);
+ optimalIter = FastMath.min(k, sequence.length - 2);
}
}
if (previousRejected) {
// after a rejected step neither order nor stepsize
// should increase
- targetIter = Math.min(optimalIter, k);
- hNew = Math.min(Math.abs(stepSize), optimalStep[targetIter]);
+ targetIter = FastMath.min(optimalIter, k);
+ hNew = FastMath.min(FastMath.abs(stepSize), optimalStep[targetIter]);
} else {
// stepsize control
if (optimalIter <= k) {
@@ -978,7 +979,7 @@ public class GraggBulirschStoerIntegrato
}
- hNew = Math.min(hNew, hInt);
+ hNew = FastMath.min(hNew, hInt);
if (! forward) {
hNew = -hNew;
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java Sun Aug 29 22:04:09 2010
@@ -24,6 +24,7 @@ import java.io.ObjectOutput;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
import org.apache.commons.math.ode.sampling.StepInterpolator;
+import org.apache.commons.math.util.FastMath;
/**
* This class implements an interpolator for the Gragg-Bulirsch-Stoer
@@ -211,7 +212,7 @@ class GraggBulirschStoerStepInterpolator
for (int i = 0; i < errfac.length; ++i) {
final int ip5 = i + 5;
errfac[i] = 1.0 / (ip5 * ip5);
- final double e = 0.5 * Math.sqrt (((double) (i + 1)) / ip5);
+ final double e = 0.5 * FastMath.sqrt (((double) (i + 1)) / ip5);
for (int j = 0; j <= i; ++j) {
errfac[i] *= e / (j + 1);
}
@@ -301,7 +302,7 @@ class GraggBulirschStoerStepInterpolator
final double e = polynoms[currentDegree][i] / scale[i];
error += e * e;
}
- error = Math.sqrt(error / scale.length) * errfac[currentDegree - 5];
+ error = FastMath.sqrt(error / scale.length) * errfac[currentDegree - 5];
}
return error;
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/HighamHall54Integrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/HighamHall54Integrator.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/HighamHall54Integrator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/HighamHall54Integrator.java Sun Aug 29 22:04:09 2010
@@ -17,6 +17,8 @@
package org.apache.commons.math.ode.nonstiff;
+import org.apache.commons.math.util.FastMath;
+
/**
* This class implements the 5(4) Higham and Hall integrator for
@@ -114,7 +116,7 @@ public class HighamHall54Integrator exte
errSum += STATIC_E[l] * yDotK[l][j];
}
- final double yScale = Math.max(Math.abs(y0[j]), Math.abs(y1[j]));
+ final double yScale = FastMath.max(FastMath.abs(y0[j]), FastMath.abs(y1[j]));
final double tol = (vecAbsoluteTolerance == null) ?
(scalAbsoluteTolerance + scalRelativeTolerance * yScale) :
(vecAbsoluteTolerance[j] + vecRelativeTolerance[j] * yScale);
@@ -123,7 +125,7 @@ public class HighamHall54Integrator exte
}
- return Math.sqrt(error / mainSetDimension);
+ return FastMath.sqrt(error / mainSetDimension);
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java Sun Aug 29 22:04:09 2010
@@ -26,6 +26,7 @@ import org.apache.commons.math.ode.event
import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
import org.apache.commons.math.ode.sampling.DummyStepInterpolator;
import org.apache.commons.math.ode.sampling.StepHandler;
+import org.apache.commons.math.util.FastMath;
/**
* This class implements the common part of all fixed step Runge-Kutta
@@ -88,7 +89,7 @@ public abstract class RungeKuttaIntegrat
this.a = a;
this.b = b;
this.prototype = prototype;
- this.step = Math.abs(step);
+ this.step = FastMath.abs(step);
}
/** {@inheritDoc} */
@@ -171,7 +172,7 @@ public abstract class RungeKuttaIntegrat
interpolator.storeTime(stepStart + stepSize);
if (manager.evaluateStep(interpolator)) {
final double dt = manager.getEventTime() - stepStart;
- if (Math.abs(dt) <= Math.ulp(stepStart)) {
+ if (FastMath.abs(dt) <= FastMath.ulp(stepStart)) {
// we cannot simply truncate the step, reject the current computation
// and let the loop compute another state with the truncated step.
// it is so small (much probably exactly 0 due to limited accuracy)
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/NordsieckStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/NordsieckStepInterpolator.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/NordsieckStepInterpolator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/NordsieckStepInterpolator.java Sun Aug 29 22:04:09 2010
@@ -24,6 +24,7 @@ import java.util.Arrays;
import org.apache.commons.math.linear.Array2DRowRealMatrix;
import org.apache.commons.math.ode.DerivativeException;
+import org.apache.commons.math.util.FastMath;
/**
* This class implements an interpolator for integrators using Nordsieck representation.
@@ -197,7 +198,7 @@ public class NordsieckStepInterpolator e
for (int i = nData.length - 1; i >= 0; --i) {
final int order = i + 2;
final double[] nDataI = nData[i];
- final double power = Math.pow(normalizedAbscissa, order);
+ final double power = FastMath.pow(normalizedAbscissa, order);
for (int j = 0; j < nDataI.length; ++j) {
final double d = nDataI[j] * power;
stateVariation[j] += d;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/StepNormalizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/StepNormalizer.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/StepNormalizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/StepNormalizer.java Sun Aug 29 22:04:09 2010
@@ -18,6 +18,7 @@
package org.apache.commons.math.ode.sampling;
import org.apache.commons.math.ode.DerivativeException;
+import org.apache.commons.math.util.FastMath;
/**
* This class wraps an object implementing {@link FixedStepHandler}
@@ -72,7 +73,7 @@ public class StepNormalizer implements S
* @param handler fixed time step handler to wrap
*/
public StepNormalizer(final double h, final FixedStepHandler handler) {
- this.h = Math.abs(h);
+ this.h = FastMath.abs(h);
this.handler = handler;
reset();
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultivariateRealOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultivariateRealOptimizer.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultivariateRealOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultivariateRealOptimizer.java Sun Aug 29 22:04:09 2010
@@ -24,7 +24,7 @@ import org.apache.commons.math.analysis.
* Optimization algorithms find the input point set that either {@link GoalType
* maximize or minimize} an objective function.
* This interface is mainly intended to enforce the internal coherence of
- * Commons-Math. Users of the API are advised to base their code on
+ * Commons-FastMath. Users of the API are advised to base their code on
* {@link MultivariateRealOptimizer} or on
* {@link DifferentiableMultivariateRealOptimizer}.
* @param <T> the type of the objective function to be optimized
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java Sun Aug 29 22:04:09 2010
@@ -23,6 +23,7 @@ import org.apache.commons.math.MathRunti
import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.random.RandomGenerator;
+import org.apache.commons.math.util.FastMath;
/**
* Special implementation of the {@link UnivariateRealOptimizer} interface adding
@@ -242,8 +243,8 @@ public class MultiStartUnivariateRealOpt
final double bound1 = (i == 0) ? min : min + generator.nextDouble() * (max - min);
final double bound2 = (i == 0) ? max : min + generator.nextDouble() * (max - min);
optima[i] = optimizer.optimize(f, goalType,
- Math.min(bound1, bound2),
- Math.max(bound1, bound2));
+ FastMath.min(bound1, bound2),
+ FastMath.max(bound1, bound2));
optimaValues[i] = optimizer.getFunctionValue();
} catch (FunctionEvaluationException fee) {
optima[i] = Double.NaN;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/SimpleRealPointChecker.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/SimpleRealPointChecker.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/SimpleRealPointChecker.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/SimpleRealPointChecker.java Sun Aug 29 22:04:09 2010
@@ -17,6 +17,7 @@
package org.apache.commons.math.optimization;
+import org.apache.commons.math.util.FastMath;
import org.apache.commons.math.util.MathUtils;
/**
@@ -74,8 +75,8 @@ public class SimpleRealPointChecker impl
final double[] p = previous.getPoint();
final double[] c = current.getPoint();
for (int i = 0; i < p.length; ++i) {
- final double difference = Math.abs(p[i] - c[i]);
- final double size = Math.max(Math.abs(p[i]), Math.abs(c[i]));
+ final double difference = FastMath.abs(p[i] - c[i]);
+ final double size = FastMath.max(FastMath.abs(p[i]), FastMath.abs(c[i]));
if ((difference > (size * relativeThreshold)) && (difference > absoluteThreshold)) {
return false;
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/SimpleScalarValueChecker.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/SimpleScalarValueChecker.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/SimpleScalarValueChecker.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/SimpleScalarValueChecker.java Sun Aug 29 22:04:09 2010
@@ -17,6 +17,7 @@
package org.apache.commons.math.optimization;
+import org.apache.commons.math.util.FastMath;
import org.apache.commons.math.util.MathUtils;
/**
@@ -73,8 +74,8 @@ public class SimpleScalarValueChecker im
final RealPointValuePair current) {
final double p = previous.getValue();
final double c = current.getValue();
- final double difference = Math.abs(p - c);
- final double size = Math.max(Math.abs(p), Math.abs(c));
+ final double difference = FastMath.abs(p - c);
+ final double size = FastMath.max(FastMath.abs(p), FastMath.abs(c));
return (difference <= (size * relativeThreshold)) || (difference <= absoluteThreshold);
}
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/SimpleVectorialPointChecker.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/SimpleVectorialPointChecker.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/SimpleVectorialPointChecker.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/SimpleVectorialPointChecker.java Sun Aug 29 22:04:09 2010
@@ -17,6 +17,7 @@
package org.apache.commons.math.optimization;
+import org.apache.commons.math.util.FastMath;
import org.apache.commons.math.util.MathUtils;
/**
@@ -76,8 +77,8 @@ public class SimpleVectorialPointChecker
for (int i = 0; i < p.length; ++i) {
final double pi = p[i];
final double ci = c[i];
- final double difference = Math.abs(pi - ci);
- final double size = Math.max(Math.abs(pi), Math.abs(ci));
+ final double difference = FastMath.abs(pi - ci);
+ final double size = FastMath.max(FastMath.abs(pi), FastMath.abs(ci));
if ((difference > (size * relativeThreshold)) &&
(difference > absoluteThreshold)) {
return false;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/SimpleVectorialValueChecker.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/SimpleVectorialValueChecker.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/SimpleVectorialValueChecker.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/SimpleVectorialValueChecker.java Sun Aug 29 22:04:09 2010
@@ -17,6 +17,7 @@
package org.apache.commons.math.optimization;
+import org.apache.commons.math.util.FastMath;
import org.apache.commons.math.util.MathUtils;
/**
@@ -76,8 +77,8 @@ public class SimpleVectorialValueChecker
for (int i = 0; i < p.length; ++i) {
final double pi = p[i];
final double ci = c[i];
- final double difference = Math.abs(pi - ci);
- final double size = Math.max(Math.abs(pi), Math.abs(ci));
+ final double difference = FastMath.abs(pi - ci);
+ final double size = FastMath.max(FastMath.abs(pi), FastMath.abs(ci));
if ((difference > (size * relativeThreshold)) &&
(difference > absoluteThreshold)) {
return false;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicCoefficientsGuesser.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicCoefficientsGuesser.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicCoefficientsGuesser.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicCoefficientsGuesser.java Sun Aug 29 22:04:09 2010
@@ -19,6 +19,7 @@ package org.apache.commons.math.optimiza
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.optimization.OptimizationException;
+import org.apache.commons.math.util.FastMath;
/** This class guesses harmonic coefficients from a sample.
@@ -241,8 +242,8 @@ public class HarmonicCoefficientsGuesser
if ((c1 / c2 < 0.0) || (c2 / c3 < 0.0)) {
throw new OptimizationException(LocalizedFormats.UNABLE_TO_FIRST_GUESS_HARMONIC_COEFFICIENTS);
}
- a = Math.sqrt(c1 / c2);
- omega = Math.sqrt(c2 / c3);
+ a = FastMath.sqrt(c1 / c2);
+ omega = FastMath.sqrt(c2 / c3);
}
@@ -266,14 +267,14 @@ public class HarmonicCoefficientsGuesser
final double currentYPrime = (currentY - previousY) / (currentX - previousX);
double omegaX = omega * currentX;
- double cosine = Math.cos(omegaX);
- double sine = Math.sin(omegaX);
+ double cosine = FastMath.cos(omegaX);
+ double sine = FastMath.sin(omegaX);
fcMean += omega * currentY * cosine - currentYPrime * sine;
fsMean += omega * currentY * sine + currentYPrime * cosine;
}
- phi = Math.atan2(-fsMean, fcMean);
+ phi = FastMath.atan2(-fsMean, fcMean);
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicFitter.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicFitter.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicFitter.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicFitter.java Sun Aug 29 22:04:09 2010
@@ -22,6 +22,7 @@ import org.apache.commons.math.MathRunti
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer;
import org.apache.commons.math.optimization.OptimizationException;
+import org.apache.commons.math.util.FastMath;
/** This class implements a curve fitting specialized for sinusoids.
* <p>Harmonic fitting is a very simple case of curve fitting. The
@@ -114,7 +115,7 @@ public class HarmonicFitter {
final double a = parameters[0];
final double omega = parameters[1];
final double phi = parameters[2];
- return a * Math.cos(omega * x + phi);
+ return a * FastMath.cos(omega * x + phi);
}
/** {@inheritDoc} */
@@ -123,8 +124,8 @@ public class HarmonicFitter {
final double omega = parameters[1];
final double phi = parameters[2];
final double alpha = omega * x + phi;
- final double cosAlpha = Math.cos(alpha);
- final double sinAlpha = Math.sin(alpha);
+ final double cosAlpha = FastMath.cos(alpha);
+ final double sinAlpha = FastMath.sin(alpha);
return new double[] { cosAlpha, -a * x * sinAlpha, -a * sinAlpha };
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicFunction.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicFunction.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicFunction.java Sun Aug 29 22:04:09 2010
@@ -18,6 +18,7 @@
package org.apache.commons.math.optimization.fitting;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
+import org.apache.commons.math.util.FastMath;
/** Harmonic function of the form <code>f (t) = a cos (ω t + φ)</code>.
* @version $Revision$ $Date$
@@ -47,12 +48,12 @@ public class HarmonicFunction implements
/** {@inheritDoc} */
public double value(double x) {
- return a * Math.cos(omega * x + phi);
+ return a * FastMath.cos(omega * x + phi);
}
/** {@inheritDoc} */
public HarmonicFunction derivative() {
- return new HarmonicFunction(a * omega, omega, phi + Math.PI / 2);
+ return new HarmonicFunction(a * omega, omega, phi + FastMath.PI / 2);
}
/** Get the amplitude a.
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java Sun Aug 29 22:04:09 2010
@@ -32,6 +32,7 @@ import org.apache.commons.math.optimizat
import org.apache.commons.math.optimization.VectorialConvergenceChecker;
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer;
import org.apache.commons.math.optimization.VectorialPointValuePair;
+import org.apache.commons.math.util.FastMath;
/**
* Base class for implementing least squares optimizers.
@@ -189,7 +190,7 @@ public abstract class AbstractLeastSquar
}
for (int i = 0; i < rows; i++) {
final double[] ji = weightedResidualJacobian[i];
- double wi = Math.sqrt(residualsWeights[i]);
+ double wi = FastMath.sqrt(residualsWeights[i]);
for (int j = 0; j < cols; ++j) {
//ji[j] *= -1.0;
weightedResidualJacobian[i][j] = -ji[j]*wi;
@@ -219,11 +220,11 @@ public abstract class AbstractLeastSquar
int index = 0;
for (int i = 0; i < rows; i++) {
final double residual = targetValues[i] - objective[i];
- weightedResiduals[i]= residual*Math.sqrt(residualsWeights[i]);
+ weightedResiduals[i]= residual*FastMath.sqrt(residualsWeights[i]);
cost += residualsWeights[i] * residual * residual;
index += cols;
}
- cost = Math.sqrt(cost);
+ cost = FastMath.sqrt(cost);
}
@@ -238,7 +239,7 @@ public abstract class AbstractLeastSquar
* @return RMS value
*/
public double getRMS() {
- return Math.sqrt(getChiSquare() / rows);
+ return FastMath.sqrt(getChiSquare() / rows);
}
/**
@@ -306,10 +307,10 @@ public abstract class AbstractLeastSquar
rows, cols);
}
double[] errors = new double[cols];
- final double c = Math.sqrt(getChiSquare() / (rows - cols));
+ final double c = FastMath.sqrt(getChiSquare() / (rows - cols));
double[][] covar = getCovariances();
for (int i = 0; i < errors.length; ++i) {
- errors[i] = Math.sqrt(covar[i][i]) * c;
+ errors[i] = FastMath.sqrt(covar[i][i]) * c;
}
return errors;
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/BaseAbstractScalarOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/BaseAbstractScalarOptimizer.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/BaseAbstractScalarOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/BaseAbstractScalarOptimizer.java Sun Aug 29 22:04:09 2010
@@ -33,7 +33,7 @@ import org.apache.commons.math.optimizat
* This base class handles the boiler-plate methods associated to thresholds
* settings, iterations and evaluations counting.
* This class is mainly intended to enforce the internal coherence of
- * Commons-Math.
+ * Commons-FastMath.
* A class that implements an optimization algorithm should inherit from
* {@link AbstractScalarOptimizer} or from
* {@link AbstractScalarDifferentiableOptimizer}.
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java Sun Aug 29 22:04:09 2010
@@ -23,6 +23,7 @@ import org.apache.commons.math.exception
import org.apache.commons.math.optimization.OptimizationException;
import org.apache.commons.math.optimization.VectorialPointValuePair;
import org.apache.commons.math.util.MathUtils;
+import org.apache.commons.math.util.FastMath;
/**
@@ -242,7 +243,7 @@ public class LevenbergMarquardtOptimizer
throws FunctionEvaluationException, OptimizationException, IllegalArgumentException {
// arrays shared with the other private methods
- solvedCols = Math.min(rows, cols);
+ solvedCols = FastMath.min(rows, cols);
diagR = new double[cols];
jacNorm = new double[cols];
beta = new double[cols];
@@ -302,7 +303,7 @@ public class LevenbergMarquardtOptimizer
xNorm += xk * xk;
diag[k] = dk;
}
- xNorm = Math.sqrt(xNorm);
+ xNorm = FastMath.sqrt(xNorm);
// initialize the step bound delta
delta = (xNorm == 0) ? initialStepBoundFactor : (initialStepBoundFactor * xNorm);
@@ -320,7 +321,7 @@ public class LevenbergMarquardtOptimizer
for (int i = 0; i <= j; ++i) {
sum += weightedResidualJacobian[i][pj] * qtf[i];
}
- maxCosine = Math.max(maxCosine, Math.abs(sum) / (s * cost));
+ maxCosine = FastMath.max(maxCosine, FastMath.abs(sum) / (s * cost));
}
}
}
@@ -333,7 +334,7 @@ public class LevenbergMarquardtOptimizer
// rescale if necessary
for (int j = 0; j < cols; ++j) {
- diag[j] = Math.max(diag[j], jacNorm[j]);
+ diag[j] = FastMath.max(diag[j], jacNorm[j]);
}
// inner loop
@@ -364,10 +365,10 @@ public class LevenbergMarquardtOptimizer
double s = diag[pj] * lmDir[pj];
lmNorm += s * s;
}
- lmNorm = Math.sqrt(lmNorm);
+ lmNorm = FastMath.sqrt(lmNorm);
// on the first iteration, adjust the initial step bound.
if (firstIteration) {
- delta = Math.min(delta, lmNorm);
+ delta = FastMath.min(delta, lmNorm);
}
// evaluate the function at x + p and calculate its norm
@@ -410,7 +411,7 @@ public class LevenbergMarquardtOptimizer
if ((0.1 * cost >= previousCost) || (tmp < 0.1)) {
tmp = 0.1;
}
- delta = tmp * Math.min(delta, 10.0 * lmNorm);
+ delta = tmp * FastMath.min(delta, 10.0 * lmNorm);
lmPar /= tmp;
} else if ((lmPar == 0) || (ratio >= 0.75)) {
delta = 2 * lmNorm;
@@ -426,7 +427,7 @@ public class LevenbergMarquardtOptimizer
double xK = diag[k] * point[k];
xNorm += xK * xK;
}
- xNorm = Math.sqrt(xNorm);
+ xNorm = FastMath.sqrt(xNorm);
current = new VectorialPointValuePair(point, objective);
// tests for convergence.
@@ -451,7 +452,7 @@ public class LevenbergMarquardtOptimizer
oldObj = tmpVec;
}
if (checker==null) {
- if (((Math.abs(actRed) <= costRelativeTolerance) &&
+ if (((FastMath.abs(actRed) <= costRelativeTolerance) &&
(preRed <= costRelativeTolerance) &&
(ratio <= 2.0)) ||
(delta <= parRelativeTolerance * xNorm)) {
@@ -460,7 +461,7 @@ public class LevenbergMarquardtOptimizer
}
// tests for termination and stringent tolerances
// (2.2204e-16 is the machine epsilon for IEEE754)
- if ((Math.abs(actRed) <= 2.2204e-16) && (preRed <= 2.2204e-16) && (ratio <= 2.0)) {
+ if ((FastMath.abs(actRed) <= 2.2204e-16) && (preRed <= 2.2204e-16) && (ratio <= 2.0)) {
throw new OptimizationException(LocalizedFormats.TOO_SMALL_COST_RELATIVE_TOLERANCE,
costRelativeTolerance);
} else if (delta <= 2.2204e-16 * xNorm) {
@@ -528,7 +529,7 @@ public class LevenbergMarquardtOptimizer
work1[pj] = s;
dxNorm += s * s;
}
- dxNorm = Math.sqrt(dxNorm);
+ dxNorm = FastMath.sqrt(dxNorm);
double fp = dxNorm - delta;
if (fp <= 0.1 * delta) {
lmPar = 0;
@@ -570,16 +571,16 @@ public class LevenbergMarquardtOptimizer
sum /= diag[pj];
sum2 += sum * sum;
}
- double gNorm = Math.sqrt(sum2);
+ double gNorm = FastMath.sqrt(sum2);
double paru = gNorm / delta;
if (paru == 0) {
// 2.2251e-308 is the smallest positive real for IEE754
- paru = 2.2251e-308 / Math.min(delta, 0.1);
+ paru = 2.2251e-308 / FastMath.min(delta, 0.1);
}
// if the input par lies outside of the interval (parl,paru),
// set par to the closer endpoint
- lmPar = Math.min(paru, Math.max(lmPar, parl));
+ lmPar = FastMath.min(paru, FastMath.max(lmPar, parl));
if (lmPar == 0) {
lmPar = gNorm / dxNorm;
}
@@ -588,9 +589,9 @@ public class LevenbergMarquardtOptimizer
// evaluate the function at the current value of lmPar
if (lmPar == 0) {
- lmPar = Math.max(2.2251e-308, 0.001 * paru);
+ lmPar = FastMath.max(2.2251e-308, 0.001 * paru);
}
- double sPar = Math.sqrt(lmPar);
+ double sPar = FastMath.sqrt(lmPar);
for (int j = 0; j < solvedCols; ++j) {
int pj = permutation[j];
work1[pj] = sPar * diag[pj];
@@ -604,13 +605,13 @@ public class LevenbergMarquardtOptimizer
work3[pj] = s;
dxNorm += s * s;
}
- dxNorm = Math.sqrt(dxNorm);
+ dxNorm = FastMath.sqrt(dxNorm);
double previousFP = fp;
fp = dxNorm - delta;
// if the function is small enough, accept the current value
// of lmPar, also test for the exceptional cases where parl is zero
- if ((Math.abs(fp) <= 0.1 * delta) ||
+ if ((FastMath.abs(fp) <= 0.1 * delta) ||
((parl == 0) && (fp <= previousFP) && (previousFP < 0))) {
return;
}
@@ -637,13 +638,13 @@ public class LevenbergMarquardtOptimizer
// depending on the sign of the function, update parl or paru.
if (fp > 0) {
- parl = Math.max(parl, lmPar);
+ parl = FastMath.max(parl, lmPar);
} else if (fp < 0) {
- paru = Math.min(paru, lmPar);
+ paru = FastMath.min(paru, lmPar);
}
// compute an improved estimate for lmPar
- lmPar = Math.max(parl, lmPar + correction);
+ lmPar = FastMath.max(parl, lmPar + correction);
}
}
@@ -708,13 +709,13 @@ public class LevenbergMarquardtOptimizer
final double sin;
final double cos;
double rkk = weightedResidualJacobian[k][pk];
- if (Math.abs(rkk) < Math.abs(lmDiag[k])) {
+ if (FastMath.abs(rkk) < FastMath.abs(lmDiag[k])) {
final double cotan = rkk / lmDiag[k];
- sin = 1.0 / Math.sqrt(1.0 + cotan * cotan);
+ sin = 1.0 / FastMath.sqrt(1.0 + cotan * cotan);
cos = sin * cotan;
} else {
final double tan = lmDiag[k] / rkk;
- cos = 1.0 / Math.sqrt(1.0 + tan * tan);
+ cos = 1.0 / FastMath.sqrt(1.0 + tan * tan);
sin = cos * tan;
}
@@ -804,7 +805,7 @@ public class LevenbergMarquardtOptimizer
double akk = weightedResidualJacobian[i][k];
norm2 += akk * akk;
}
- jacNorm[k] = Math.sqrt(norm2);
+ jacNorm[k] = FastMath.sqrt(norm2);
}
// transform the matrix column after column
@@ -838,7 +839,7 @@ public class LevenbergMarquardtOptimizer
// choose alpha such that Hk.u = alpha ek
double akk = weightedResidualJacobian[k][pk];
- double alpha = (akk > 0) ? -Math.sqrt(ak2) : Math.sqrt(ak2);
+ double alpha = (akk > 0) ? -FastMath.sqrt(ak2) : FastMath.sqrt(ak2);
double betak = 1.0 / (ak2 - akk * alpha);
beta[pk] = betak;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java Sun Aug 29 22:04:09 2010
@@ -26,6 +26,7 @@ import org.apache.commons.math.exception
import org.apache.commons.math.optimization.GoalType;
import org.apache.commons.math.optimization.OptimizationException;
import org.apache.commons.math.optimization.RealPointValuePair;
+import org.apache.commons.math.util.FastMath;
/**
* Non-linear conjugate gradient optimizer.
@@ -224,7 +225,7 @@ public class NonLinearConjugateGradientO
throws FunctionEvaluationException, OptimizationException {
final double yA = f.value(a);
double yB = yA;
- for (double step = h; step < Double.MAX_VALUE; step *= Math.max(2, yA / yB)) {
+ for (double step = h; step < Double.MAX_VALUE; step *= FastMath.max(2, yA / yB)) {
final double b = a + step;
yB = f.value(b);
if (yA * yB <= 0) {
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/BrentOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/BrentOptimizer.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/BrentOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/BrentOptimizer.java Sun Aug 29 22:04:09 2010
@@ -20,6 +20,7 @@ import org.apache.commons.math.FunctionE
import org.apache.commons.math.MaxIterationsExceededException;
import org.apache.commons.math.exception.NotStrictlyPositiveException;
import org.apache.commons.math.optimization.GoalType;
+import org.apache.commons.math.util.FastMath;
/**
* Implements Richard Brent's algorithm (from his book "Algorithms for
@@ -34,7 +35,7 @@ public class BrentOptimizer extends Abst
/**
* Golden section.
*/
- private static final double GOLDEN_SECTION = 0.5 * (3 - Math.sqrt(5));
+ private static final double GOLDEN_SECTION = 0.5 * (3 - FastMath.sqrt(5));
/**
* Construct a solver.
@@ -112,17 +113,17 @@ public class BrentOptimizer extends Abst
while (true) {
double m = 0.5 * (a + b);
- final double tol1 = eps * Math.abs(x) + t;
+ final double tol1 = eps * FastMath.abs(x) + t;
final double tol2 = 2 * tol1;
// Check stopping criterion.
- if (Math.abs(x - m) > tol2 - 0.5 * (b - a)) {
+ if (FastMath.abs(x - m) > tol2 - 0.5 * (b - a)) {
double p = 0;
double q = 0;
double r = 0;
double u = 0;
- if (Math.abs(e) > tol1) { // Fit parabola.
+ if (FastMath.abs(e) > tol1) { // Fit parabola.
r = (x - w) * (fx - fv);
q = (x - v) * (fx - fw);
p = (x - v) * q - (x - w) * r;
@@ -139,7 +140,7 @@ public class BrentOptimizer extends Abst
if (p > q * (a - x) &&
p < q * (b - x) &&
- Math.abs(p) < Math.abs(0.5 * q * r)) {
+ FastMath.abs(p) < FastMath.abs(0.5 * q * r)) {
// Parabolic interpolation step.
d = p / q;
u = x + d;
@@ -172,7 +173,7 @@ public class BrentOptimizer extends Abst
}
// Update by at least "tol1".
- if (Math.abs(d) < tol1) {
+ if (FastMath.abs(d) < tol1) {
if (d >= 0) {
u = x + tol1;
} else {
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/AbstractRandomGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/AbstractRandomGenerator.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/AbstractRandomGenerator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/AbstractRandomGenerator.java Sun Aug 29 22:04:09 2010
@@ -17,6 +17,7 @@
package org.apache.commons.math.random;
import org.apache.commons.math.exception.NotStrictlyPositiveException;
+import org.apache.commons.math.util.FastMath;
/**
* Abstract class implementing the {@link RandomGenerator} interface.
@@ -263,7 +264,7 @@ public abstract class AbstractRandomGene
s = v1 * v1 + v2 * v2;
}
if (s != 0) {
- s = Math.sqrt(-2 * Math.log(s) / s);
+ s = FastMath.sqrt(-2 * FastMath.log(s) / s);
}
cachedNormalDeviate = v2 * s;
return v1 * s;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/BitsStreamGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/BitsStreamGenerator.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/BitsStreamGenerator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/BitsStreamGenerator.java Sun Aug 29 22:04:09 2010
@@ -17,6 +17,7 @@
package org.apache.commons.math.random;
import org.apache.commons.math.exception.NotStrictlyPositiveException;
+import org.apache.commons.math.util.FastMath;
/** Base class for random number generators that generates bits streams.
@@ -99,10 +100,10 @@ public abstract class BitsStreamGenerato
// generate a new pair of gaussian numbers
final double x = nextDouble();
final double y = nextDouble();
- final double alpha = 2 * Math.PI * x;
- final double r = Math.sqrt(-2 * Math.log(y));
- random = r * Math.cos(alpha);
- nextGaussian = r * Math.sin(alpha);
+ final double alpha = 2 * FastMath.PI * x;
+ final double r = FastMath.sqrt(-2 * FastMath.log(y));
+ random = r * FastMath.cos(alpha);
+ nextGaussian = r * FastMath.sin(alpha);
} else {
// use the second element of the pair already generated
random = nextGaussian;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/CorrelatedRandomVectorGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/CorrelatedRandomVectorGenerator.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/CorrelatedRandomVectorGenerator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/CorrelatedRandomVectorGenerator.java Sun Aug 29 22:04:09 2010
@@ -21,6 +21,7 @@ import org.apache.commons.math.Dimension
import org.apache.commons.math.linear.MatrixUtils;
import org.apache.commons.math.linear.NotPositiveDefiniteMatrixException;
import org.apache.commons.math.linear.RealMatrix;
+import org.apache.commons.math.util.FastMath;
/**
* A {@link RandomVectorGenerator} that generates vectors with with
@@ -243,7 +244,7 @@ public class CorrelatedRandomVectorGener
} else {
// transform the matrix
- double sqrt = Math.sqrt(c[ir][ir]);
+ double sqrt = FastMath.sqrt(c[ir][ir]);
b[rank][rank] = sqrt;
double inverse = 1 / sqrt;
for (int i = rank + 1; i < order; ++i) {
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java Sun Aug 29 22:04:09 2010
@@ -31,6 +31,7 @@ import org.apache.commons.math.MathRunti
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.stat.descriptive.StatisticalSummary;
import org.apache.commons.math.stat.descriptive.SummaryStatistics;
+import org.apache.commons.math.util.FastMath;
/**
* Implements <code>EmpiricalDistribution</code> interface. This implementation
@@ -356,8 +357,8 @@ public class EmpiricalDistributionImpl i
* @return the index of the bin containing the value
*/
private int findBin(double value) {
- return Math.min(
- Math.max((int) Math.ceil((value- min) / delta) - 1, 0),
+ return FastMath.min(
+ FastMath.max((int) FastMath.ceil((value- min) / delta) - 1, 0),
binCount - 1);
}
@@ -374,7 +375,7 @@ public class EmpiricalDistributionImpl i
}
// Start with a uniformly distributed random number in (0,1)
- double x = Math.random();
+ double x = FastMath.random();
// Use this to select the bin and generate a Gaussian within the bin
for (int i = 0; i < binCount; i++) {
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/MersenneTwister.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/MersenneTwister.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/MersenneTwister.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/MersenneTwister.java Sun Aug 29 22:04:09 2010
@@ -18,6 +18,8 @@ package org.apache.commons.math.random;
import java.io.Serializable;
+import org.apache.commons.math.util.FastMath;
+
/** This class implements a powerful pseudo-random number generator
* developed by Makoto Matsumoto and Takuji Nishimura during
@@ -167,7 +169,7 @@ public class MersenneTwister extends Bit
int i = 1;
int j = 0;
- for (int k = Math.max(N, seed.length); k != 0; k--) {
+ for (int k = FastMath.max(N, seed.length); k != 0; k--) {
long l0 = (mt[i] & 0x7fffffffl) | ((mt[i] < 0) ? 0x80000000l : 0x0l);
long l1 = (mt[i-1] & 0x7fffffffl) | ((mt[i-1] < 0) ? 0x80000000l : 0x0l);
long l = (l0 ^ ((l1 ^ (l1 >> 30)) * 1664525l)) + seed[j] + j; // non linear
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java Sun Aug 29 22:04:09 2010
@@ -43,6 +43,7 @@ import org.apache.commons.math.distribut
import org.apache.commons.math.distribution.WeibullDistributionImpl;
import org.apache.commons.math.distribution.ZipfDistributionImpl;
import org.apache.commons.math.util.MathUtils;
+import org.apache.commons.math.util.FastMath;
/**
* Implements the {@link RandomData} interface using a {@link RandomGenerator}
@@ -362,7 +363,7 @@ public class RandomDataImpl implements R
final double pivot = 40.0d;
if (mean < pivot) {
- double p = Math.exp(-mean);
+ double p = FastMath.exp(-mean);
long n = 0;
double r = 1.0d;
double rnd = 1.0d;
@@ -378,16 +379,16 @@ public class RandomDataImpl implements R
}
return n;
} else {
- final double lambda = Math.floor(mean);
+ final double lambda = FastMath.floor(mean);
final double lambdaFractional = mean - lambda;
- final double logLambda = Math.log(lambda);
+ final double logLambda = FastMath.log(lambda);
final double logLambdaFactorial = MathUtils.factorialLog((int) lambda);
final long y2 = lambdaFractional < Double.MIN_VALUE ? 0 : nextPoisson(lambdaFractional);
- final double delta = Math.sqrt(lambda * Math.log(32 * lambda / Math.PI + 1));
+ final double delta = FastMath.sqrt(lambda * FastMath.log(32 * lambda / FastMath.PI + 1));
final double halfDelta = delta / 2;
final double twolpd = 2 * lambda + delta;
- final double a1 = Math.sqrt(Math.PI * twolpd) * Math.exp(1 / 8 * lambda);
- final double a2 = (twolpd / delta) * Math.exp(-delta * (1 + delta) / twolpd);
+ final double a1 = FastMath.sqrt(FastMath.PI * twolpd) * FastMath.exp(1 / 8 * lambda);
+ final double a2 = (twolpd / delta) * FastMath.exp(-delta * (1 + delta) / twolpd);
final double aSum = a1 + a2 + 1;
final double p1 = a1 / aSum;
final double p2 = a2 / aSum;
@@ -404,11 +405,11 @@ public class RandomDataImpl implements R
final double u = nextUniform(0.0, 1);
if (u <= p1) {
final double n = nextGaussian(0d, 1d);
- x = n * Math.sqrt(lambda + halfDelta) - 0.5d;
+ x = n * FastMath.sqrt(lambda + halfDelta) - 0.5d;
if (x > delta || x < -lambda) {
continue;
}
- y = x < 0 ? Math.floor(x) : Math.ceil(x);
+ y = x < 0 ? FastMath.floor(x) : FastMath.ceil(x);
final double e = nextExponential(1d);
v = -e - (n * n / 2) + c1;
} else {
@@ -417,7 +418,7 @@ public class RandomDataImpl implements R
break;
} else {
x = delta + (twolpd / delta) * nextExponential(1d);
- y = Math.ceil(x);
+ y = FastMath.ceil(x);
v = -nextExponential(1d) - delta * (x + 1) / twolpd;
}
}
@@ -487,7 +488,7 @@ public class RandomDataImpl implements R
while (unif == 0.0d) {
unif = generator.nextDouble();
}
- return -mean * Math.log(unif);
+ return -mean * FastMath.log(unif);
}
/**
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/UniformRandomGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/UniformRandomGenerator.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/UniformRandomGenerator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/UniformRandomGenerator.java Sun Aug 29 22:04:09 2010
@@ -17,6 +17,8 @@
package org.apache.commons.math.random;
+import org.apache.commons.math.util.FastMath;
+
/**
* This class implements a normalized uniform random generator.
* <p>Since it is a normalized random generator, it generates values
@@ -35,7 +37,7 @@ public class UniformRandomGenerator impl
private static final long serialVersionUID = 1569292426375546027L;
/** Square root of three. */
- private static final double SQRT3 = Math.sqrt(3.0);
+ private static final double SQRT3 = FastMath.sqrt(3.0);
/** Underlying generator. */
private final RandomGenerator generator;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/UnitSphereRandomVectorGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/UnitSphereRandomVectorGenerator.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/UnitSphereRandomVectorGenerator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/UnitSphereRandomVectorGenerator.java Sun Aug 29 22:04:09 2010
@@ -17,6 +17,8 @@
package org.apache.commons.math.random;
+import org.apache.commons.math.util.FastMath;
+
/**
* Generate random vectors isotropically located on the surface of a sphere.
@@ -70,7 +72,7 @@ public class UnitSphereRandomVectorGener
}
} while (normSq > 1);
- final double f = 1 / Math.sqrt(normSq);
+ final double f = 1 / FastMath.sqrt(normSq);
for (int i = 0; i < dimension; i++) {
v[i] *= f;
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Beta.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Beta.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Beta.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Beta.java Sun Aug 29 22:04:09 2010
@@ -18,6 +18,7 @@ package org.apache.commons.math.special;
import org.apache.commons.math.MathException;
import org.apache.commons.math.util.ContinuedFraction;
+import org.apache.commons.math.util.FastMath;
/**
* This is a utility class that provides computation methods related to the
@@ -148,8 +149,8 @@ public class Beta {
return 1.0;
}
};
- ret = Math.exp((a * Math.log(x)) + (b * Math.log(1.0 - x)) -
- Math.log(a) - logBeta(a, b, epsilon, maxIterations)) *
+ ret = FastMath.exp((a * FastMath.log(x)) + (b * FastMath.log(1.0 - x)) -
+ FastMath.log(a) - logBeta(a, b, epsilon, maxIterations)) *
1.0 / fraction.evaluate(x, epsilon, maxIterations);
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Gamma.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Gamma.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Gamma.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/special/Gamma.java Sun Aug 29 22:04:09 2010
@@ -19,6 +19,7 @@ package org.apache.commons.math.special;
import org.apache.commons.math.MathException;
import org.apache.commons.math.MaxIterationsExceededException;
import org.apache.commons.math.util.ContinuedFraction;
+import org.apache.commons.math.util.FastMath;
/**
* This is a utility class that provides computation methods related to the
@@ -58,7 +59,7 @@ public class Gamma {
};
/** Avoid repeated computation of log of 2 PI in logGamma */
- private static final double HALF_LOG_2_PI = 0.5 * Math.log(2.0 * Math.PI);
+ private static final double HALF_LOG_2_PI = 0.5 * FastMath.log(2.0 * FastMath.PI);
// limits for switching algorithm in digamma
/** C limit. */
@@ -106,8 +107,8 @@ public class Gamma {
sum = sum + LANCZOS[0];
double tmp = x + g + .5;
- ret = ((x + .5) * Math.log(tmp)) - tmp +
- HALF_LOG_2_PI + Math.log(sum / x);
+ ret = ((x + .5) * FastMath.log(tmp)) - tmp +
+ HALF_LOG_2_PI + FastMath.log(sum / x);
}
return ret;
@@ -175,7 +176,7 @@ public class Gamma {
double n = 0.0; // current element index
double an = 1.0 / a; // n-th element in the series
double sum = an; // partial sum
- while (Math.abs(an/sum) > epsilon && n < maxIterations && sum < Double.POSITIVE_INFINITY) {
+ while (FastMath.abs(an/sum) > epsilon && n < maxIterations && sum < Double.POSITIVE_INFINITY) {
// compute next element in the series
n = n + 1.0;
an = an * (x / (a + n));
@@ -188,7 +189,7 @@ public class Gamma {
} else if (Double.isInfinite(sum)) {
ret = 1.0;
} else {
- ret = Math.exp(-x + (a * Math.log(x)) - logGamma(a)) * sum;
+ ret = FastMath.exp(-x + (a * FastMath.log(x)) - logGamma(a)) * sum;
}
}
@@ -263,7 +264,7 @@ public class Gamma {
};
ret = 1.0 / cf.evaluate(x, epsilon, maxIterations);
- ret = Math.exp(-x + (a * Math.log(x)) - logGamma(a)) * ret;
+ ret = FastMath.exp(-x + (a * FastMath.log(x)) - logGamma(a)) * ret;
}
return ret;
@@ -303,7 +304,7 @@ public class Gamma {
// 1 1 1 1
// log(x) - --- - ------ + ------- - -------
// 2 x 12 x^2 120 x^4 252 x^6
- return Math.log(x) - 0.5 / x - inv * ((1.0 / 12) + inv * (1.0 / 120 - inv / 252));
+ return FastMath.log(x) - 0.5 / x - inv * ((1.0 / 12) + inv * (1.0 / 120 - inv / 252));
}
return digamma(x + 1) - 1 / x;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java Sun Aug 29 22:04:09 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/trunk/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java Sun Aug 29 22:04:09 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/trunk/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java Sun Aug 29 22:04:09 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/trunk/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java Sun Aug 29 22:04:09 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/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java Sun Aug 29 22:04:09 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/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java Sun Aug 29 22:04:09 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/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java Sun Aug 29 22:04:09 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/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Skewness.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Skewness.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Skewness.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Skewness.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;
/**
* 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/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviation.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;
/**
* 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/trunk/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java Sun Aug 29 22:04:09 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/trunk/src/main/java/org/apache/commons/math/stat/descriptive/summary/Product.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/summary/Product.java?rev=990658&r1=990657&r2=990658&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/summary/Product.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/summary/Product.java Sun Aug 29 22:04:09 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;