use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class PoissonDistributionTest method canComputeProbability.
@SeededTest
void canComputeProbability(RandomSeed seed) {
final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
final PoissonDistribution fpd = new PoissonDistribution(1);
for (int i = 1; i <= 100; i++) {
final double mean = rng.nextDouble() * i;
final org.apache.commons.math3.distribution.PoissonDistribution pd = createReferencePoissonDistribution(mean);
fpd.setMean(mean);
final int lower = (int) Math.floor(Math.max(0, mean - 5 * Math.sqrt(mean)));
final int upper = (int) Math.ceil((mean + 5 * Math.sqrt(mean)));
for (int x = lower; x <= upper; x++) {
Assertions.assertEquals(pd.probability(x), fpd.probability(x), 1e-16);
}
}
}
use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class PoissonDistributionTest method canComputeInverseCumulativeProbability.
@SeededTest
void canComputeInverseCumulativeProbability(RandomSeed seed) {
final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
final PoissonDistribution fpd = new PoissonDistribution(1);
for (int i = 1; i <= 100; i++) {
final double mean = rng.nextDouble() * i;
final org.apache.commons.math3.distribution.PoissonDistribution pd = createReferencePoissonDistribution(mean);
fpd.setMean(mean);
for (int j = 0; j <= 10; j++) {
final double p = 0.1 * j;
Assertions.assertEquals(pd.inverseCumulativeProbability(p), fpd.inverseCumulativeProbability(p), 1e-16);
}
}
}
use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class SphericalDistributionTest method canSampleWithNoRadius.
@SeededTest
void canSampleWithNoRadius(RandomSeed seed) {
final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
final double[] expected = { 0, 0, 0 };
for (final double radius : new double[] { 0.0, -0.0 }) {
final SphericalDistribution dist = new SphericalDistribution(radius, rg);
for (int i = 5; i-- > 0; ) {
final double[] x = dist.next();
Assertions.assertArrayEquals(expected, x);
}
}
}
use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class SphericalDistributionTest method canSample.
@SeededTest
void canSample(RandomSeed seed) {
final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
final double radius = 10 + rg.nextDouble() * 10;
final SphericalDistribution dist = new SphericalDistribution(radius, rg);
for (int i = 100; i-- > 0; ) {
final double[] x = dist.next();
Assertions.assertTrue(MathUtils.distance(x[0], x[1], x[2], 0, 0, 0) <= radius, () -> "Bad coords: " + Arrays.toString(x) + " radius=" + radius);
}
}
use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class DynamicMultipleTargetTracingTest method checkBuilderDefaults.
@SeededTest
void checkBuilderDefaults(RandomSeed seed) {
final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
final double diffusionCoefficientMaximum = 1 + rng.nextDouble();
final DmttConfiguration.Builder b = DmttConfiguration.newBuilder(diffusionCoefficientMaximum);
final DmttConfiguration c1 = b.build();
// Check round-trip
for (final DmttConfiguration config : new DmttConfiguration[] { c1, c1.toBuilder().build() }) {
Assertions.assertEquals(diffusionCoefficientMaximum, config.getDiffusionCoefficientMaximum());
Assertions.assertTrue(config.getTemporalWindow() > 1);
Assertions.assertTrue(config.getLocalDiffusionWeight() >= 0);
Assertions.assertTrue(config.getLocalDiffusionWeight() <= 1);
Assertions.assertTrue(config.getOnIntensityWeight() >= 0);
Assertions.assertTrue(config.getOnIntensityWeight() <= 1);
Assertions.assertTrue(config.getDisappearanceDecayFactor() > 0);
Assertions.assertTrue(config.getDisappearanceThreshold() > 0);
Assertions.assertFalse(config.isDisableIntensityModel());
Assertions.assertFalse(config.isDisableLocalDiffusionModel());
}
}
Aggregations