Example usage for org.apache.commons.math3.distribution CustomGammaDistribution sample

List of usage examples for org.apache.commons.math3.distribution CustomGammaDistribution sample

Introduction

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

Prototype

@Override
public double sample() 

Source Link

Document

This implementation uses the following algorithms:

For 0 < shape < 1:
Ahrens, J.

Usage

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

/**
 * Randomly generate a histogram from poisson-gamma-gaussian samples
 * /* ww w. j  a  v a2 s.  com*/
 * @return The histogram
 */
private int[] simulateFromPoissonGammaGaussian() {
    // Randomly sample
    RandomGenerator random = new Well44497b(System.currentTimeMillis() + System.identityHashCode(this));

    PoissonDistribution poisson = new PoissonDistribution(random, _photons, PoissonDistribution.DEFAULT_EPSILON,
            PoissonDistribution.DEFAULT_MAX_ITERATIONS);

    CustomGammaDistribution gamma = new CustomGammaDistribution(random, _photons, _gain,
            GammaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);

    final int steps = simulationSize;
    int[] sample = new int[steps];
    for (int n = 0; n < steps; n++) {
        if (n % 64 == 0)
            IJ.showProgress(n, steps);

        // Poisson
        double d = poisson.sample();

        // Gamma
        if (d > 0) {
            gamma.setShapeUnsafe(d);
            d = gamma.sample();
        }

        // Gaussian
        d += _noise * random.nextGaussian();

        // Convert the sample to a count 
        sample[n] = (int) Math.round(d + _bias);
    }

    int max = Maths.max(sample);
    int[] h = new int[max + 1];
    for (int s : sample)
        h[s]++;
    return h;
}