Example usage for org.apache.commons.math3.distribution PoissonDistribution probability

List of usage examples for org.apache.commons.math3.distribution PoissonDistribution probability

Introduction

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

Prototype

public double probability(int x) 

Source Link

Usage

From source file:me.datamining.cluster.STING.java

/**
 * /*from  w  w w .  ja v  a2 s  . co  m*/
 * @param value
 * @param lambda
 * @return
 */
public static double pissonPDF(double value, double lambda) {
    if (lambda == 0) {
        return 0;
    }
    PoissonDistribution pdf = new PoissonDistribution(lambda);
    //TODO: fix needs to take in double
    return pdf.probability((int) value);
}

From source file:com.github.rinde.rinsim.scenario.generator.PoissonProcessTest.java

/**
 * Checks whether the observations conform to a Poisson process with the
 * specified intensity. Uses a chi square test with the specified confidence.
 * The null hypothesis is that the observations are the result of a poisson
 * process.//  ww  w. ja v  a2s.  c o m
 * @param observations
 * @param intensity
 * @param confidence
 * @return <code>true</code> if the observations
 */
static boolean isPoissonProcess(Frequency observations, double intensity, double length, double confidence) {
    final PoissonDistribution pd = new PoissonDistribution(length * intensity);

    final Iterator<?> it = observations.valuesIterator();
    final long[] observed = new long[observations.getUniqueCount()];
    final double[] expected = new double[observations.getUniqueCount()];

    int index = 0;
    while (it.hasNext()) {
        final Long l = (Long) it.next();
        observed[index] = observations.getCount(l);
        expected[index] = pd.probability(l.intValue()) * observations.getSumFreq();
        if (expected[index] == 0) {
            return false;
        }
        index++;
    }
    final double chi = TestUtils.chiSquareTest(expected, observed);
    return !(chi < confidence);
}

From source file:org.deidentifier.arx.criteria.KMap.java

/**
 * Calculates k, based on Zero-truncated Poisson distribution.
 * https://en.wikipedia.org/wiki/Zero-truncated_Poisson_distribution
 * //from  w w  w  . j av  a2  s .  com
 * @param lambda
 * @return
 */
private int calculateKZeroPoisson(double lambda) {

    final double threshold = 1d - this.significanceLevel;
    final PoissonDistribution distribution = new PoissonDistribution(lambda);
    final double v2 = 1d - distribution.probability(0);
    int counter = 1;
    double value = 0d;
    while (value < threshold) {
        // value2 += ((Math.pow(lambda, counter)) / (Math.exp(lambda) - 1)) * ArithmeticUtils.factorial(counter);
        value += distribution.probability(counter) / v2;
        counter++;
        // Break if the estimated k is equal or greater than the given k, as this makes no sense.
        if (counter >= this.k) {
            // We are 100% sure that the dataset fulfills k-map
            value = 1d;
            break;
        }
    }
    this.type1Error = 1d - value;
    return counter;
}