Example usage for java.lang Math exp

List of usage examples for java.lang Math exp

Introduction

In this page you can find the example usage for java.lang Math exp.

Prototype

@HotSpotIntrinsicCandidate
public static double exp(double a) 

Source Link

Document

Returns Euler's number e raised to the power of a double value.

Usage

From source file:Main.java

/**
 * Returns n!. Shorthand for <code>n</code> <a
 * href="http://mathworld.wolfram.com/Factorial.html"> Factorial</a>, the
 * product of the numbers <code>1,...,n</code> as a <code>double</code>.
 * <p>//from   w  w w . j  a  v a  2 s  . c o  m
 * <Strong>Preconditions</strong>:
 * <ul>
 * <li> <code>n >= 0</code> (otherwise
 * <code>IllegalArgumentException</code> is thrown)</li>
 * <li> The result is small enough to fit into a <code>double</code>. The
 * largest value of <code>n</code> for which <code>n!</code> <
 * Double.MAX_VALUE</code> is 170. If the computed value exceeds
 * Double.MAX_VALUE, Double.POSITIVE_INFINITY is returned</li>
 * </ul>
 * </p>
 * 
 * @param n argument
 * @return <code>n!</code>
 * @throws IllegalArgumentException if n < 0
 */
public static double factorialDouble(final int n) {
    if (n < 0) {
        throw new IllegalArgumentException("must have n >= 0 for n!");
    }
    return Math.floor(Math.exp(factorialLog(n)) + 0.5);
}

From source file:hivemall.utils.MathUtils.java

public static double sigmoid(double x) {
    return 1.d / (1.d + Math.exp(-x));
}

From source file:edu.tum.cs.vis.model.util.HandleComparator.java

/**
 * Get weight for area coverage based on sigmoid function. Area coverage should be bigger than
 * 0.5 (= 50%)// ww  w.  j a v a2  s  .c  om
 * 
 * @param coverage
 *            area coverage to calculate weight for
 * @return weight for provided area coverage
 */
private static double getAreaCoverageWeight(float coverage) {
    // calculates sigmoid: 1/(1+e^(-(x-0.5)*20))
    return 1 / (1 + Math.exp(-(Math.min(coverage, 1) - 0.5) * 20)) * WEIGHT_COVERAGE;
}

From source file:Main.java

/**
 * Returns a <code>double</code> representation of the <a
 * href="http://mathworld.wolfram.com/BinomialCoefficient.html"> Binomial
 * Coefficient</a>, "<code>n choose k</code>", the number of
 * <code>k</code>-element subsets that can be selected from an
 * <code>n</code>-element set.
 * <p>//ww w. j a v  a 2 s .  c o m
 * <Strong>Preconditions</strong>:
 * <ul>
 * <li> <code>0 <= k <= n </code> (otherwise
 * <code>IllegalArgumentException</code> is thrown)</li>
 * <li> The result is small enough to fit into a <code>double</code>. The
 * largest value of <code>n</code> for which all coefficients are <
 * Double.MAX_VALUE is 1029. If the computed value exceeds Double.MAX_VALUE,
 * Double.POSITIVE_INFINITY is returned</li>
 * </ul></p>
 * 
 * @param n the size of the set
 * @param k the size of the subsets to be counted
 * @return <code>n choose k</code>
 * @throws IllegalArgumentException if preconditions are not met.
 */
public static double binomialCoefficientDouble(final int n, final int k) {
    return Math.floor(Math.exp(binomialCoefficientLog(n, k)) + 0.5);
}

From source file:com.opengamma.analytics.math.function.special.GammaFunction.java

@Override
public Double evaluate(final Double x) {
    if (x > 0.0) {
        return Math.exp(Gamma.logGamma(x));
    }/*w ww. j av  a  2  s.  c  o m*/
    return Math.PI / Math.sin(Math.PI * x) / evaluate(1 - x);
}

From source file:com.opengamma.strata.math.impl.function.special.GammaFunction.java

@Override
public double applyAsDouble(double x) {
    if (x > 0.0) {
        return Math.exp(Gamma.logGamma(x));
    }/*from  w w  w.j a v  a 2 s  .  c  o m*/
    return Math.PI / Math.sin(Math.PI * x) / applyAsDouble(1 - x);
}

From source file:Main.java

/**
 * Applies a gaussian blur of the given radius to the given {@link BufferedImage} using a kernel
 * convolution.//  www .  j  a  v a  2s  .  co m
 *
 * @param source The source image.
 * @param radius The blur radius, in pixels.
 * @return A new, blurred image, or the source image if no blur is performed.
 */
public static BufferedImage blurredImage(BufferedImage source, double radius) {
    if (radius == 0) {
        return source;
    }

    final int r = (int) Math.ceil(radius);
    final int rows = r * 2 + 1;
    final float[] kernelData = new float[rows * rows];

    final double sigma = radius / 3;
    final double sigma22 = 2 * sigma * sigma;
    final double sqrtPiSigma22 = Math.sqrt(Math.PI * sigma22);
    final double radius2 = radius * radius;

    double total = 0;
    int index = 0;
    double distance2;

    int x, y;
    for (y = -r; y <= r; y++) {
        for (x = -r; x <= r; x++) {
            distance2 = 1.0 * x * x + 1.0 * y * y;
            if (distance2 > radius2) {
                kernelData[index] = 0;
            } else {
                kernelData[index] = (float) (Math.exp(-distance2 / sigma22) / sqrtPiSigma22);
            }
            total += kernelData[index];
            ++index;
        }
    }

    for (index = 0; index < kernelData.length; index++) {
        kernelData[index] /= total;
    }

    // We first pad the image so the kernel can operate at the edges.
    BufferedImage paddedSource = paddedImage(source, r);
    BufferedImage blurredPaddedImage = operatedImage(paddedSource,
            new ConvolveOp(new Kernel(rows, rows, kernelData), ConvolveOp.EDGE_ZERO_FILL, null));
    return blurredPaddedImage.getSubimage(r, r, source.getWidth(), source.getHeight());
}

From source file:geogebra.util.MyMath.java

final public static double coth(double a) {
    double e = Math.exp(2.0 * a);
    return (e + 1.0) / (e - 1.0);
}

From source file:Randoms.java

/** Return random integer from Poission with parameter lambda.  
 * The mean of this distribution is lambda.  The variance is lambda. */
public synchronized int nextPoisson(double lambda) {
    int i, j, v = -1;
    double l = Math.exp(-lambda), p;
    p = 1.0;/*  w w  w. j  av a  2s . c  o  m*/
    while (p >= l) {
        p *= nextUniform();
        v++;
    }
    return v;
}

From source file:com.opengamma.analytics.financial.interestrate.PeriodicInterestRate.java

@Override
public InterestRate fromContinuous(final ContinuousInterestRate continuous) {
    Validate.notNull(continuous, "continuous");
    final int m = getCompoundingPeriodsPerYear();
    return new PeriodicInterestRate(m * (Math.exp(continuous.getRate() / m) - 1), m);
}