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

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

Introduction

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

Prototype

public void setShapeUnsafe(double shape) 

Source Link

Document

Set the shape parameter

Does not throw an exception if shape is not strictly positive

Usage

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

/**
 * Randomly generate a histogram from poisson-gamma-gaussian samples
 * /*from www .j a  v  a2s.c o m*/
 * @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;
}