/** {@inheritDoc} */ @Override public RealVector mapExpToSelf() { for (int i = 0; i < data.length; i++) { data[i] = FastMath.exp(data[i]); } return this; }
/** * Returns the <a href="http://mathworld.wolfram.com/HyperbolicCosine.html"> * hyperbolic cosine</a> of x. * * @param x double value for which to find the hyperbolic cosine * @return hyperbolic cosine of x */ public static double cosh(double x) { return (FastMath.exp(x) + FastMath.exp(-x)) / 2.0; }
/** * 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) { double x0 = x - mean; return FastMath.exp(-x0 * x0 / (2 * standardDeviation * standardDeviation)) / (standardDeviation * SQRT2PI); }
/** {@inheritDoc} */ @Override public double value(double d) { return FastMath.exp(d); } };
/** * Return 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) { if (x < 0) { return 0; } return FastMath.exp(-x / mean) / mean; }
/** * For this distribution, X, this method returns P(X < x). * * The implementation of this method is based on: * <ul> * <li> * <a href="http://mathworld.wolfram.com/ExponentialDistribution.html"> * Exponential Distribution</a>, equation (1).</li> * </ul> * * @param x the value at which the CDF is evaluated. * @return CDF for this distribution. * @throws MathException if the cumulative probability can not be * computed due to convergence or other numerical errors. */ public double cumulativeProbability(double x) throws MathException{ double ret; if (x <= 0.0) { ret = 0.0; } else { ret = 1.0 - FastMath.exp(-x / mean); } return ret; }
/** * Exponential function. * * Computes exp(x), function result is nearly rounded. It will be correctly * rounded to the theoretical value for 99.9% of input values, otherwise it will * have a 1 UPL error. * * Method: * Lookup intVal = exp(int(x)) * Lookup fracVal = exp(int(x-int(x) / 1024.0) * 1024.0 ); * Compute z as the exponential of the remaining bits by a polynomial minus one * exp(x) = intVal * fracVal * (1 + z) * * Accuracy: * Calculation is done with 63 bits of precision, so result should be correctly * rounded for 99.9% of input values, with less than 1 ULP error otherwise. * * @param x a double * @return double e<sup>x</sup> */ public static double exp(double x) { return exp(x, 0.0, null); }
/** * 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. */ @Override public double density(double x) { if (x < 0) return 0; return FastMath.pow(x / beta, alpha - 1) / beta * FastMath.exp(-x / beta) / FastMath.exp(Gamma.logGamma(alpha)); }
/** * For this distribution, X, this method returns P(X < <code>x</code>). * @param x the value at which the CDF is evaluated. * @return CDF evaluated at <code>x</code>. */ public double cumulativeProbability(double x) { double ret; if (x <= 0.0) { ret = 0.0; } else { ret = 1.0 - FastMath.exp(-FastMath.pow(x / scale, shape)); } return ret; }
/** * For this distribution, X, this method returns P(X = x). * * @param x the value at which the PMF is evaluated. * @return PMF for this distribution. */ public double probability(int x) { double ret; if (x < 0 || x > numberOfTrials) { ret = 0.0; } else { ret = FastMath.exp(SaddlePointExpansion.logBinomialProbability(x, numberOfTrials, probabilityOfSuccess, 1.0 - probabilityOfSuccess)); } return ret; }
/** * 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) { 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); }
/** * Returns the geometric mean of the entries in the specified portion * of the input array. * <p> * See {@link GeometricMean} for details on the computing algorithm.</p> * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * * @param values input array containing the values * @param begin first array element to include * @param length the number of elements to include * @return the geometric mean or Double.NaN if length = 0 or * any of the values are <= 0. * @throws IllegalArgumentException if the input array is null or the array * index parameters are not valid */ @Override public double evaluate( final double[] values, final int begin, final int length) { return FastMath.exp( sumOfLogs.evaluate(values, begin, length) / length); }
/** * The probability mass function P(X = x) for a Poisson distribution. * * @param x the value at which the probability density function is * evaluated. * @return the value of the probability mass function at x */ public double probability(int x) { double ret; if (x < 0 || x == Integer.MAX_VALUE) { ret = 0.0; } else if (x == 0) { ret = FastMath.exp(-mean); } else { ret = FastMath.exp(-SaddlePointExpansion.getStirlingError(x) - SaddlePointExpansion.getDeviancePart(x, mean)) / FastMath.sqrt(MathUtils.TWO_PI * x); } return ret; }
/** * {@inheritDoc} */ @Override public double getResult() { if (sumOfLogs.getN() > 0) { return FastMath.exp(sumOfLogs.getResult() / sumOfLogs.getN()); } else { return Double.NaN; } }
/** * Calculates the mean. * * The mean is <code>scale * Gamma(1 + (1 / shape))</code> * where <code>Gamma(...)</code> is the Gamma-function * * @return the mean * @since 2.2 */ protected double calculateNumericalMean() { final double sh = getShape(); final double sc = getScale(); return sc * FastMath.exp(Gamma.logGamma(1 + (1 / sh))); }
/** * 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)); }
/** * Calculates the variance. * * The variance is * <code>scale^2 * Gamma(1 + (2 / shape)) - mean^2</code> * where <code>Gamma(...)</code> is the Gamma-function * * @return the variance * @since 2.2 */ private double calculateNumericalVariance() { final double sh = getShape(); final double sc = getScale(); final double mn = getNumericalMean(); return (sc * sc) * FastMath.exp(Gamma.logGamma(1 + (2 / sh))) - (mn * mn); }
/** * 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 n = degreesOfFreedom; final double nPlus1Over2 = (n + 1) / 2; return FastMath.exp(Gamma.logGamma(nPlus1Over2) - 0.5 * (FastMath.log(FastMath.PI) + FastMath.log(n)) - Gamma.logGamma(n/2) - nPlus1Over2 * FastMath.log(1 + x * x /n)); }
/** * 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)); }