Example usage for org.apache.commons.math3.distribution NormalDistribution NormalDistribution

List of usage examples for org.apache.commons.math3.distribution NormalDistribution NormalDistribution

Introduction

In this page you can find the example usage for org.apache.commons.math3.distribution NormalDistribution NormalDistribution.

Prototype

public NormalDistribution(double mean, double sd) throws NotStrictlyPositiveException 

Source Link

Document

Create a normal distribution using the given mean and standard deviation.

Usage

From source file:org.apache.spark.ml.stat.JavaKolmogorovSmirnovTestSuite.java

@Test
public void testKSTestCDF() {
    // Create theoretical distributions
    NormalDistribution stdNormalDist = new NormalDistribution(0, 1);

    // set seeds/* ww  w .  j  a v a2  s.co  m*/
    Long seed = 10L;
    stdNormalDist.reseedRandomGenerator(seed);
    Function<Double, Double> stdNormalCDF = (x) -> stdNormalDist.cumulativeProbability(x);

    double pThreshold = 0.05;

    // Comparing a standard normal sample to a standard normal distribution
    Row results = KolmogorovSmirnovTest.test(dataset, "sample", stdNormalCDF).head();
    double pValue1 = results.getDouble(0);
    // Cannot reject null hypothesis
    assert (pValue1 > pThreshold);
}

From source file:org.asoem.greyfish.utils.math.statistics.DefaultShapiroWilkTest.java

/**
 * Calculate significance level for W//from w w w.jav  a  2s .c  om
 */
private static double significance(final double w, final int n) {

    if (n == EXACT_P_SAMPLE_SIZE) { /* exact P value */
        double pw = PI_6 * (asin(sqrt(w)) - STQR);
        if (pw < 0.0) {
            pw = 0.0;
        }
        return pw;
    }

    double y = log(1 - w);
    final double an = (double) n;
    final double mean;
    final double sd;

    if (n <= LOWER_APPROXIMATION_MAX_SAMPLE_SIZE) {
        final double gamma = POLYNOMIAL_FUNCTION_GAMMA.value(an);
        if (y >= gamma) {
            return CLOSE_TO_0; /* an "obvious" value, was 'SMALL' which was 1e-19f */
        }
        y = -log(gamma - y);
        mean = POLYNOMIAL_FUNCTION_3.value(an);
        sd = exp(POLYNOMIAL_FUNCTION_4.value(an));
    } else { /* n >= 12 */
        final double x = log(an);
        mean = POLYNOMIAL_FUNCTION_5.value(x);
        sd = exp(POLYNOMIAL_FUNCTION_6.value(x));
    }

    return new NormalDistribution(mean, sd).probability(y, Double.POSITIVE_INFINITY);
}

From source file:org.briljantframework.data.dataseries.SymbolicAggregator.java

private static DoubleArray calculateThresholds(Vector alphabet) {
    double prob = 1.0 / alphabet.size();
    int length = alphabet.size() - 1;
    RealDistribution distribution = new NormalDistribution(0, 1);
    DoubleArray array = Arrays.linspace(prob, 1.0 - prob, length);
    array.map(distribution::inverseCumulativeProbability);
    return array;
}

From source file:org.deeplearning4j.arbiter.optimize.parameter.TestParameterSpaces.java

@Test
public void testContinuousParameterSpace() {

    ContinuousParameterSpace cps = new ContinuousParameterSpace(0, 1);
    cps.setIndices(0);/*  w  ww. j av a 2  s  .co m*/

    for (int i = 0; i < 10; i++) {
        double d = i / 10.0;
        assertEquals(d, cps.getValue(new double[] { d }), 0.0);
    }

    cps = new ContinuousParameterSpace(10, 20);
    cps.setIndices(0);

    for (int i = 0; i < 10; i++) {
        double d = i / 10.0;
        double exp = d * 10 + 10;
        assertEquals(exp, cps.getValue(new double[] { d }), 0.0);
    }

    cps = new ContinuousParameterSpace(new NormalDistribution(0, 1));
    NormalDistribution nd = new NormalDistribution(0, 1);
    cps.setIndices(0);
    for (int i = 0; i < 11; i++) {
        double d = i / 10.0;
        assertEquals(nd.inverseCumulativeProbability(d), cps.getValue(new double[] { d }), 1e-4);
    }
}

From source file:org.drugis.addis.entities.relativeeffect.GaussianBase.java

public GaussianBase(double mu, double sigma) {
    if (Double.isNaN(mu))
        throw new IllegalArgumentException("mu may not be NaN");
    if (Double.isNaN(sigma))
        throw new IllegalArgumentException("sigma may not be NaN");
    if (sigma < 0.0)
        throw new IllegalArgumentException("sigma must be >= 0.0");
    d_mu = mu;//ww  w  .ja va  2 s  . com
    d_sigma = sigma;
    if (getSigma() != 0.0) {
        d_dist = new NormalDistribution(d_mu, d_sigma);
    }
}

From source file:org.drugis.addis.presentation.ContinuousMeasurementPresentation.java

public String normConfIntervalString() {
    DecimalFormat df = new DecimalFormat("###0.00");
    NormalDistribution distribution = new NormalDistribution(getBean().getMean(), getBean().getStdDev());
    Interval<Double> confInterval;
    confInterval = new Interval<Double>(distribution.inverseCumulativeProbability(0.025),
            distribution.inverseCumulativeProbability(0.975));

    return df.format(getBean().getMean()) + " (" + df.format(confInterval.getLowerBound()) + ", "
            + df.format(confInterval.getUpperBound()) + ")";
}

From source file:org.easotope.shared.math.QQPlot.java

public ArrayList<Point> getPoints() {
    if (needsRecalculation) {
        Statistics statistics = new Statistics();

        for (Point point : points) {
            statistics.addNumber(point.getSampleQuantile());
        }//  ww w . j  a  v  a  2  s  . co  m

        NormalDistribution distribution = new NormalDistribution(statistics.getMean(),
                statistics.getStandardDeviationSample());

        Collections.sort(points);

        int i = 1;
        for (Point point : points) {
            double percentile = (double) i / ((double) points.size() + 1.0d);
            point.setTheoreticalQuantile(distribution.inverseCumulativeProbability(percentile));
            i++;
        }
    }

    return points;
}

From source file:org.gitools.analysis.stats.test.MannWhitneyWilcoxonTest.java

private double calculateOneTailPValue(final double Umin, final int n1, final int n2)
        throws ConvergenceException, MaxCountExceededException {

    /* long multiplication to avoid overflow (double not used due to efficiency
     * and to avoid precision loss)//from  w ww.  j a v  a  2 s .  com
     */
    final long n1n2prod = (long) n1 * n2;

    // http://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U#Normal_approximation
    final double EU = n1n2prod / 2.0;
    final double VarU = n1n2prod * (n1 + n2 + 1) / 12.0;

    final double z = (Umin - EU) / FastMath.sqrt(VarU);

    // No try-catch or advertised exception because args are valid
    final NormalDistribution standardNormal = new NormalDistribution(0, 1);

    return standardNormal.cumulativeProbability(z);
}

From source file:org.hawkular.datamining.forecast.PredictionIntervalMultipliers.java

public static double multiplier(int percentage) {
    if (percentage < 0 || percentage > 100) {
        throw new IllegalArgumentException();
    }//from w w w  .j a va 2  s .  c om

    Double multiplier = cashedMultipliers.get(percentage);
    if (multiplier == null) {
        NormalDistribution normalDistribution = new NormalDistribution(0, 1);
        multiplier = normalDistribution.inverseCumulativeProbability(0.5 + (percentage * 0.01) / 2);
        cashedMultipliers.put(percentage, multiplier);
    }

    return multiplier;
}

From source file:org.jpmml.evaluator.DistributionUtil.java

static public double probability(GaussianDistribution gaussianDistribution, Number x) {
    NormalDistribution distribution = new NormalDistribution(gaussianDistribution.getMean(),
            Math.sqrt(gaussianDistribution.getVariance()));

    return distribution.density(x.doubleValue());
}