org.apache.commons.math3.special.Erf Java Examples

The following examples show how to use org.apache.commons.math3.special.Erf. 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: LogNormalDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double cumulativeProbability(double x0, double x1)
    throws NumberIsTooLargeException {
    if (x0 > x1) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
                                            x0, x1, true);
    }
    if (x0 <= 0 || x1 <= 0) {
        return super.cumulativeProbability(x0, x1);
    }
    final double denom = shape * SQRT2;
    final double v0 = (FastMath.log(x0) - scale) / denom;
    final double v1 = (FastMath.log(x1) - scale) / denom;
    return 0.5 * Erf.erf(v0, v1);
}
 
Example #2
Source File: LogNormalDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double probability(double x0,
                          double x1)
    throws NumberIsTooLargeException {
    if (x0 > x1) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
                                            x0, x1, true);
    }
    if (x0 <= 0 || x1 <= 0) {
        return super.probability(x0, x1);
    }
    final double denom = shape * SQRT2;
    final double v0 = (FastMath.log(x0) - scale) / denom;
    final double v1 = (FastMath.log(x1) - scale) / denom;
    return 0.5 * Erf.erf(v0, v1);
}
 
Example #3
Source File: LogNormalDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double probability(double x0,
                          double x1)
    throws NumberIsTooLargeException {
    if (x0 > x1) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
                                            x0, x1, true);
    }
    if (x0 <= 0 || x1 <= 0) {
        return super.probability(x0, x1);
    }
    final double denom = shape * SQRT2;
    final double v0 = (FastMath.log(x0) - scale) / denom;
    final double v1 = (FastMath.log(x1) - scale) / denom;
    return 0.5 * Erf.erf(v0, v1);
}
 
Example #4
Source File: LogNormalDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double probability(double x0,
                          double x1)
    throws NumberIsTooLargeException {
    if (x0 > x1) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
                                            x0, x1, true);
    }
    if (x0 <= 0 || x1 <= 0) {
        return super.probability(x0, x1);
    }
    final double denom = shape * SQRT2;
    final double v0 = (FastMath.log(x0) - scale) / denom;
    final double v1 = (FastMath.log(x1) - scale) / denom;
    return 0.5 * Erf.erf(v0, v1);
}
 
Example #5
Source File: LogNormalDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double probability(double x0,
                          double x1)
    throws NumberIsTooLargeException {
    if (x0 > x1) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
                                            x0, x1, true);
    }
    if (x0 <= 0 || x1 <= 0) {
        return super.probability(x0, x1);
    }
    final double denom = shape * SQRT2;
    final double v0 = (FastMath.log(x0) - scale) / denom;
    final double v1 = (FastMath.log(x1) - scale) / denom;
    return 0.5 * Erf.erf(v0, v1);
}
 
Example #6
Source File: LogNormalDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double cumulativeProbability(double x0, double x1)
    throws NumberIsTooLargeException {
    if (x0 > x1) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
                                            x0, x1, true);
    }
    if (x0 <= 0 || x1 <= 0) {
        return super.cumulativeProbability(x0, x1);
    }
    final double denom = shape * SQRT2;
    final double v0 = (FastMath.log(x0) - scale) / denom;
    final double v1 = (FastMath.log(x1) - scale) / denom;
    return 0.5 * Erf.erf(v0, v1);
}
 
Example #7
Source File: NormalDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc}
 * @since 3.2
 */
@Override
public double inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }
    return mean + standardDeviation * SQRT2 * Erf.erfInv(2 * p - 1);
}
 
Example #8
Source File: NormalDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * If {@code x} is more than 40 standard deviations from the mean, 0 or 1
 * is returned, as in these cases the actual value is within
 * {@code Double.MIN_VALUE} of 0 or 1.
 */
public double cumulativeProbability(double x)  {
    final double dev = x - mean;
    if (FastMath.abs(dev) > 40 * standardDeviation) {
        return dev < 0 ? 0.0d : 1.0d;
    }
    return 0.5 * (1 + Erf.erf(dev / (standardDeviation * SQRT2)));
}
 
Example #9
Source File: LogNormalDistribution.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public double probability(double x0, double x1) throws NumberIsTooLargeException {
    if (x0 > x1) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1, true);
    }
    final double denom = standardDeviation * SQRT2;
    final double v0 = (x0 - mean) / denom;
    final double v1 = (x1 - mean) / denom;
    return 0.5 * Erf.erf(v0, v1);
}
 
Example #10
Source File: LevyDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public double inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }
    final double t = Erf.erfcInv(p);
    return mu + halfC / (t * t);
}
 
Example #11
Source File: NormalDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public double probability(double x0,
                          double x1)
    throws NumberIsTooLargeException {
    if (x0 > x1) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
                                            x0, x1, true);
    }
    final double denom = standardDeviation * SQRT2;
    final double v0 = (x0 - mean) / denom;
    final double v1 = (x1 - mean) / denom;
    return 0.5 * Erf.erf(v0, v1);
}
 
Example #12
Source File: NormalDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc}
 * @since 3.2
 */
@Override
public double inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }
    return mean + standardDeviation * SQRT2 * Erf.erfInv(2 * p - 1);
}
 
Example #13
Source File: NormalDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * If {@code x} is more than 40 standard deviations from the mean, 0 or 1
 * is returned, as in these cases the actual value is within
 * {@code Double.MIN_VALUE} of 0 or 1.
 */
public double cumulativeProbability(double x)  {
    final double dev = x - mean;
    if (FastMath.abs(dev) > 40 * standardDeviation) {
        return dev < 0 ? 0.0d : 1.0d;
    }
    return 0.5 * (1 + Erf.erf(dev / (standardDeviation * SQRT2)));
}
 
Example #14
Source File: LogNormalDistribution.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p/>
 * If {@code x} is more than 40 standard deviations from the mean, 0 or 1
 * is returned, as in these cases the actual value is within
 * {@code Double.MIN_VALUE} of 0 or 1.
 */
public double cumulativeProbability(double x) {
    if (means != null)
        throw new IllegalStateException("Unable to sample from more than one mean");
    final double dev = x - mean;
    if (FastMath.abs(dev) > 40 * standardDeviation) {
        return dev < 0 ? 0.0d : 1.0d;
    }
    return 0.5 * (1 + Erf.erf(dev / (standardDeviation * SQRT2)));
}
 
Example #15
Source File: NormalDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * If {@code x} is more than 40 standard deviations from the mean, 0 or 1
 * is returned, as in these cases the actual value is within
 * {@code Double.MIN_VALUE} of 0 or 1.
 */
public double cumulativeProbability(double x)  {
    final double dev = x - mean;
    if (FastMath.abs(dev) > 40 * standardDeviation) {
        return dev < 0 ? 0.0d : 1.0d;
    }
    return 0.5 * (1 + Erf.erf(dev / (standardDeviation * SQRT2)));
}
 
Example #16
Source File: NormalDistribution.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @since 3.2
 */
@Override
public double inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }
    if (means != null)
        throw new IllegalStateException("Unable to sample from more than one mean");

    return mean + standardDeviation * SQRT2 * Erf.erfInv(2 * p - 1);
}
 
Example #17
Source File: LevyDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public double inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }
    final double t = Erf.erfcInv(p);
    return mu + halfC / (t * t);
}
 
Example #18
Source File: NormalDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public double probability(double x0,
                          double x1)
    throws NumberIsTooLargeException {
    if (x0 > x1) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
                                            x0, x1, true);
    }
    final double denom = standardDeviation * SQRT2;
    final double v0 = (x0 - mean) / denom;
    final double v1 = (x1 - mean) / denom;
    return 0.5 * Erf.erf(v0, v1);
}
 
Example #19
Source File: LevyDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public double inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }
    final double t = Erf.erfcInv(p);
    return mu + halfC / (t * t);
}
 
Example #20
Source File: NormalDistribution.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p/>
 * If {@code x} is more than 40 standard deviations from the mean, 0 or 1
 * is returned, as in these cases the actual value is within
 * {@code Double.MIN_VALUE} of 0 or 1.
 */
public double cumulativeProbability(double x) {
    if (means != null)
        throw new IllegalStateException("Unable to sample from more than one mean");
    final double dev = x - mean;
    if (FastMath.abs(dev) > 40 * standardDeviation) {
        return dev < 0 ? 0.0d : 1.0d;
    }
    return 0.5 * (1 + Erf.erf(dev / (standardDeviation * SQRT2)));
}
 
Example #21
Source File: LevyDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public double inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }
    final double t = Erf.erfcInv(p);
    return mu + halfC / (t * t);
}
 
Example #22
Source File: NormalDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public double cumulativeProbability(double x0, double x1)
    throws NumberIsTooLargeException {
    if (x0 > x1) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
                                            x0, x1, true);
    }
    final double denom = standardDeviation * SQRT2;
    final double v0 = (x0 - mean) / denom;
    final double v1 = (x1 - mean) / denom;
    return 0.5 * Erf.erf(v0, v1);
}
 
Example #23
Source File: NormalDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * If {@code x} is more than 40 standard deviations from the mean, 0 or 1
 * is returned, as in these cases the actual value is within
 * {@code Double.MIN_VALUE} of 0 or 1.
 */
public double cumulativeProbability(double x)  {
    final double dev = x - mean;
    if (FastMath.abs(dev) > 40 * standardDeviation) {
        return dev < 0 ? 0.0d : 1.0d;
    }
    return 0.5 * (1 + Erf.erf(dev / (standardDeviation * SQRT2)));
}
 
Example #24
Source File: NormalDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public double probability(double x0,
                          double x1)
    throws NumberIsTooLargeException {
    if (x0 > x1) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
                                            x0, x1, true);
    }
    final double denom = standardDeviation * SQRT2;
    final double v0 = (x0 - mean) / denom;
    final double v1 = (x1 - mean) / denom;
    return 0.5 * Erf.erf(v0, v1);
}
 
Example #25
Source File: NormalDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * If {@code x} is more than 40 standard deviations from the mean, 0 or 1
 * is returned, as in these cases the actual value is within
 * {@code Double.MIN_VALUE} of 0 or 1.
 */
public double cumulativeProbability(double x)  {
    final double dev = x - mean;
    if (FastMath.abs(dev) > 40 * standardDeviation) {
        return dev < 0 ? 0.0d : 1.0d;
    }
    return 0.5 * (1 + Erf.erf(dev / (standardDeviation * SQRT2)));
}
 
Example #26
Source File: NormalDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public double probability(double x0,
                          double x1)
    throws NumberIsTooLargeException {
    if (x0 > x1) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
                                            x0, x1, true);
    }
    final double denom = standardDeviation * SQRT2;
    final double v0 = (x0 - mean) / denom;
    final double v1 = (x1 - mean) / denom;
    return 0.5 * Erf.erf(v0, v1);
}
 
Example #27
Source File: MathFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@Description("Inverse of normal cdf given a mean, std, and probability")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double inverseNormalCdf(@SqlType(StandardTypes.DOUBLE) double mean, @SqlType(StandardTypes.DOUBLE) double sd, @SqlType(StandardTypes.DOUBLE) double p)
{
    checkCondition(p > 0 && p < 1, INVALID_FUNCTION_ARGUMENT, "p must be 0 > p > 1");
    checkCondition(sd > 0, INVALID_FUNCTION_ARGUMENT, "sd must be > 0");

    return mean + sd * 1.4142135623730951 * Erf.erfInv(2 * p - 1);
}
 
Example #28
Source File: NormalDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * If {@code x} is more than 40 standard deviations from the mean, 0 or 1
 * is returned, as in these cases the actual value is within
 * {@code Double.MIN_VALUE} of 0 or 1.
 */
public double cumulativeProbability(double x)  {
    final double dev = x - mean;
    if (FastMath.abs(dev) > 40 * standardDeviation) {
        return dev < 0 ? 0.0d : 1.0d;
    }
    return 0.5 * (1 + Erf.erf(dev / (standardDeviation * SQRT2)));
}
 
Example #29
Source File: LevyDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public double inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }
    final double t = Erf.erfcInv(p);
    return mu + halfC / (t * t);
}
 
Example #30
Source File: GaussianLowEnergySampler.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
private double radialIntegral(double a, int k){
    //\int_0^a exp(-r^2/2) r^k dr
    if(k>1)
        return (k-1)*radialIntegral(a,k-2) - Math.pow(a,k-1)*Math.exp(-a*a/2);
    else if(k==1)
        return 1-Math.exp(-a*a/2);
    else if(k==0)
        return Math.sqrt(Math.PI/2) * Erf.erf(a/Math.sqrt(2));
    else
        throw new RuntimeException("ERROR: Negative k not supported here: "+k);
}