use of uk.ac.sussex.gdsc.test.junit5.SeededTest in project GDSC-SMLM by aherbert.
the class PeakResultTest method differentResultsAreNotEqual.
@SeededTest
void differentResultsAreNotEqual(RandomSeed seed) {
UniformRandomProvider rng;
final int size = 1;
final int n = 5;
final boolean[] both = { true, false };
for (final boolean withDeviations : both) {
for (final boolean withId : both) {
for (final boolean withCategory : both) {
for (final boolean withEndFrame : both) {
for (final boolean withPrecision : both) {
rng = RngUtils.create(seed.getSeed());
final PeakResult[] r1 = createResults(rng, size, n, withDeviations, withId, withCategory, withEndFrame, withPrecision);
final PeakResult[] r2 = createResults(rng, size, n, withDeviations, withId, withCategory, withEndFrame, withPrecision);
for (int i = 0; i < r1.length; i++) {
Assertions.assertFalse(PeakResult.equals(r1[i], r2[i]));
}
}
}
}
}
}
}
use of uk.ac.sussex.gdsc.test.junit5.SeededTest 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.SeededTest 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.SeededTest 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.SeededTest 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);
}
}
Aggregations