use of org.apache.commons.rng.sampling.distribution.InverseTransformDiscreteSampler in project GDSC-SMLM by aherbert.
the class BinomialFitterTest method createData.
private static int[] createData(UniformRandomProvider rg, int n, double p, boolean zeroTruncated) {
final BinomialDistribution bd = new BinomialDistribution(null, n, p);
final DiscreteSampler sampler = new InverseTransformDiscreteSampler(rg, pvalue -> bd.inverseCumulativeProbability(pvalue));
final int[] data = new int[2000];
if (zeroTruncated) {
if (p <= 0) {
throw new RuntimeException("p must be positive");
}
for (int i = 0; i < data.length; i++) {
int count;
do {
count = sampler.sample();
} while (count == 0);
data[i] = count;
}
} else {
for (int i = 0; i < data.length; i++) {
data[i] = sampler.sample();
}
}
return data;
}
Aggregations