Search in sources :

Example 56 with RandomSeed

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

the class AreaAverageFilterTest method areaAverageUsingSumsInternalCorrectlyInterpolatesBetweenBlocks.

@SeededTest
void areaAverageUsingSumsInternalCorrectlyInterpolatesBetweenBlocks(RandomSeed seed) {
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    final int max = 50;
    final float[] data = createData(rg, max, max);
    final AreaAverageFilter filter = new AreaAverageFilter();
    filter.setSimpleInterpolation(false);
    final int n = 30;
    final float[][] results = new float[n + 1][];
    final double[] w = new double[n + 1];
    int count = 0;
    for (int i = 0; i <= n; i++) {
        w[count] = i / 10.0;
        results[count] = data.clone();
        filter.areaAverageUsingSumsInternal(results[count], max, max, w[count]);
        count++;
    }
    checkInterpolation(max, n, results, count);
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 57 with RandomSeed

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

the class AreaAverageFilterTest method areaAverageUsingSumsCorrectlyInterpolatesBetweenBlocks.

@SeededTest
void areaAverageUsingSumsCorrectlyInterpolatesBetweenBlocks(RandomSeed seed) {
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    final int max = 50;
    final float[] data = createData(rg, max, max);
    final AreaAverageFilter filter = new AreaAverageFilter();
    filter.setSimpleInterpolation(false);
    final int n = 30;
    final float[][] results = new float[n + 1][];
    final double[] w = new double[n + 1];
    int count = 0;
    for (int i = 0; i <= n; i++) {
        w[count] = i / 10.0;
        results[count] = data.clone();
        filter.areaAverageUsingSums(results[count], max, max, w[count]);
        count++;
    }
    checkInterpolation(max, n, results, count);
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 58 with RandomSeed

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

the class TraceManagerTest method canTraceSinglePulseWithMovingCoords.

@SeededTest
void canTraceSinglePulseWithMovingCoords(RandomSeed seed) {
    final UniformRandomProvider rand = RngUtils.create(seed.getSeed());
    final float distance = 0.5f;
    final float[] params = createParams(rand);
    final Trace trace = new Trace();
    for (int i = 0; i < 5; i++) {
        move(rand, params, distance);
        trace.add(new PeakResult(i, 0, 0, 0, 0, 0, 0, params, null));
    }
    runTracing(rand, distance, 1, trace);
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 59 with RandomSeed

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

the class TraceManagerTest method canTraceSinglePulseWithFixedCoords.

@SeededTest
void canTraceSinglePulseWithFixedCoords(RandomSeed seed) {
    final UniformRandomProvider rand = RngUtils.create(seed.getSeed());
    final float[] params = createParams(rand);
    final Trace trace = new Trace();
    for (int i = 0; i < 5; i++) {
        trace.add(new PeakResult(i, 0, 0, 0, 0, 0, 0, params, null));
    }
    runTracing(rand, 0, 1, trace);
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 60 with RandomSeed

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

the class MultivariateGaussianMixtureExpectationMaximizationTest method testExpectationMaximizationSpeed.

/**
 * Test the speed of implementations of the expectation maximization algorithm with a mixture of n
 * ND Gaussian distributions.
 *
 * @param seed the seed
 */
@SpeedTag
@SeededTest
void testExpectationMaximizationSpeed(RandomSeed seed) {
    Assumptions.assumeTrue(TestSettings.allow(TestComplexity.HIGH));
    final MultivariateGaussianMixtureExpectationMaximization.DoubleDoubleBiPredicate relChecker = TestHelper.doublesAreClose(1e-6)::test;
    // Create data
    final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
    for (int n = 2; n <= 3; n++) {
        for (int dim = 2; dim <= 4; dim++) {
            final double[][][] data = new double[10][][];
            final int nCorrelations = dim - 1;
            for (int i = 0; i < data.length; i++) {
                final double[] sampleWeights = createWeights(n, rng);
                final double[][] sampleMeans = create(n, dim, rng, -5, 5);
                final double[][] sampleStdDevs = create(n, dim, rng, 1, 10);
                final double[][] sampleCorrelations = IntStream.range(0, n).mapToObj(component -> create(nCorrelations, rng, -0.9, 0.9)).toArray(double[][]::new);
                data[i] = createDataNd(1000, rng, sampleWeights, sampleMeans, sampleStdDevs, sampleCorrelations);
            }
            final int numComponents = n;
            // Time initial estimation and fitting
            final TimingService ts = new TimingService();
            ts.execute(new FittingSpeedTask("Commons n=" + n + " " + dim + "D", data) {

                @Override
                Object run(double[][] data) {
                    final MultivariateNormalMixtureExpectationMaximization fitter = new MultivariateNormalMixtureExpectationMaximization(data);
                    fitter.fit(MultivariateNormalMixtureExpectationMaximization.estimate(data, numComponents));
                    return fitter.getLogLikelihood();
                }
            });
            ts.execute(new FittingSpeedTask("GDSC n=" + n + " " + dim + "D", data) {

                @Override
                Object run(double[][] data) {
                    final MultivariateGaussianMixtureExpectationMaximization fitter = new MultivariateGaussianMixtureExpectationMaximization(data);
                    fitter.fit(MultivariateGaussianMixtureExpectationMaximization.estimate(data, numComponents));
                    return fitter.getLogLikelihood();
                }
            });
            ts.execute(new FittingSpeedTask("GDSC rel 1e-6 n=" + n + " " + dim + "D", data) {

                @Override
                Object run(double[][] data) {
                    final MultivariateGaussianMixtureExpectationMaximization fitter = new MultivariateGaussianMixtureExpectationMaximization(data);
                    fitter.fit(MultivariateGaussianMixtureExpectationMaximization.estimate(data, numComponents), 1000, relChecker);
                    return fitter.getLogLikelihood();
                }
            });
            if (logger.isLoggable(Level.INFO)) {
                logger.info(ts.getReport());
            }
            // More than twice as fast
            Assertions.assertTrue(ts.get(-2).getMean() < ts.get(-3).getMean() / 2);
        }
    }
}
Also used : IntStream(java.util.stream.IntStream) RandomUtils(uk.ac.sussex.gdsc.core.utils.rng.RandomUtils) Arrays(java.util.Arrays) MultivariateGaussianDistribution(uk.ac.sussex.gdsc.smlm.math3.distribution.fitting.MultivariateGaussianMixtureExpectationMaximization.MixtureMultivariateGaussianDistribution.MultivariateGaussianDistribution) BaseTimingTask(uk.ac.sussex.gdsc.test.utils.BaseTimingTask) RngUtils(uk.ac.sussex.gdsc.test.rng.RngUtils) Covariance(org.apache.commons.math3.stat.correlation.Covariance) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) MultivariateNormalMixtureExpectationMaximization(org.apache.commons.math3.distribution.fitting.MultivariateNormalMixtureExpectationMaximization) AfterAll(org.junit.jupiter.api.AfterAll) Mean(org.apache.commons.math3.stat.descriptive.moment.Mean) TimingService(uk.ac.sussex.gdsc.test.utils.TimingService) BeforeAll(org.junit.jupiter.api.BeforeAll) ContinuousUniformSampler(org.apache.commons.rng.sampling.distribution.ContinuousUniformSampler) MultivariateNormalDistribution(org.apache.commons.math3.distribution.MultivariateNormalDistribution) TestComplexity(uk.ac.sussex.gdsc.test.utils.TestComplexity) MixtureMultivariateNormalDistribution(org.apache.commons.math3.distribution.MixtureMultivariateNormalDistribution) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) TestAssertions(uk.ac.sussex.gdsc.test.api.TestAssertions) RandomSeed(uk.ac.sussex.gdsc.test.junit5.RandomSeed) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SpeedTag(uk.ac.sussex.gdsc.test.junit5.SpeedTag) Pair(org.apache.commons.math3.util.Pair) DoubleDoubleBiPredicate(uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate) RandomGeneratorAdapter(uk.ac.sussex.gdsc.core.utils.rng.RandomGeneratorAdapter) Logger(java.util.logging.Logger) SamplerUtils(uk.ac.sussex.gdsc.core.utils.rng.SamplerUtils) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest) Test(org.junit.jupiter.api.Test) List(java.util.List) Assumptions(org.junit.jupiter.api.Assumptions) TestSettings(uk.ac.sussex.gdsc.test.utils.TestSettings) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) SharedStateContinuousSampler(org.apache.commons.rng.sampling.distribution.SharedStateContinuousSampler) Assertions(org.junit.jupiter.api.Assertions) TestHelper(uk.ac.sussex.gdsc.test.api.TestHelper) MixtureMultivariateGaussianDistribution(uk.ac.sussex.gdsc.smlm.math3.distribution.fitting.MultivariateGaussianMixtureExpectationMaximization.MixtureMultivariateGaussianDistribution) NormalizedGaussianSampler(org.apache.commons.rng.sampling.distribution.NormalizedGaussianSampler) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) TimingService(uk.ac.sussex.gdsc.test.utils.TimingService) MultivariateNormalMixtureExpectationMaximization(org.apache.commons.math3.distribution.fitting.MultivariateNormalMixtureExpectationMaximization) SpeedTag(uk.ac.sussex.gdsc.test.junit5.SpeedTag) 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