Search in sources :

Example 41 with UniformRandomProvider

use of org.apache.commons.rng.UniformRandomProvider in project GDSC-SMLM by aherbert.

the class MedianFilterTest method floatBlockMedian3x3InternalAndRollingMedianNxNInternalReturnSameResult.

@SeededTest
public void floatBlockMedian3x3InternalAndRollingMedianNxNInternalReturnSameResult(RandomSeed seed) {
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    final MedianFilter filter = new MedianFilter();
    for (final int width : primes) {
        for (final int height : primes) {
            floatCompareBlockMedian3x3InternalAndRollingMedianNxNInternal(rg, filter, width, height);
        }
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 42 with UniformRandomProvider

use of org.apache.commons.rng.UniformRandomProvider in project GDSC-SMLM by aherbert.

the class WeightedFilterTest method filterDoesNotAlterFilteredImageMean.

@SeededTest
void filterDoesNotAlterFilteredImageMean(RandomSeed seed) {
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    // ExponentialDistribution ed = new ExponentialDistribution(rand, 57,
    // ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    final DataFilter filter = createDataFilter();
    final float[] offsets = getOffsets(filter);
    final int[] boxSizes = getBoxSizes(filter);
    final TDoubleArrayList l1 = new TDoubleArrayList();
    final SharedStateContinuousSampler gs = SamplerUtils.createGaussianSampler(rg, 2, 0.2);
    for (final int width : primes) {
        for (final int height : primes) {
            final float[] data = createData(width, height, rg);
            l1.reset();
            filter.setWeights(null, width, height);
            for (final int boxSize : boxSizes) {
                for (final float offset : offsets) {
                    for (final boolean internal : checkInternal) {
                        l1.add(getMean(data, width, height, boxSize - offset, internal, filter));
                    }
                }
            }
            final double[] e = l1.toArray();
            int ei = 0;
            // Uniform weights
            final float[] w = new float[width * height];
            Arrays.fill(w, 0.5f);
            filter.setWeights(w, width, height);
            for (final int boxSize : boxSizes) {
                for (final float offset : offsets) {
                    for (final boolean internal : checkInternal) {
                        testMean(data, width, height, boxSize - offset, internal, filter, "w=0.5", e[ei++], 1e-5);
                    }
                }
            }
            // Weights simulating the variance of sCMOS pixels
            for (int i = 0; i < w.length; i++) {
                // w[i] = (float) (1.0 / Math.max(0.01, ed.sample()));
                w[i] = (float) (1.0 / Math.max(0.01, gs.sample()));
            // w[i] = 0.5f;
            }
            ei = 0;
            filter.setWeights(w, width, height);
            for (final int boxSize : boxSizes) {
                for (final float offset : offsets) {
                    for (final boolean internal : checkInternal) {
                        testMean(data, width, height, boxSize - offset, internal, filter, "w=?", e[ei++], 5e-2);
                    }
                }
            }
        }
    }
}
Also used : TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) SharedStateContinuousSampler(org.apache.commons.rng.sampling.distribution.SharedStateContinuousSampler) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 43 with UniformRandomProvider

use of org.apache.commons.rng.UniformRandomProvider in project GDSC-SMLM by aherbert.

the class WeightedFilterTest method evenWeightsDoesNotAlterFiltering.

@SeededTest
void evenWeightsDoesNotAlterFiltering(RandomSeed seed) {
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    final DataFilter filter1 = createDataFilter();
    final DataFilter filter2 = createDataFilter();
    final float[] offsets = getOffsets(filter1);
    final int[] boxSizes = getBoxSizes(filter1);
    final int[] primes = Arrays.copyOf(WeightedFilterTest.primes, WeightedFilterTest.primes.length - 1);
    final FloatFloatBiPredicate equality = TestHelper.floatsAreClose(1e-4, 0);
    for (final int width : primes) {
        for (final int height : primes) {
            final float[] data = createData(width, height, rg);
            // Uniform weights
            final float[] w = new float[width * height];
            Arrays.fill(w, 0.5f);
            filter2.setWeights(w, width, height);
            for (final int boxSize : boxSizes) {
                for (final float offset : offsets) {
                    for (final boolean internal : checkInternal) {
                        final float[] e = filter(data, width, height, boxSize - offset, internal, filter1);
                        final float[] o = filter(data, width, height, boxSize - offset, internal, filter2);
                        try {
                            TestAssertions.assertArrayTest(e, o, equality);
                        } catch (final AssertionError ex) {
                            final String msg = String.format("%s : [%dx%d] @ %.1f [internal=%b]", filter2.name, width, height, boxSize - offset, internal);
                            throw new AssertionError(msg, ex);
                        }
                    }
                }
            }
        }
    }
}
Also used : FloatFloatBiPredicate(uk.ac.sussex.gdsc.test.api.function.FloatFloatBiPredicate) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 44 with UniformRandomProvider

use of org.apache.commons.rng.UniformRandomProvider in project GDSC-SMLM by aherbert.

the class BinomialFitterTest method sameFitZeroTruncatedBinomialWithKnownNUsingLseOrMle.

@SeededTest
void sameFitZeroTruncatedBinomialWithKnownNUsingLseOrMle(RandomSeed seed) {
    Assumptions.assumeTrue(TestSettings.allow(nonEssentialTestComplexity));
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    final boolean zeroTruncated = true;
    for (final int n : N) {
        for (final double p : P) {
            fitBinomialUsingLseOrMle(rg, n, p, zeroTruncated, n, n);
        }
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 45 with UniformRandomProvider

use of org.apache.commons.rng.UniformRandomProvider in project GDSC-SMLM by aherbert.

the class BinomialFitterTest method canFitZeroTruncatedBinomialWithUnknownNUsingLeastSquaresEstimator.

@SeededTest
void canFitZeroTruncatedBinomialWithUnknownNUsingLeastSquaresEstimator(RandomSeed seed) {
    Assumptions.assumeTrue(TestSettings.allow(nonEssentialTestComplexity));
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    final boolean zeroTruncated = true;
    final boolean maximumLikelihood = false;
    for (final int n : N) {
        for (final double p : P) {
            fitBinomial(rg, n, p, zeroTruncated, maximumLikelihood, 1, n);
        }
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Aggregations

UniformRandomProvider (org.apache.commons.rng.UniformRandomProvider)213 SeededTest (uk.ac.sussex.gdsc.test.junit5.SeededTest)145 SharedStateContinuousSampler (org.apache.commons.rng.sampling.distribution.SharedStateContinuousSampler)17 TimingService (uk.ac.sussex.gdsc.test.utils.TimingService)14 Rectangle (java.awt.Rectangle)13 DoubleDoubleBiPredicate (uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate)13 SpeedTag (uk.ac.sussex.gdsc.test.junit5.SpeedTag)12 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)10 ArrayList (java.util.ArrayList)10 NormalizedGaussianSampler (org.apache.commons.rng.sampling.distribution.NormalizedGaussianSampler)9 StoredDataStatistics (uk.ac.sussex.gdsc.core.utils.StoredDataStatistics)8 CalibrationWriter (uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter)8 ContinuousSampler (org.apache.commons.rng.sampling.distribution.ContinuousSampler)6 ImageExtractor (uk.ac.sussex.gdsc.core.utils.ImageExtractor)6 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)6 Gaussian2DFunction (uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction)6 FloatProcessor (ij.process.FloatProcessor)5 ErfGaussian2DFunction (uk.ac.sussex.gdsc.smlm.function.gaussian.erf.ErfGaussian2DFunction)5 TimingResult (uk.ac.sussex.gdsc.test.utils.TimingResult)5 File (java.io.File)4