Java Code Examples for org.apache.commons.math3.distribution.NormalDistribution#inverseCumulativeProbability()

The following examples show how to use org.apache.commons.math3.distribution.NormalDistribution#inverseCumulativeProbability() . 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: WilsonScoreInterval.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
public ConfidenceInterval createInterval(int numberOfTrials, int numberOfSuccesses, double confidenceLevel) {
    IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
    final double alpha = (1.0 - confidenceLevel) / 2;
    final NormalDistribution normalDistribution = new NormalDistribution();
    final double z = normalDistribution.inverseCumulativeProbability(1 - alpha);
    final double zSquared = FastMath.pow(z, 2);
    final double mean = (double) numberOfSuccesses / (double) numberOfTrials;

    final double factor = 1.0 / (1 + (1.0 / numberOfTrials) * zSquared);
    final double modifiedSuccessRatio = mean + (1.0 / (2 * numberOfTrials)) * zSquared;
    final double difference = z *
                              FastMath.sqrt(1.0 / numberOfTrials * mean * (1 - mean) +
                                            (1.0 / (4 * FastMath.pow(numberOfTrials, 2)) * zSquared));

    final double lowerBound = factor * (modifiedSuccessRatio - difference);
    final double upperBound = factor * (modifiedSuccessRatio + difference);
    return new ConfidenceInterval(lowerBound, upperBound, confidenceLevel);
}
 
Example 2
Source File: WilsonScoreInterval.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
public ConfidenceInterval createInterval(int numberOfTrials, int numberOfSuccesses, double confidenceLevel) {
    IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
    final double alpha = (1.0 - confidenceLevel) / 2;
    final NormalDistribution normalDistribution = new NormalDistribution();
    final double z = normalDistribution.inverseCumulativeProbability(1 - alpha);
    final double zSquared = FastMath.pow(z, 2);
    final double mean = (double) numberOfSuccesses / (double) numberOfTrials;

    final double factor = 1.0 / (1 + (1.0 / numberOfTrials) * zSquared);
    final double modifiedSuccessRatio = mean + (1.0 / (2 * numberOfTrials)) * zSquared;
    final double difference = z *
                              FastMath.sqrt(1.0 / numberOfTrials * mean * (1 - mean) +
                                            (1.0 / (4 * FastMath.pow(numberOfTrials, 2)) * zSquared));

    final double lowerBound = factor * (modifiedSuccessRatio - difference);
    final double upperBound = factor * (modifiedSuccessRatio + difference);
    return new ConfidenceInterval(lowerBound, upperBound, confidenceLevel);
}
 
Example 3
Source File: AgrestiCoullInterval.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public ConfidenceInterval createInterval(int numberOfTrials, int numberOfSuccesses, double confidenceLevel) {
    IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
    final double alpha = (1.0 - confidenceLevel) / 2;
    final NormalDistribution normalDistribution = new NormalDistribution();
    final double z = normalDistribution.inverseCumulativeProbability(1 - alpha);
    final double zSquared = FastMath.pow(z, 2);
    final double modifiedNumberOfTrials = numberOfTrials + zSquared;
    final double modifiedSuccessesRatio = (1.0 / modifiedNumberOfTrials) * (numberOfSuccesses + 0.5 * zSquared);
    final double difference = z *
                              FastMath.sqrt(1.0 / modifiedNumberOfTrials * modifiedSuccessesRatio *
                                            (1 - modifiedSuccessesRatio));
    return new ConfidenceInterval(modifiedSuccessesRatio - difference, modifiedSuccessesRatio + difference,
                                  confidenceLevel);
}
 
Example 4
Source File: NormalApproximationInterval.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public ConfidenceInterval createInterval(int numberOfTrials, int numberOfSuccesses,
                                         double confidenceLevel) {
    IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
    final double mean = (double) numberOfSuccesses / (double) numberOfTrials;
    final double alpha = (1.0 - confidenceLevel) / 2;
    final NormalDistribution normalDistribution = new NormalDistribution();
    final double difference = normalDistribution.inverseCumulativeProbability(1 - alpha) *
                              FastMath.sqrt(1.0 / numberOfTrials * mean * (1 - mean));
    return new ConfidenceInterval(mean - difference, mean + difference, confidenceLevel);
}
 
Example 5
Source File: AgrestiCoullInterval.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public ConfidenceInterval createInterval(int numberOfTrials, int numberOfSuccesses, double confidenceLevel) {
    IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
    final double alpha = (1.0 - confidenceLevel) / 2;
    final NormalDistribution normalDistribution = new NormalDistribution();
    final double z = normalDistribution.inverseCumulativeProbability(1 - alpha);
    final double zSquared = FastMath.pow(z, 2);
    final double modifiedNumberOfTrials = numberOfTrials + zSquared;
    final double modifiedSuccessesRatio = (1.0 / modifiedNumberOfTrials) * (numberOfSuccesses + 0.5 * zSquared);
    final double difference = z *
                              FastMath.sqrt(1.0 / modifiedNumberOfTrials * modifiedSuccessesRatio *
                                            (1 - modifiedSuccessesRatio));
    return new ConfidenceInterval(modifiedSuccessesRatio - difference, modifiedSuccessesRatio + difference,
                                  confidenceLevel);
}
 
Example 6
Source File: NormalApproximationInterval.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public ConfidenceInterval createInterval(int numberOfTrials, int numberOfSuccesses,
                                         double confidenceLevel) {
    IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
    final double mean = (double) numberOfSuccesses / (double) numberOfTrials;
    final double alpha = (1.0 - confidenceLevel) / 2;
    final NormalDistribution normalDistribution = new NormalDistribution();
    final double difference = normalDistribution.inverseCumulativeProbability(1 - alpha) *
                              FastMath.sqrt(1.0 / numberOfTrials * mean * (1 - mean));
    return new ConfidenceInterval(mean - difference, mean + difference, confidenceLevel);
}
 
Example 7
Source File: WienerProcessModel.java    From Hi-WAY with Apache License 2.0 5 votes vote down vote up
public double getEstimate(double timestamp, double alpha) {
	if (alpha == 0.5 && measurements.size() > 0) {
		return logarithmize ? Math.pow(Math.E, measurements.getLast().runtime) : Math.max(measurements.getLast().runtime, Double.MIN_NORMAL);
	}
	
	if (differences.size() < 2) {
		return 0d;
	}

	Runtime lastMeasurement = measurements.getLast();

	double variance = 0d;
	double avgDifference = sumOfDifferences / differences.size();
	for (double difference : differences) {
		variance += Math.pow(difference - avgDifference, 2d);
	}
	variance /= differences.size() - 1;

	variance *= timestamp - lastMeasurement.timestamp;

	double estimate = lastMeasurement.runtime;
	if (variance > 0d) {
		NormalDistribution nd = new NormalDistribution(lastMeasurement.runtime, Math.sqrt(variance));
		estimate = nd.inverseCumulativeProbability(alpha);
	}

	estimate = logarithmize ? Math.pow(Math.E, estimate) : Math.max(estimate, 0d);

	return estimate;
}
 
Example 8
Source File: Probit.java    From Alink with Apache License 2.0 4 votes vote down vote up
/**
 *
 * @param mu: mean
 * return get eta
 */
@Override
public double link(double mu) {
    NormalDistribution distribution = new NormalDistribution();
    return distribution.inverseCumulativeProbability(mu);
}
 
Example 9
Source File: JobRuntimePredictionUtil.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
/**
 * Estimate the standard deviation of a gaussian distribution given 2 quantiles. See https://www.johndcook.com/quantiles_parameters.pdf
 */
private static double computeNormSigma() {
    NormalDistribution normal = new NormalDistribution();
    return normal.inverseCumulativeProbability(HIGH_QUANTILE) - normal.inverseCumulativeProbability(LOW_QUANTILE);
}