Search in sources :

Example 91 with SeededTest

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

Example 92 with SeededTest

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

Example 93 with SeededTest

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

Example 94 with SeededTest

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

Example 95 with SeededTest

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

Aggregations

SeededTest (uk.ac.sussex.gdsc.test.junit5.SeededTest)172 UniformRandomProvider (org.apache.commons.rng.UniformRandomProvider)142 DoubleDoubleBiPredicate (uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate)18 Rectangle (java.awt.Rectangle)12 SpeedTag (uk.ac.sussex.gdsc.test.junit5.SpeedTag)12 TimingService (uk.ac.sussex.gdsc.test.utils.TimingService)12 SharedStateContinuousSampler (org.apache.commons.rng.sampling.distribution.SharedStateContinuousSampler)7 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)6 FloatProcessor (ij.process.FloatProcessor)6 ErfGaussian2DFunction (uk.ac.sussex.gdsc.smlm.function.gaussian.erf.ErfGaussian2DFunction)6 DummyGradientFunction (uk.ac.sussex.gdsc.smlm.function.DummyGradientFunction)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 Gaussian2DFunction (uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction)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 FloatFloatBiPredicate (uk.ac.sussex.gdsc.test.api.function.FloatFloatBiPredicate)4 MultivariateNormalMixtureExpectationMaximization (org.apache.commons.math3.distribution.fitting.MultivariateNormalMixtureExpectationMaximization)3 DoubleEquality (uk.ac.sussex.gdsc.core.utils.DoubleEquality)3