Example usage for org.apache.commons.math3.random RandomDataGenerator nextPoisson

List of usage examples for org.apache.commons.math3.random RandomDataGenerator nextPoisson

Introduction

In this page you can find the example usage for org.apache.commons.math3.random RandomDataGenerator nextPoisson.

Prototype

public long nextPoisson(double mean) throws NotStrictlyPositiveException 

Source Link

Document

<p> <strong>Algorithm Description</strong>: <ul><li> For small means, uses simulation of a Poisson process using Uniform deviates, as described <a href="http://irmi.epfl.ch/cmos/Pmmi/interactive/rng7.htm"> here.</a> The Poisson process (and hence value returned) is bounded by 1000 * mean.</li> <li> For large means, uses the rejection algorithm described in <br/> Devroye, Luc.

Usage

From source file:gdsc.smlm.model.StandardFluorophoreSequenceModel.java

/**
 * Get the number of blinks using the specified random data generator using a Poisson or Geometric distribution.
 * @param useGeometricBlinkingDistribution
 * @param rand//w  w w . jav a 2s. c  o m
 * @param mean
 * @return The number of blinks
 */
public static int getBlinks(boolean useGeometricBlinkingDistribution, RandomDataGenerator rand, double mean) {
    if (mean > 0) {
        return (useGeometricBlinkingDistribution) ? nextGeometric(rand, mean) : (int) rand.nextPoisson(mean);
    }
    return 0;
}

From source file:gdsc.smlm.ij.plugins.CreateData.java

private float[] createBackground(RandomDataGenerator random) {
    float[] pixels2 = null;

    if (settings.background > 0) {
        if (random == null)
            random = new RandomDataGenerator();
        createBackgroundPixels();/*  w ww  .j  a va  2  s  .  c o m*/
        pixels2 = Arrays.copyOf(backgroundPixels, backgroundPixels.length);

        // Add Poisson noise.
        if (uniformBackground) {
            // We can do N random samples thus ensuring the background average is constant.
            // Note: The number of samples must be Poisson distributed.
            final int samples = (int) random.nextPoisson(pixels2[0] * pixels2.length);

            // Only do sampling if the number of samples is valid
            if (samples >= 1) {
                pixels2 = new float[pixels2.length];
                final int upper = pixels2.length - 1;
                for (int i = 0; i < samples; i++) {
                    pixels2[random.nextInt(0, upper)] += 1;
                }
            } else {
                // If using a uniform illumination then we can use a fixed Poisson distribution
                PoissonDistribution dist = new PoissonDistribution(random.getRandomGenerator(), pixels2[0],
                        PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS);
                for (int i = 0; i < pixels2.length; i++) {
                    pixels2[i] = dist.sample();
                }
            }
        } else {
            for (int i = 0; i < pixels2.length; i++) {
                pixels2[i] = random.nextPoisson(pixels2[i]);
            }
        }
    } else {
        pixels2 = new float[settings.size * settings.size];
    }

    return pixels2;
}

From source file:org.meteoinfo.math.RandomUtil.java

/**
 * Get random data from a Poisson distribution
 * @param mean Poisson mean//from   w  w w .j a  v a2s  .  co m
 * @return Random value
 */
public static double poisson(double mean) {
    RandomDataGenerator rdg = new RandomDataGenerator();
    return rdg.nextPoisson(mean);
}

From source file:org.meteoinfo.math.RandomUtil.java

/**
 * Get random data from a Poisson distribution
 *
 * @param mean Poisson mean/*from w w w  . java  2  s.co  m*/
 * @param n Array length
 * @return Array Result array
 */
public static Array poisson(double mean, int n) {
    Array a = Array.factory(DataType.INT, new int[] { n });
    RandomDataGenerator rd = new RandomDataGenerator();
    for (int i = 0; i < a.getSize(); i++) {
        a.setDouble(i, rd.nextPoisson(mean));
    }

    return a;
}

From source file:org.meteoinfo.math.RandomUtil.java

/**
 * Get random data from a Poisson distribution
 *
 * @param mean Poisson mean//from   ww w .  j a  va 2 s  . c om
 * @param shape Shape
 * @return Array Result array
 */
public static Array poisson(double mean, List<Integer> shape) {
    int[] ashape = new int[shape.size()];
    for (int i = 0; i < shape.size(); i++) {
        ashape[i] = shape.get(i);
    }
    Array a = Array.factory(DataType.INT, ashape);
    RandomDataGenerator rd = new RandomDataGenerator();
    for (int i = 0; i < a.getSize(); i++) {
        a.setDouble(i, rd.nextPoisson(mean));
    }

    return a;
}