Search in sources :

Example 96 with SeededTest

use of uk.ac.sussex.gdsc.test.junit5.SeededTest 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)

Example 97 with SeededTest

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

the class ImageSourceTest method interlacedImageSourceCanReturnCroppedDataWithGet.

@SeededTest
void interlacedImageSourceCanReturnCroppedDataWithGet(RandomSeed seed) {
    final int width = 5;
    final int height = 3;
    final float[][] data = createData(width, height, 15);
    final int start = 4;
    final int size = 2;
    final int skip = 1;
    final Rectangle bounds = new Rectangle(2, 1, 3, 1);
    final ImageSource source = new InterlacedImageSource(new MemoryImageSource(width, height, data), start, size, skip);
    final int[] frames = new int[data.length];
    for (int i = 0; i < data.length; i++) {
        frames[i] = i + 1;
    }
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    RandomUtils.shuffle(frames, rg);
    final int[] expected = new int[] { 4, 5, 7, 8, 10, 11, 13, 14 };
    Assertions.assertTrue(source.open());
    for (int i = 0; i < data.length; i++) {
        final int frame = frames[i];
        Assertions.assertTrue(source.isValid(frame));
        final float[] next = source.get(frame, bounds);
        if (isExpected(frame, expected)) {
            Assertions.assertEquals(bounds.width * bounds.height, next.length);
            Assertions.assertArrayEquals(crop(data[frame - 1], width, bounds), next);
        } else {
            Assertions.assertNull(next);
        }
    }
    Assertions.assertFalse(source.isValid(0));
    Assertions.assertFalse(source.isValid(data.length + 1));
}
Also used : Rectangle(java.awt.Rectangle) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 98 with SeededTest

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

the class ImageSourceTest method memoryImageSourceCanReturnDataWithGet.

@SeededTest
void memoryImageSourceCanReturnDataWithGet(RandomSeed seed) {
    final int width = 5;
    final int height = 3;
    final float[][] data = createData(width, height, 15);
    final MemoryImageSource source = new MemoryImageSource(width, height, data);
    final int[] frames = new int[data.length];
    for (int i = 0; i < data.length; i++) {
        frames[i] = i + 1;
    }
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    RandomUtils.shuffle(frames, rg);
    Assertions.assertTrue(source.open());
    for (int i = 0; i < data.length; i++) {
        final int frame = frames[i];
        Assertions.assertTrue(source.isValid(frame));
        Assertions.assertArrayEquals(data[frame - 1], source.get(frame));
    }
    Assertions.assertFalse(source.isValid(0));
    Assertions.assertFalse(source.isValid(data.length + 1));
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 99 with SeededTest

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

the class ImageSourceTest method aggregatedImageSourceCanReturnCroppedDataWithGet.

@SeededTest
void aggregatedImageSourceCanReturnCroppedDataWithGet(RandomSeed seed) {
    final int width = 5;
    final int height = 3;
    final int aggregate = 3;
    final float[][] data = createData(width, height, 15);
    final Rectangle bounds = new Rectangle(2, 1, 3, 1);
    final ImageSource source = new AggregatedImageSource(new MemoryImageSource(width, height, data), aggregate);
    final int[] frames = new int[data.length / 3];
    for (int i = 0, frame = 1; i < frames.length; i++, frame += 3) {
        frames[i] = frame;
    }
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    RandomUtils.shuffle(frames, rg);
    Assertions.assertTrue(source.open());
    for (int i = 0; i < frames.length; i++) {
        final int frame = frames[i];
        Assertions.assertTrue(source.isValid(frame));
        final float[] d = source.get(frame, bounds);
        Assertions.assertEquals(frame, source.getStartFrameNumber());
        Assertions.assertEquals(frame + 2, source.getEndFrameNumber());
        final float[] all = combine(crop(data[frame - 1], width, bounds), crop(data[frame], width, bounds), crop(data[frame + 1], width, bounds));
        Assertions.assertArrayEquals(all, d, () -> "Invalid frame data " + frame);
    }
    Assertions.assertFalse(source.isValid(0));
    Assertions.assertFalse(source.isValid(data.length + 1));
}
Also used : Rectangle(java.awt.Rectangle) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 100 with SeededTest

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

the class PeakResultTest method sameResultsAreEqual.

@SeededTest
void sameResultsAreEqual(RandomSeed seed) {
    UniformRandomProvider rng;
    final int size = 10;
    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);
                        rng = RngUtils.create(seed.getSeed());
                        final PeakResult[] r2 = createResults(rng, size, n, withDeviations, withId, withCategory, withEndFrame, withPrecision);
                        for (int i = 0; i < r1.length; i++) {
                            Assertions.assertTrue(PeakResult.equals(r1[i], r2[i]));
                        }
                    }
                }
            }
        }
    }
}
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