Search in sources :

Example 71 with RandomSeed

use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.

the class Gaussian2DPeakResultHelperTest method canComputeMeanSignalUsingP.

@SeededTest
void canComputeMeanSignalUsingP(RandomSeed seed) {
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    final DoubleDoubleBiPredicate predicate = TestHelper.doublesAreClose(1e-10, 0);
    for (int i = 0; i < 10; i++) {
        final double intensity = rg.nextDouble() * 100;
        final double sx = rg.nextDouble() * 2;
        final double sy = rg.nextDouble() * 2;
        final double p = rg.nextDouble();
        double expected = intensity * p / (Math.PI * MathUtils.pow2(Gaussian2DPeakResultHelper.inverseCumulative2D(p)) * sx * sy);
        double observed = Gaussian2DPeakResultHelper.getMeanSignalUsingP(intensity, sx, sy, p);
        assertEquals(expected, observed, predicate);
        // Test fixed versions verse dynamic
        expected = Gaussian2DPeakResultHelper.getMeanSignalUsingP(intensity, sx, sy, 0.5);
        observed = Gaussian2DPeakResultHelper.getMeanSignalUsingP05(intensity, sx, sy);
        assertEquals(expected, observed, predicate);
    }
}
Also used : DoubleDoubleBiPredicate(uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 72 with RandomSeed

use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.

the class Gaussian2DPeakResultHelperTest method canComputeMeanSignalUsingR.

@SeededTest
void canComputeMeanSignalUsingR(RandomSeed seed) {
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    final DoubleDoubleBiPredicate predicate = TestHelper.doublesAreClose(1e-10, 0);
    for (int i = 0; i < 10; i++) {
        final double intensity = rg.nextDouble() * 100;
        final double sx = rg.nextDouble() * 2;
        final double sy = rg.nextDouble() * 2;
        final double r = rg.nextDouble() * 5;
        assertEquals(intensity * Gaussian2DPeakResultHelper.cumulative2D(r) / (Math.PI * r * r * sx * sy), Gaussian2DPeakResultHelper.getMeanSignalUsingR(intensity, sx, sy, r), predicate);
        // Test fixed versions verse dynamic
        assertEquals(Gaussian2DPeakResultHelper.getMeanSignalUsingR(intensity, sx, sy, 1), Gaussian2DPeakResultHelper.getMeanSignalUsingR1(intensity, sx, sy), predicate);
        assertEquals(Gaussian2DPeakResultHelper.getMeanSignalUsingR(intensity, sx, sy, 2), Gaussian2DPeakResultHelper.getMeanSignalUsingR2(intensity, sx, sy), predicate);
    }
}
Also used : DoubleDoubleBiPredicate(uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 73 with RandomSeed

use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.

the class PoissonDistributionTest method canComputeCumulativeProbability.

@SeededTest
void canComputeCumulativeProbability(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.cumulativeProbability(x), fpd.cumulativeProbability(x), 1e-16);
        }
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 74 with RandomSeed

use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.

the class FilterTest method canCompareMultiFilter.

@SeededTest
void canCompareMultiFilter(RandomSeed seed) {
    final UniformRandomProvider UniformRandomProvider = RngUtils.create(seed.getSeed());
    final MultiFilter f = new MultiFilter(0, 0, 0, 0, 0, 0, 0, 0, 0);
    for (int i = 1000; i-- > 0; ) {
        final MultiFilter f1 = (MultiFilter) f.create(random(f.getNumberOfParameters(), UniformRandomProvider));
        final MultiFilter f2 = (MultiFilter) f.create(random(f.getNumberOfParameters(), UniformRandomProvider));
        final int e = f1.weakest((Filter) f2);
        final int o = f1.weakest(f2);
        Assertions.assertEquals(e, o);
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 75 with RandomSeed

use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.

the class ConvolutionTest method canComputeDoubleScaledConvolution.

@SeededTest
void canComputeDoubleScaledConvolution(RandomSeed seed) {
    final UniformRandomProvider random = RngUtils.create(seed.getSeed());
    final TDoubleArrayList list = new TDoubleArrayList();
    int size = 10;
    for (int i = 0; i < sizeLoops / 2; i++) {
        double sd = 0.5;
        for (int j = 0; j < sdLoops; j++) {
            final double[] data1 = randomData(random, size);
            final double[] data2 = randomData(random, size);
            final double[] kernel = createKernel(sd);
            for (int scale = 2; scale < 5; scale++) {
                final double[] e1 = convolve(kernel, data1, list, scale);
                final double[] e2 = convolve(kernel, data2, list, scale);
                final double[][] o = Convolution.convolve(kernel, data1, data2, scale);
                final double[][] o2 = new double[2][o[0].length];
                Convolution.convolve(kernel, data1, data2, scale, new DoubleConvolutionValueProcedure() {

                    int index = 0;

                    @Override
                    public boolean execute(double value1, double value2) {
                        o2[0][index] = value1;
                        o2[1][index] = value2;
                        index++;
                        return true;
                    }
                });
                Assertions.assertArrayEquals(e1, o[0]);
                Assertions.assertArrayEquals(e1, o2[0]);
                Assertions.assertArrayEquals(e2, o[1]);
                Assertions.assertArrayEquals(e2, o2[1]);
            }
            sd *= 2;
        }
        size *= 2;
    }
}
Also used : DoubleConvolutionValueProcedure(uk.ac.sussex.gdsc.smlm.utils.Convolution.DoubleConvolutionValueProcedure) TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) 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