Search in sources :

Example 31 with UniformRandomProvider

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

the class SumFilterTest method intStripedBlockSum3x3AndStripedBlockSumNxNReturnSameResult.

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

Example 32 with UniformRandomProvider

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

the class SumFilterTest method intBlockSum3x3InternalAndBlockSumNxNInternalReturnSameResult.

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

Example 33 with UniformRandomProvider

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

the class SumFilterTest method floatBlockSum3x3InternalAndBlockSumNxNInternalReturnSameResult.

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

Example 34 with UniformRandomProvider

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

the class WeightedKernelFilterTest method filterPerformsWeightedKernelFiltering.

@SeededTest
void filterPerformsWeightedKernelFiltering(RandomSeed seed) {
    final DataFilter filter = createDataFilter();
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    final SharedStateContinuousSampler gs = SamplerUtils.createGaussianSampler(rg, 2, 0.2);
    final float[] offsets = getOffsets(filter);
    final int[] boxSizes = getBoxSizes(filter);
    final TDoubleArrayList l1 = new TDoubleArrayList();
    final FloatFloatBiPredicate equality = TestHelper.floatsAreClose(1e-6, 0);
    for (final int width : primes) {
        for (final int height : new int[] { 29 }) {
            final float[] data = createData(width, height, rg);
            l1.reset();
            // Uniform weights
            final float[] w1 = new float[width * height];
            Arrays.fill(w1, 0.5f);
            // Weights simulating the variance of sCMOS pixels
            final float[] w2 = new float[width * height];
            for (int i = 0; i < w2.length; i++) {
                w2[i] = (float) (1.0 / Math.max(0.01, gs.sample()));
            }
            for (final int boxSize : boxSizes) {
                for (final float offset : offsets) {
                    for (final boolean internal : checkInternal) {
                        // For each pixel over the range around the pixel (vi).
                        // kernel filter: sum(vi * ki) / sum(ki)
                        // Weighted kernel filter: sum(vi * wi * ki) / sum(ki * wi)
                        // Note: The kernel filter is like a weighted filter
                        // (New kernel = wi * ki)
                        filter.setWeights(null, width, height);
                        // Uniform weights
                        testfilterPerformsWeightedFiltering(filter, width, height, data, w1, boxSize, offset, internal, equality);
                        // Random weights.
                        testfilterPerformsWeightedFiltering(filter, width, height, data, w2, boxSize, offset, internal, equality);
                    }
                }
            }
        }
    }
}
Also used : TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) SharedStateContinuousSampler(org.apache.commons.rng.sampling.distribution.SharedStateContinuousSampler) FloatFloatBiPredicate(uk.ac.sussex.gdsc.test.api.function.FloatFloatBiPredicate) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 35 with UniformRandomProvider

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

the class FisherInformationMatrixTest method computeWithSubsetReducesTheCrlb.

@SeededTest
void computeWithSubsetReducesTheCrlb(RandomSeed seed) {
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    final Gaussian2DFunction f = createFunction(10, 1);
    final int perPeak = f.getGradientParametersPerPeak();
    // Create a matrix with 2 peaks + background
    final FisherInformationMatrix m = createFisherInformationMatrix(rg, 1 + 2 * perPeak, 0);
    // Subset each peak
    final int[] indices = SimpleArrayUtils.natural(1 + perPeak);
    final FisherInformationMatrix m1 = m.subset(indices);
    for (int i = 1; i < indices.length; i++) {
        indices[i] += perPeak;
    }
    final FisherInformationMatrix m2 = m.subset(indices);
    // TestLog.fine(logger,m.getMatrix());
    // TestLog.fine(logger,m1.getMatrix());
    // TestLog.fine(logger,m2.getMatrix());
    final double[] crlb = m.crlb();
    final double[] crlb1 = m1.crlb();
    final double[] crlb2 = m2.crlb();
    final double[] crlbB = Arrays.copyOf(crlb1, crlb.length);
    System.arraycopy(crlb2, 1, crlbB, crlb1.length, perPeak);
    // Removing the interaction between fit parameters lowers the bounds
    for (int i = 0; i < crlb.length; i++) {
        Assertions.assertTrue(crlbB[i] < crlb[i]);
    }
}
Also used : Gaussian2DFunction(uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction) 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