Search in sources :

Example 66 with RandomSeed

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

the class PeakResultDigestTest method sameResultsAreEqualWithId.

@SeededTest
void sameResultsAreEqualWithId(RandomSeed seed) {
    final UniformRandomProvider r = RngUtils.create(seed.getSeed());
    final PeakResult[] r1 = createResults(r, 10, 5, false, true, false, false);
    final PeakResultsDigest digest = new PeakResultsDigest(r1);
    Assertions.assertTrue(digest.matches(r1));
    Assertions.assertTrue(digest.matches(digest));
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 67 with RandomSeed

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

the class PeakResultDigestTest method digestMatchesPeakResultDigest.

@SeededTest
void digestMatchesPeakResultDigest(RandomSeed seed) {
    final UniformRandomProvider r = RngUtils.create(seed.getSeed());
    for (int size = 1; size < 5; size++) {
        final PeakResult[] r1 = createResults(r, size, 5, false, false, false, false);
        final PeakResultsDigest digest = new PeakResultsDigest(r1);
        final PeakResultDigest d = new PeakResultDigest();
        for (final PeakResult rr : r1) {
            d.update(rr);
        }
        Assertions.assertEquals(d.digest(), digest.getDigest());
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 68 with RandomSeed

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

the class PeakResultsReaderTest method canConvertMalkToNmAndPhotons.

@SeededTest
void canConvertMalkToNmAndPhotons(RandomSeed seed) {
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    final MemoryPeakResults out = createResults(rg, 200, false, false, false, false, false);
    // Output in pixel and count
    final CalibrationWriter cal = new CalibrationWriter(out.getCalibration());
    cal.setDistanceUnit(DistanceUnit.PIXEL);
    cal.setIntensityUnit(IntensityUnit.COUNT);
    out.setCalibration(cal.getCalibration());
    out.setPsf(PsfHelper.create(PSFType.CUSTOM));
    final String filename = createFile();
    writeFile(false, ResultsFileFormat.MALK, false, false, false, false, false, false, out, filename);
    final MemoryPeakResults in = readFile(filename, false);
    // Change to nm and photon for the validation
    out.convertToUnits(DistanceUnit.NM, IntensityUnit.PHOTON, null);
    checkEqual(ResultsFileFormat.MALK, false, false, false, false, false, false, out, in);
}
Also used : CalibrationWriter(uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 69 with RandomSeed

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

the class MultivariateGaussianMixtureExpectationMaximizationTest method testExpectationMaximizationSpeedWithDifferentNumberOfComponents.

/**
 * Test the speed of implementations of the expectation maximization algorithm with a mixture of n
 * 2D Gaussian distributions.
 *
 * @param seed the seed
 */
@SpeedTag
@SeededTest
void testExpectationMaximizationSpeedWithDifferentNumberOfComponents(RandomSeed seed) {
    Assumptions.assumeTrue(TestSettings.allow(TestComplexity.HIGH));
    // Create data
    final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
    for (int n = 2; n <= 4; n++) {
        final double[][][] data = new double[10][][];
        for (int i = 0; i < data.length; i++) {
            final double[] sampleWeights = createWeights(n, rng);
            final double[][] sampleMeans = create(n, 2, rng, -5, 5);
            final double[][] sampleStdDevs = create(n, 2, rng, 1, 10);
            final double[] sampleCorrelations = create(n, rng, -0.9, 0.9);
            data[i] = createData2d(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 + " 2D", 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 + " 2D", data) {

            @Override
            Object run(double[][] data) {
                final MultivariateGaussianMixtureExpectationMaximization fitter = new MultivariateGaussianMixtureExpectationMaximization(data);
                fitter.fit(MultivariateGaussianMixtureExpectationMaximization.estimate(data, numComponents));
                return fitter.getLogLikelihood();
            }
        });
        if (logger.isLoggable(Level.INFO)) {
            logger.info(ts.getReport());
        }
        // More than twice as fast
        Assertions.assertTrue(ts.get(-1).getMean() < ts.get(-2).getMean() / 2);
    }
}
Also used : 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)

Example 70 with RandomSeed

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

the class PerPixelCameraModelTest method canCropAndConvertDataWithCropBounds.

@SeededTest
void canCropAndConvertDataWithCropBounds(RandomSeed seed) {
    final PerPixelCameraModelTestData data = (PerPixelCameraModelTestData) dataCache.computeIfAbsent(seed, PerPixelCameraModelTest::createData);
    final PerPixelCameraModel model = new PerPixelCameraModel(w, h, data.bias, data.gain, data.variance);
    final UniformRandomProvider rand = RngUtils.create(seed.getSeed());
    final ImageExtractor ie = ImageExtractor.wrap(data.bias, w, h);
    for (int j = 0; j < 10; j++) {
        final Rectangle bounds = getBounds(rand, ie);
        checkConversion(data, bounds, model.crop(bounds, false));
    }
}
Also used : Rectangle(java.awt.Rectangle) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) ImageExtractor(uk.ac.sussex.gdsc.core.utils.ImageExtractor) 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