Search in sources :

Example 86 with RandomSeed

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);
        }
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 87 with RandomSeed

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);
        }
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 88 with RandomSeed

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);
        }
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 89 with RandomSeed

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);
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 90 with RandomSeed

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());
    }
}
Also used : DmttConfiguration(uk.ac.sussex.gdsc.smlm.results.DynamicMultipleTargetTracing.DmttConfiguration) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Aggregations

SeededTest (uk.ac.sussex.gdsc.test.junit5.SeededTest)161 UniformRandomProvider (org.apache.commons.rng.UniformRandomProvider)142 DoubleDoubleBiPredicate (uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate)17 Rectangle (java.awt.Rectangle)12 SpeedTag (uk.ac.sussex.gdsc.test.junit5.SpeedTag)12 TimingService (uk.ac.sussex.gdsc.test.utils.TimingService)11 SharedStateContinuousSampler (org.apache.commons.rng.sampling.distribution.SharedStateContinuousSampler)7 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)6 FloatProcessor (ij.process.FloatProcessor)5 SingleFreeCircularErfGaussian2DFunction (uk.ac.sussex.gdsc.smlm.function.gaussian.erf.SingleFreeCircularErfGaussian2DFunction)5 TimingResult (uk.ac.sussex.gdsc.test.utils.TimingResult)5 ArrayList (java.util.ArrayList)4 ErfGaussian2DFunction (uk.ac.sussex.gdsc.smlm.function.gaussian.erf.ErfGaussian2DFunction)4 MixtureMultivariateGaussianDistribution (uk.ac.sussex.gdsc.smlm.math3.distribution.fitting.MultivariateGaussianMixtureExpectationMaximization.MixtureMultivariateGaussianDistribution)4 MultivariateGaussianDistribution (uk.ac.sussex.gdsc.smlm.math3.distribution.fitting.MultivariateGaussianMixtureExpectationMaximization.MixtureMultivariateGaussianDistribution.MultivariateGaussianDistribution)4 DoubleConvolutionValueProcedure (uk.ac.sussex.gdsc.smlm.utils.Convolution.DoubleConvolutionValueProcedure)4 FloatFloatBiPredicate (uk.ac.sussex.gdsc.test.api.function.FloatFloatBiPredicate)4 MixtureMultivariateNormalDistribution (org.apache.commons.math3.distribution.MixtureMultivariateNormalDistribution)3 MultivariateNormalMixtureExpectationMaximization (org.apache.commons.math3.distribution.fitting.MultivariateNormalMixtureExpectationMaximization)3 DoubleEquality (uk.ac.sussex.gdsc.core.utils.DoubleEquality)3