Java Code Examples for org.apache.commons.math.util.FastMath#exp()
The following examples show how to use
org.apache.commons.math.util.FastMath#exp() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MinpackTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Override protected double[] getResiduals() { double x01 = parameters[0].getEstimate(); double x02 = parameters[1].getEstimate(); double x03 = parameters[2].getEstimate(); double x04 = parameters[3].getEstimate(); double x05 = parameters[4].getEstimate(); double x06 = parameters[5].getEstimate(); double x07 = parameters[6].getEstimate(); double x08 = parameters[7].getEstimate(); double x09 = parameters[8].getEstimate(); double x10 = parameters[9].getEstimate(); double x11 = parameters[10].getEstimate(); double[] f = new double[m]; for (int i = 0; i < m; ++i) { double temp = i / 10.0; double tmp1 = FastMath.exp(-x05 * temp); double tmp2 = FastMath.exp(-x06 * (temp - x09) * (temp - x09)); double tmp3 = FastMath.exp(-x07 * (temp - x10) * (temp - x10)); double tmp4 = FastMath.exp(-x08 * (temp - x11) * (temp - x11)); f[i] = y[i] - (x01 * tmp1 + x02 * tmp2 + x03 * tmp3 + x04 * tmp4); } return f; }
Example 2
Source File: WeibullDistributionImpl.java From astor with GNU General Public License v2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public double density(double x) { if (x < 0) { return 0; } final double xscale = x / scale; final double xscalepow = FastMath.pow(xscale, shape - 1); /* * FastMath.pow(x / scale, shape) = * FastMath.pow(xscale, shape) = * FastMath.pow(xscale, shape - 1) * xscale */ final double xscalepowshape = xscalepow * xscale; return (shape / scale) * xscalepow * FastMath.exp(-xscalepowshape); }
Example 3
Source File: HypergeometricDistributionImpl.java From astor with GNU General Public License v2.0 | 6 votes |
/** * For this distribution, {@code X}, this method returns {@code P(X = x)}. * * @param x Value at which the PMF is evaluated. * @return PMF for this distribution. */ public double probability(int x) { double ret; int[] domain = getDomain(populationSize, numberOfSuccesses, sampleSize); if (x < domain[0] || x > domain[1]) { ret = 0.0; } else { double p = (double) sampleSize / (double) populationSize; double q = (double) (populationSize - sampleSize) / (double) populationSize; double p1 = SaddlePointExpansion.logBinomialProbability(x, numberOfSuccesses, p, q); double p2 = SaddlePointExpansion.logBinomialProbability(sampleSize - x, populationSize - numberOfSuccesses, p, q); double p3 = SaddlePointExpansion.logBinomialProbability(sampleSize, populationSize, p, q); ret = FastMath.exp(p1 + p2 - p3); } return ret; }
Example 4
Source File: ExponentialDistributionImpl.java From astor with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public double density(double x) { if (x < 0) { return 0; } return FastMath.exp(-x / mean) / mean; }
Example 5
Source File: GeometricMean.java From astor with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public double getResult() { if (sumOfLogs.getN() > 0) { return FastMath.exp(sumOfLogs.getResult() / sumOfLogs.getN()); } else { return Double.NaN; } }
Example 6
Source File: TestProblem1.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public double[] computeTheoreticalState(double t) { double c = FastMath.exp (t0 - t); for (int i = 0; i < n; ++i) { y[i] = c * y0[i]; } return y; }
Example 7
Source File: Sigmoid.java From astor with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} */ public UnivariateRealFunction derivative() { return new UnivariateRealFunction() { /** {@inheritDoc} */ public double value(double x) { final double exp = FastMath.exp(-x); if (Double.isInfinite(exp)) { // Avoid returning NaN in case of overflow. return 0; } final double exp1 = 1 + exp; return (hi - lo) * exp / (exp1 * exp1); } }; }
Example 8
Source File: MinpackTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public double[] value(double[] variables) { double x1 = variables[0]; double x2 = variables[1]; double x3 = variables[2]; double[] f = new double[m]; for (int i = 0; i < m; ++i) { f[i] = x1 * FastMath.exp(x2 / (5.0 * (i + 1) + 45.0 + x3)) - y[i]; } return f; }
Example 9
Source File: FDistributionImpl.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Returns the probability density for a particular point. * * @param x The point at which the density should be computed. * @return The pdf at point x. * @since 2.1 */ @Override public double density(double x) { final double nhalf = numeratorDegreesOfFreedom / 2; final double mhalf = denominatorDegreesOfFreedom / 2; final double logx = FastMath.log(x); final double logn = FastMath.log(numeratorDegreesOfFreedom); final double logm = FastMath.log(denominatorDegreesOfFreedom); final double lognxm = FastMath.log(numeratorDegreesOfFreedom * x + denominatorDegreesOfFreedom); return FastMath.exp(nhalf*logn + nhalf*logx - logx + mhalf*logm - nhalf*lognxm - mhalf*lognxm - Beta.logBeta(nhalf, mhalf)); }
Example 10
Source File: MinpackTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public double[] value(double[] variables) { double x1 = variables[0]; double x2 = variables[1]; double[] f = new double[m]; for (int i = 0; i < m; ++i) { double temp = i + 1; f[i] = 2 + 2 * temp - FastMath.exp(temp * x1) - FastMath.exp(temp * x2); } return f; }
Example 11
Source File: Expm1Function.java From astor with GNU General Public License v2.0 | 5 votes |
public UnivariateRealFunction derivative() { return new UnivariateRealFunction() { public double value(double x) { return FastMath.exp(x); } }; }
Example 12
Source File: MinpackTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public double[] value(double[] variables) { double x1 = variables[0]; double x2 = variables[1]; double x3 = variables[2]; double[] f = new double[m]; for (int i = 0; i < m; ++i) { double tmp = (i + 1) / 10.0; f[i] = FastMath.exp(-tmp * x1) - FastMath.exp(-tmp * x2) + (FastMath.exp(-i - 1) - FastMath.exp(-tmp)) * x3; } return f; }
Example 13
Source File: ExponentialDistributionImpl.java From astor with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public double density(double x) { if (x < 0) { return 0; } return FastMath.exp(-x / mean) / mean; }
Example 14
Source File: Gamma.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Returns the regularized gamma function P(a, x). * * The implementation of this method is based on: * <ul> * <li> * <a href="http://mathworld.wolfram.com/RegularizedGammaFunction.html"> * Regularized Gamma Function</a>, equation (1) * </li> * <li> * <a href="http://mathworld.wolfram.com/IncompleteGammaFunction.html"> * Incomplete Gamma Function</a>, equation (4). * </li> * <li> * <a href="http://mathworld.wolfram.com/ConfluentHypergeometricFunctionoftheFirstKind.html"> * Confluent Hypergeometric Function of the First Kind</a>, equation (1). * </li> * </ul> * * @param a the a parameter. * @param x the value. * @param epsilon When the absolute value of the nth item in the * series is less than epsilon the approximation ceases to calculate * further elements in the series. * @param maxIterations Maximum number of "iterations" to complete. * @return the regularized gamma function P(a, x) * @throws MaxCountExceededException if the algorithm fails to converge. */ public static double regularizedGammaP(double a, double x, double epsilon, int maxIterations) { double ret; if (Double.isNaN(a) || Double.isNaN(x) || (a <= 0.0) || (x < 0.0)) { ret = Double.NaN; } else if (x == 0.0) { ret = 0.0; } else if (x >= a + 1) { // use regularizedGammaQ because it should converge faster in this // case. ret = 1.0 - regularizedGammaQ(a, x, epsilon, maxIterations); } else { // calculate series double n = 0.0; // current element index double an = 1.0 / a; // n-th element in the series double sum = an; // partial sum 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)); // update partial sum sum = sum + an; } if (n >= maxIterations) { throw new MaxCountExceededException(maxIterations); } else if (Double.isInfinite(sum)) { ret = 1.0; } else { ret = FastMath.exp(-x + (a * FastMath.log(x)) - logGamma(a)) * sum; } } return ret; }
Example 15
Source File: arja8_eigth_s.java From coming with MIT License | 3 votes |
/** * Compute the * <a href="http://mathworld.wolfram.com/ExponentialFunction.html" TARGET="_top"> * exponential function</a> of this complex number. * <p> * Implements the formula: <pre> * <code> exp(a + bi) = exp(a)cos(b) + exp(a)sin(b)i</code></pre> * where the (real) functions on the right-hand side are * {@link java.lang.Math#exp}, {@link java.lang.Math#cos}, and * {@link java.lang.Math#sin}.</p> * <p> * Returns {@link Complex#NaN} if either real or imaginary part of the * input argument is <code>NaN</code>.</p> * <p> * Infinite values in real or imaginary parts of the input may result in * infinite or NaN values returned in parts of the result.<pre> * Examples: * <code> * exp(1 ± INFINITY i) = NaN + NaN i * exp(INFINITY + i) = INFINITY + INFINITY i * exp(-INFINITY + i) = 0 + 0i * exp(±INFINITY ± INFINITY i) = NaN + NaN i</code></pre></p> * * @return <i>e</i><sup><code>this</code></sup> * @since 1.2 */ public Complex exp() { if (isNaN) { return NaN; } double expReal = FastMath.exp(real); return createComplex(expReal * FastMath.cos(imaginary), expReal * FastMath.sin(imaginary)); }
Example 16
Source File: JGenProg2017_0065_s.java From coming with MIT License | 3 votes |
/** * Compute the * <a href="http://mathworld.wolfram.com/ExponentialFunction.html" TARGET="_top"> * exponential function</a> of this complex number. * <p> * Implements the formula: <pre> * <code> exp(a + bi) = exp(a)cos(b) + exp(a)sin(b)i</code></pre> * where the (real) functions on the right-hand side are * {@link java.lang.Math#exp}, {@link java.lang.Math#cos}, and * {@link java.lang.Math#sin}.</p> * <p> * Returns {@link Complex#NaN} if either real or imaginary part of the * input argument is <code>NaN</code>.</p> * <p> * Infinite values in real or imaginary parts of the input may result in * infinite or NaN values returned in parts of the result.<pre> * Examples: * <code> * exp(1 ± INFINITY i) = NaN + NaN i * exp(INFINITY + i) = INFINITY + INFINITY i * exp(-INFINITY + i) = 0 + 0i * exp(±INFINITY ± INFINITY i) = NaN + NaN i</code></pre></p> * * @return <i>e</i><sup><code>this</code></sup> * @since 1.2 */ public Complex exp() { if (isNaN) { return NaN; } double expReal = FastMath.exp(real); return createComplex(expReal * FastMath.cos(imaginary), expReal * FastMath.sin(imaginary)); }
Example 17
Source File: Cardumen_00168_s.java From coming with MIT License | 3 votes |
/** * Compute the * <a href="http://mathworld.wolfram.com/ExponentialFunction.html" TARGET="_top"> * exponential function</a> of this complex number. * Implements the formula: * <pre> * <code> * exp(a + bi) = exp(a)cos(b) + exp(a)sin(b)i * </code> * </pre> * where the (real) functions on the right-hand side are * {@link java.lang.Math#exp}, {@link java.lang.Math#cos}, and * {@link java.lang.Math#sin}. * <br/> * Returns {@link Complex#NaN} if either real or imaginary part of the * input argument is {@code NaN}. * <br/> * Infinite values in real or imaginary parts of the input may result in * infinite or NaN values returned in parts of the result. * <pre> * Examples: * <code> * exp(1 ± INFINITY i) = NaN + NaN i * exp(INFINITY + i) = INFINITY + INFINITY i * exp(-INFINITY + i) = 0 + 0i * exp(±INFINITY ± INFINITY i) = NaN + NaN i * </code> * </pre> * * @return <code><i>e</i><sup>this</sup></code>. * @since 1.2 */ public Complex exp() { if (isNaN) { return NaN; } double expReal = FastMath.exp(real); return createComplex(expReal * FastMath.cos(imaginary), expReal * FastMath.sin(imaginary)); }
Example 18
Source File: Complex.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Compute the * <a href="http://mathworld.wolfram.com/ExponentialFunction.html" TARGET="_top"> * exponential function</a> of this complex number. * Implements the formula: * <pre> * <code> * exp(a + bi) = exp(a)cos(b) + exp(a)sin(b)i * </code> * </pre> * where the (real) functions on the right-hand side are * {@link java.lang.Math#exp}, {@link java.lang.Math#cos}, and * {@link java.lang.Math#sin}. * <br/> * Returns {@link Complex#NaN} if either real or imaginary part of the * input argument is {@code NaN}. * <br/> * Infinite values in real or imaginary parts of the input may result in * infinite or NaN values returned in parts of the result. * <pre> * Examples: * <code> * exp(1 ± INFINITY i) = NaN + NaN i * exp(INFINITY + i) = INFINITY + INFINITY i * exp(-INFINITY + i) = 0 + 0i * exp(±INFINITY ± INFINITY i) = NaN + NaN i * </code> * </pre> * * @return <code><i>e</i><sup>this</sup></code>. * @since 1.2 */ public Complex exp() { if (isNaN) { return NaN; } double expReal = FastMath.exp(real); return createComplex(expReal * FastMath.cos(imaginary), expReal * FastMath.sin(imaginary)); }
Example 19
Source File: HypergeometricDistributionImpl.java From astor with GNU General Public License v2.0 | 2 votes |
/** * For this distribution, {@code X}, defined by the given hypergeometric * distribution parameters, this method returns {@code P(X = x)}. * * @param x Value at which the PMF is evaluated. * @param n the population size. * @param m number of successes in the population. * @param k the sample size. * @return PMF for the distribution. */ private double probability(int n, int m, int k, int x) { return FastMath.exp(MathUtils.binomialCoefficientLog(m, x) + MathUtils.binomialCoefficientLog(n - m, k - x) - MathUtils.binomialCoefficientLog(n, k)); }
Example 20
Source File: HypergeometricDistributionImpl.java From astor with GNU General Public License v2.0 | 2 votes |
/** * For the distribution, X, defined by the given hypergeometric distribution * parameters, this method returns P(X = x). * * @param n the population size. * @param m number of successes in the population. * @param k the sample size. * @param x the value at which the PMF is evaluated. * @return PMF for the distribution. */ private double probability(int n, int m, int k, int x) { return FastMath.exp(MathUtils.binomialCoefficientLog(m, x) + MathUtils.binomialCoefficientLog(n - m, k - x) - MathUtils.binomialCoefficientLog(n, k)); }