/** * Create a new Poisson distribution with the given the mean. The mean value * must be positive; otherwise an <code>IllegalArgument</code> is thrown. * * @param p the Poisson mean * @throws IllegalArgumentException if p ≤ 0 */ public PoissonDistributionImpl(double p) { this(p, new NormalDistributionImpl()); }
/** * Access the initial domain value, based on <code>p</code>, used to * bracket a CDF root. This method is used by * {@link #inverseCumulativeProbability(double)} to find critical values. * * @param p the desired probability for the critical value * @return initial domain value */ protected double getInitialDomain(double p) { double ret; if (p < .5) { ret = getMean() - getStandardDeviation(); } else if (p > .5) { ret = getMean() + getStandardDeviation(); } else { ret = getMean(); } return ret; } }
/** * Create a normal distribution using the given mean, standard deviation and * inverse cumulative distribution accuracy. * * @param mean mean for this distribution * @param sd standard deviation for this distribution * @param inverseCumAccuracy inverse cumulative probability accuracy * @since 2.1 */ public NormalDistributionImpl(double mean, double sd, double inverseCumAccuracy) { super(); setMeanInternal(mean); setStandardDeviationInternal(sd); solverAbsoluteAccuracy = inverseCumAccuracy; }
public synchronized Double computePhiMeasure(long now) { if (latestHeartbeatMs == -1 || descriptiveStatistics.getN() < minimumSamples) { return null; } long delta = now - latestHeartbeatMs; try { double probability; if (distribution.equals("normal")) { double standardDeviation = descriptiveStatistics.getStandardDeviation(); standardDeviation = standardDeviation < 0.1 ? 0.1 : standardDeviation; probability = new NormalDistributionImpl(descriptiveStatistics.getMean(), standardDeviation).cumulativeProbability(delta); } else { probability = new ExponentialDistributionImpl(descriptiveStatistics.getMean()).cumulativeProbability(delta); } final double eps = 1e-12; if (1 - probability < eps) { probability = 1.0; } return -1.0d * Math.log10(1.0d - probability); } catch (MathException | IllegalArgumentException e) { LOGGER.debug(e); return null; } } }
/** * Modify the standard deviation. * @param sd standard deviation for this distribution * @throws IllegalArgumentException if <code>sd</code> is not positive. * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setStandardDeviation(double sd) { setStandardDeviationInternal(sd); } /**
/** * Modify the mean. * @param mean for this distribution * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setMean(double mean) { setMeanInternal(mean); }
/** * Return the probability density for a particular point. * * @param x The point at which the density should be computed. * @return The pdf at point x. * @deprecated */ public double density(Double x) { return density(x.doubleValue()); }
/** * Returns the variance. * * For standard deviation parameter <code>s</code>, * the variance is <code>s^2</code> * * @return the variance * @since 2.2 */ public double getNumericalVariance() { final double s = getStandardDeviation(); return s * s; } }
/** * Modify the standard deviation. * @param sd standard deviation for this distribution * @throws IllegalArgumentException if <code>sd</code> is not positive. * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setStandardDeviation(double sd) { setStandardDeviationInternal(sd); }
/** * Modify the mean. * @param mean for this distribution * @deprecated as of 2.1 (class will become immutable in 3.0) */ @Deprecated public void setMean(double mean) { setMeanInternal(mean); } /**
/** * Return the probability density for a particular point. * * @param x The point at which the density should be computed. * @return The pdf at point x. * @deprecated */ @Deprecated public double density(Double x) { return density(x.doubleValue()); }
/** * Create a new Poisson distribution with the given the mean. The mean value * must be positive; otherwise an <code>IllegalArgument</code> is thrown. * * @param p the Poisson mean * @throws IllegalArgumentException if p ≤ 0 */ public PoissonDistributionImpl(double p) { this(p, new NormalDistributionImpl()); }
/** * Create a normal distribution using the given mean, standard deviation and * inverse cumulative distribution accuracy. * * @param mean mean for this distribution * @param sd standard deviation for this distribution * @param inverseCumAccuracy inverse cumulative probability accuracy * @since 2.1 */ public NormalDistributionImpl(double mean, double sd, double inverseCumAccuracy) { super(); setMeanInternal(mean); setStandardDeviationInternal(sd); solverAbsoluteAccuracy = inverseCumAccuracy; }
/** * Create a new normal distribution with the mean zero and standard * deviation one. * * @return a new normal distribution */ public NormalDistribution createNormalDistribution() { return new NormalDistributionImpl(); }
/** * Create a new Poisson distribution with the given the mean. * The mean value must be positive; otherwise an * <code>IllegalArgument</code> is thrown. * * @param p the Poisson mean * @throws IllegalArgumentException if p ≤ 0 */ public PoissonDistributionImpl(double p) { this(p, new NormalDistributionImpl()); }
/** * Create a new normal distribution with the given mean and standard * deviation. * * @param mean the mean of the distribution * @param sd standard deviation * @return a new normal distribution */ public NormalDistribution createNormalDistribution(double mean, double sd) { return new NormalDistributionImpl(mean, sd); }
import org.apache.commons.math.MathException; import org.apache.commons.math.distribution.NormalDistribution; import org.apache.commons.math.distribution.NormalDistributionImpl; /** * @see http://stattrek.com/Tables/Normal.aspx#examples * @see http://stackoverflow.com/questions/6353678 */ public class CumulativeProbability { private static NormalDistribution d; public static void main(String[] args) throws MathException { // Problem 1; µ = 1000; σ = 100 d = new NormalDistributionImpl(1000, 100); System.out.println(d.cumulativeProbability(1200)); // Problem 2; µ = 50; σ = 10 d = new NormalDistributionImpl(50, 10); System.out.println(d.inverseCumulativeProbability(0.9)); } }
/** * Computes the significance of the difference between two correlations. * @see org.tud.sir.util.statistics.Significance.testCorrelations */ public static double getSignificance(double correlation1, double correlation2, int n1, int n2) throws MathException { // transform to Fisher Z-values double zv1 = getZValue(correlation1); double zv2 = getZValue(correlation2); // difference of the Z-values double zDifference = (zv1 - zv2) / Math.sqrt( (double)1/(n1-3) + (double)1/(n2-3)); // get p value from the normal distribution NormalDistribution normal = new NormalDistributionImpl(); double p = 2 * (1 - normal.cumulativeProbability( Math.abs(zDifference))); return p; }