Search in sources :

Example 76 with RandomSeed

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

the class ConvolutionTest method canComputeDoubleConvolution.

@SeededTest
void canComputeDoubleConvolution(RandomSeed seed) {
    final UniformRandomProvider random = RngUtils.create(seed.getSeed());
    int size = 10;
    for (int i = 0; i < sizeLoops; 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);
            double[] e1;
            double[] e2;
            double[][] r1;
            for (int fft = 0; fft < 2; fft++) {
                if (fft == 1) {
                    e1 = Convolution.convolveFft(kernel, data1);
                    e2 = Convolution.convolveFft(kernel, data2);
                    r1 = Convolution.convolveFft(kernel, data1, data2);
                } else {
                    e1 = Convolution.convolve(kernel, data1);
                    e2 = Convolution.convolve(kernel, data2);
                    r1 = Convolution.convolve(kernel, data1, data2);
                }
                Assertions.assertEquals(r1.length, 2);
                Assertions.assertEquals(e1.length, r1[0].length);
                Assertions.assertEquals(e2.length, r1[1].length);
                for (int k = 0; k < e1.length; k++) {
                    // Exact match
                    Assertions.assertEquals(e1[k], r1[0][k]);
                    Assertions.assertEquals(e2[k], r1[1][k]);
                }
            }
            sd *= 2;
        }
        size *= 2;
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 77 with RandomSeed

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

the class ConvolutionTest method canComputeDoubleScaledConvolutionWithEarlyExit.

@SeededTest
void canComputeDoubleScaledConvolutionWithEarlyExit(RandomSeed seed) {
    final UniformRandomProvider random = RngUtils.create(seed.getSeed());
    int size = 10;
    final int sizeLoops = 4;
    final int sLoops = 2;
    for (int i = 0; i < sizeLoops; i++) {
        double sd = 0.5;
        for (int j = 0; j < sLoops; 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[][] e = Convolution.convolve(kernel, data1, data2, scale);
                final double[][] o = new double[2][e[0].length];
                final int limit = data1.length;
                Convolution.convolve(kernel, data1, data2, scale, new DoubleConvolutionValueProcedure() {

                    int index = 0;

                    @Override
                    public boolean execute(double value1, double value2) {
                        o[0][index] = value1;
                        o[1][index] = value1;
                        index++;
                        return index < limit;
                    }
                });
                int index = 0;
                for (; index < limit; index++) {
                    Assertions.assertEquals(e[0][index], o[0][index]);
                    Assertions.assertEquals(e[0][index], o[1][index]);
                }
                while (index < o.length) {
                    Assertions.assertEquals(0, o[0][index]);
                    Assertions.assertEquals(0, o[1][index]);
                    index++;
                }
            }
            sd *= 2;
        }
        size *= 2;
    }
}
Also used : DoubleConvolutionValueProcedure(uk.ac.sussex.gdsc.smlm.utils.Convolution.DoubleConvolutionValueProcedure) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 78 with RandomSeed

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

the class ConvolutionTest method canComputeScaledConvolutionWithEarlyExit.

@SeededTest
void canComputeScaledConvolutionWithEarlyExit(RandomSeed seed) {
    final UniformRandomProvider random = RngUtils.create(seed.getSeed());
    int size = 10;
    final int sizeLoops = 4;
    final int sLoops = 2;
    for (int i = 0; i < sizeLoops; i++) {
        double sd = 0.5;
        for (int j = 0; j < sLoops; j++) {
            final double[] data = randomData(random, size);
            final double[] kernel = createKernel(sd);
            for (int scale = 2; scale < 5; scale++) {
                final double[] e = Convolution.convolve(kernel, data, scale);
                final double[] o = new double[e.length];
                final int limit = data.length;
                Convolution.convolve(kernel, data, scale, new ConvolutionValueProcedure() {

                    int index = 0;

                    @Override
                    public boolean execute(double value) {
                        o[index++] = value;
                        return index < limit;
                    }
                });
                int index = 0;
                for (; index < limit; index++) {
                    Assertions.assertEquals(e[index], o[index]);
                }
                while (index < o.length) {
                    Assertions.assertEquals(0, o[index++]);
                }
            }
            sd *= 2;
        }
        size *= 2;
    }
}
Also used : DoubleConvolutionValueProcedure(uk.ac.sussex.gdsc.smlm.utils.Convolution.DoubleConvolutionValueProcedure) ConvolutionValueProcedure(uk.ac.sussex.gdsc.smlm.utils.Convolution.ConvolutionValueProcedure) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 79 with RandomSeed

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

the class ConvolutionTest method doSpeedTest.

@SpeedTag
@SeededTest
void doSpeedTest(RandomSeed seed) {
    Assumptions.assumeTrue(logger.isLoggable(Level.INFO));
    Assumptions.assumeTrue(TestSettings.allow(TestComplexity.HIGH));
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    int size = 10;
    for (int i = 0; i < sizeLoops; i++) {
        double sd = 0.5;
        for (int j = 0; j < sdLoops; j++) {
            speedTest(rg, size, sd);
            sd *= 2;
        }
        size *= 2;
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SpeedTag(uk.ac.sussex.gdsc.test.junit5.SpeedTag) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 80 with RandomSeed

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

the class DynamicMultipleTargetTracingTest method checkBuilder.

@SeededTest
void checkBuilder(RandomSeed seed) {
    final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
    final int temporalWindow = 2 + rng.nextInt(10);
    final double localDiffusionWeight = rng.nextDouble();
    final double diffusionCoefficientMaximum = 1 + rng.nextDouble();
    final double onIntensityWeight = rng.nextDouble();
    final double disappearanceDecayFactor = 1 + rng.nextDouble();
    final int disappearanceThreshold = 1 + rng.nextInt(10);
    final boolean disableIntensityModel = rng.nextBoolean();
    final boolean disableLocalDiffusionModel = rng.nextBoolean();
    final DmttConfiguration.Builder b = DmttConfiguration.newBuilder(45);
    final DmttConfiguration c1 = b.setTemporalWindow(temporalWindow).setLocalDiffusionWeight(localDiffusionWeight).setDiffusionCoefficientMaximum(diffusionCoefficientMaximum).setOnIntensityWeight(onIntensityWeight).setDisappearanceDecayFactor(disappearanceDecayFactor).setDisappearanceThreshold(disappearanceThreshold).setDisableIntensityModel(disableIntensityModel).setDisableLocalDiffusionModel(disableLocalDiffusionModel).build();
    // Check round-trip
    for (final DmttConfiguration config : new DmttConfiguration[] { c1, c1.toBuilder().build() }) {
        Assertions.assertEquals(diffusionCoefficientMaximum, config.getDiffusionCoefficientMaximum());
        Assertions.assertEquals(temporalWindow, config.getTemporalWindow());
        Assertions.assertEquals(localDiffusionWeight, config.getLocalDiffusionWeight());
        Assertions.assertEquals(onIntensityWeight, config.getOnIntensityWeight());
        Assertions.assertEquals(disappearanceDecayFactor, config.getDisappearanceDecayFactor());
        Assertions.assertEquals(disappearanceThreshold, config.getDisappearanceThreshold());
        Assertions.assertEquals(disableIntensityModel, config.isDisableIntensityModel());
        Assertions.assertEquals(disableLocalDiffusionModel, 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