use of uk.ac.sussex.gdsc.smlm.math3.distribution.PoissonDistribution in project systemml by apache.
the class PoissonPRNGenerator method setup.
public void setup(double mean, long sd) {
seed = sd;
SynchronizedRandomGenerator srg = new SynchronizedRandomGenerator(new Well1024a());
srg.setSeed(seed);
_pdist = new PoissonDistribution(srg, _mean, PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS);
}
use of uk.ac.sussex.gdsc.smlm.math3.distribution.PoissonDistribution in project presto by prestodb.
the class MathFunctions method poissonCdf.
@Description("Poisson cdf given the lambda (mean) parameter and value")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double poissonCdf(@SqlType(StandardTypes.DOUBLE) double lambda, @SqlType(StandardTypes.INTEGER) long value) {
checkCondition(value >= 0, INVALID_FUNCTION_ARGUMENT, "value must be a non-negative integer");
checkCondition(lambda > 0, INVALID_FUNCTION_ARGUMENT, "lambda must be greater than 0");
PoissonDistribution distribution = new PoissonDistribution(lambda);
return distribution.cumulativeProbability((int) value);
}
use of uk.ac.sussex.gdsc.smlm.math3.distribution.PoissonDistribution in project presto by prestodb.
the class TestTDigestFunctions method testPoissonDistribution.
@Test(enabled = false)
public void testPoissonDistribution() {
int trials = 10;
for (int k = 1; k < trials; k++) {
TDigest tDigest = createTDigest(STANDARD_COMPRESSION_FACTOR);
PoissonDistribution poisson = new PoissonDistribution(k * 0.1);
List<Integer> list = new ArrayList<>();
for (int i = 0; i < NUMBER_OF_ENTRIES; i++) {
int sample = poisson.sample();
tDigest.add(sample);
list.add(sample);
}
Collections.sort(list);
for (int i = 0; i < quantiles.length; i++) {
assertDiscreteQuantileWithinBound(quantiles[i], STANDARD_ERROR, list, tDigest);
}
}
}
use of uk.ac.sussex.gdsc.smlm.math3.distribution.PoissonDistribution in project GDSC-SMLM by aherbert.
the class PoissonCalculatorTest method cumulativeProbabilityIsOneWithRealDataForCountAbove4.
private static void cumulativeProbabilityIsOneWithRealDataForCountAbove4(int function) {
for (final double mu : photons) {
// Determine upper limit for a Poisson
final double max = new PoissonDistribution(mu).inverseCumulativeProbability(P_LIMIT);
// Determine lower limit
final double sd = Math.sqrt(mu);
final double min = (int) Math.max(0, mu - 4 * sd);
PoissonFunction fun;
switch(function) {
case 2:
fun = new PoissonFunction(mu) {
@Override
double likelihood(double mu, double x) {
return PoissonCalculator.fastLikelihood(mu, x, FastLogFactory.getFastLog());
}
};
break;
case 1:
fun = new PoissonFunction(mu) {
@Override
double likelihood(double mu, double x) {
return PoissonCalculator.fastLikelihood(mu, x);
}
};
break;
case 0:
fun = new PoissonFunction(mu) {
@Override
double likelihood(double mu, double x) {
return PoissonCalculator.likelihood(mu, x);
}
};
break;
default:
throw new IllegalStateException();
}
cumulativeProbabilityIsOneWithRealData(min, max, mu >= 4, fun);
}
}
use of uk.ac.sussex.gdsc.smlm.math3.distribution.PoissonDistribution in project GDSC-SMLM by aherbert.
the class PoissonCalculatorTest method canComputeFastLog_FastLikelihoodForIntegerData.
@Test
void canComputeFastLog_FastLikelihoodForIntegerData() {
final DoubleDoubleBiPredicate predicate = TestHelper.doublesAreClose(1e-4, 0);
final FastLog fastLog = FastLogFactory.getFastLog();
for (final double u : photons) {
final PoissonDistribution pd = new PoissonDistribution(u);
for (int x = 0; x < 100; x++) {
double expected = pd.probability(x);
double observed = PoissonCalculator.fastLikelihood(u, x, fastLog);
if (expected > 1e-100) {
TestAssertions.assertTest(expected, observed, predicate);
}
expected = pd.logProbability(x);
observed = PoissonCalculator.fastLogLikelihood(u, x, fastLog);
TestAssertions.assertTest(expected, observed, predicate);
}
}
}
Aggregations