List of usage examples for org.apache.commons.math3.util FastMath E
double E
To view the source code for org.apache.commons.math3.util FastMath E.
Click Source Link
From source file:com.cloudera.oryx.rdf.common.information.NumericInformationTest.java
private static double differentialEntropy(StandardDeviation stdev) { return FastMath.log(stdev.getResult() * FastMath.sqrt(2.0 * FastMath.PI * FastMath.E)); }
From source file:statalign.utils.GammaDistribution.java
/** * Creates a Gamma distribution./* ww w .j a v a2 s . c o m*/ * * @param rng Random number generator. * @param shape the shape parameter * @param scale the scale parameter * @param inverseCumAccuracy the maximum absolute error in inverse * cumulative probability estimates (defaults to * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}). * @throws NotStrictlyPositiveException if {@code shape <= 0} or * {@code scale <= 0}. * @since 3.1 */ public GammaDistribution(RandomGenerator rng, double shape, double scale, double inverseCumAccuracy) throws NotStrictlyPositiveException { super(rng); if (shape <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.SHAPE, shape); } if (scale <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.SCALE, scale); } this.shape = shape; this.scale = scale; this.solverAbsoluteAccuracy = inverseCumAccuracy; this.shiftedShape = shape + Gamma.LANCZOS_G + 0.5; final double aux = FastMath.E / (2.0 * FastMath.PI * shiftedShape); this.densityPrefactor2 = shape * FastMath.sqrt(aux) / Gamma.lanczos(shape); this.densityPrefactor1 = this.densityPrefactor2 / scale * FastMath.pow(shiftedShape, -shape) * FastMath.exp(shape + Gamma.LANCZOS_G); this.minY = shape + Gamma.LANCZOS_G - FastMath.log(Double.MAX_VALUE); this.maxLogY = FastMath.log(Double.MAX_VALUE) / (shape - 1.0); }
From source file:statalign.utils.GammaDistribution.java
/** * <p>This implementation uses the following algorithms: </p> * * <p>For 0 < shape < 1: <br/> * Ahrens, J. H. and Dieter, U., <i>Computer methods for * sampling from gamma, beta, Poisson and binomial distributions.</i> * Computing, 12, 223-246, 1974.</p> * * <p>For shape >= 1: <br/> * Marsaglia and Tsang, <i>A Simple Method for Generating * Gamma Variables.</i> ACM Transactions on Mathematical Software, * Volume 26 Issue 3, September, 2000.</p> * * @return random value sampled from the Gamma(shape, scale) distribution *///from w ww. j a v a 2 s . c om @Override public double sample() { if (shape < 1) { // [1]: p. 228, Algorithm GS while (true) { // Step 1: final double u = random.nextDouble(); final double bGS = 1 + shape / FastMath.E; final double p = bGS * u; if (p <= 1) { // Step 2: final double x = FastMath.pow(p, 1 / shape); final double u2 = random.nextDouble(); if (u2 > FastMath.exp(-x)) { // Reject continue; } else { return scale * x; } } else { // Step 3: final double x = -1 * FastMath.log((bGS - p) / shape); final double u2 = random.nextDouble(); if (u2 > FastMath.pow(x, shape - 1)) { // Reject continue; } else { return scale * x; } } } } // Now shape >= 1 final double d = shape - 0.333333333333333333; final double c = 1 / (3 * FastMath.sqrt(d)); while (true) { final double x = random.nextGaussian(); final double v = (1 + c * x) * (1 + c * x) * (1 + c * x); if (v <= 0) { continue; } final double x2 = x * x; final double u = random.nextDouble(); // Squeeze if (u < 1 - 0.0331 * x2 * x2) { return scale * d * v; } if (FastMath.log(u) < 0.5 * x2 + d * (1 - v + FastMath.log(v))) { return scale * d * v; } } }