Search in sources :

Example 6 with ContinuousSampler

use of org.apache.commons.rng.sampling.distribution.ContinuousSampler in project GDSC-SMLM by aherbert.

the class BlockMeanFilterTest method checkIsCorrect.

private static void checkIsCorrect(RandomSeed seed, BlockMeanDataFilter filter) {
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    final ContinuousSampler ed = SamplerUtils.createExponentialSampler(rg, 57);
    for (final int width : primes) {
        for (final int height : primes) {
            final float[] data = createData(rg, width, height);
            filter.filter.setWeights(null, 0, 0);
            for (final float boxSize : boxSizes) {
                for (final boolean internal : checkInternal) {
                    meanIsCorrect(data, width, height, boxSize, internal, filter);
                    if (filter.isInterpolated) {
                        meanIsCorrect(data, width, height, boxSize - 0.3f, internal, filter);
                        meanIsCorrect(data, width, height, boxSize - 0.6f, internal, filter);
                    }
                }
            }
            // Uniform weights
            final float[] w = new float[width * height];
            Arrays.fill(w, 1);
            filter.filter.setWeights(w, width, height);
            for (final float boxSize : boxSizes) {
                for (final boolean internal : checkInternal) {
                    weightedMeanIsCorrect(data, w, width, height, boxSize, internal, filter);
                    if (filter.isInterpolated) {
                        weightedMeanIsCorrect(data, w, width, height, boxSize - 0.3f, internal, filter);
                        weightedMeanIsCorrect(data, w, width, height, boxSize - 0.6f, internal, filter);
                    }
                }
            }
            // 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()));
            }
            filter.filter.setWeights(w, width, height);
            for (final float boxSize : boxSizes) {
                for (final boolean internal : checkInternal) {
                    weightedMeanIsCorrect(data, w, width, height, boxSize, internal, filter);
                    if (filter.isInterpolated) {
                        weightedMeanIsCorrect(data, w, width, height, boxSize - 0.3f, internal, filter);
                        weightedMeanIsCorrect(data, w, width, height, boxSize - 0.6f, internal, filter);
                    }
                }
            }
        }
    }
}
Also used : ContinuousSampler(org.apache.commons.rng.sampling.distribution.ContinuousSampler) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider)

Example 7 with ContinuousSampler

use of org.apache.commons.rng.sampling.distribution.ContinuousSampler in project GDSC-SMLM by aherbert.

the class BlockSumFilterTest method checkIsCorrect.

private static void checkIsCorrect(RandomSeed seed, BlockSumDataFilter filter) {
    final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
    final ContinuousSampler ed = SamplerUtils.createExponentialSampler(rg, 57);
    for (final int width : primes) {
        for (final int height : primes) {
            final float[] data = createData(rg, width, height);
            filter.filter.setWeights(null, 0, 0);
            for (final float boxSize : boxSizes) {
                for (final boolean internal : checkInternal) {
                    sumIsCorrect(data, width, height, boxSize, internal, filter);
                    if (filter.isInterpolated) {
                        sumIsCorrect(data, width, height, boxSize - 0.3f, internal, filter);
                        sumIsCorrect(data, width, height, boxSize - 0.6f, internal, filter);
                    }
                }
            }
            // Uniform weights
            final float[] w = new float[width * height];
            Arrays.fill(w, 1);
            filter.filter.setWeights(w, width, height);
            for (final float boxSize : boxSizes) {
                for (final boolean internal : checkInternal) {
                    weightedSumIsCorrect(data, w, width, height, boxSize, internal, filter);
                    if (filter.isInterpolated) {
                        weightedSumIsCorrect(data, w, width, height, boxSize - 0.3f, internal, filter);
                        weightedSumIsCorrect(data, w, width, height, boxSize - 0.6f, internal, filter);
                    }
                }
            }
            // 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()));
            }
            filter.filter.setWeights(w, width, height);
            for (final float boxSize : boxSizes) {
                for (final boolean internal : checkInternal) {
                    weightedSumIsCorrect(data, w, width, height, boxSize, internal, filter);
                    if (filter.isInterpolated) {
                        weightedSumIsCorrect(data, w, width, height, boxSize - 0.3f, internal, filter);
                        weightedSumIsCorrect(data, w, width, height, boxSize - 0.6f, internal, filter);
                    }
                }
            }
        }
    }
}
Also used : ContinuousSampler(org.apache.commons.rng.sampling.distribution.ContinuousSampler) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider)

Aggregations

ContinuousSampler (org.apache.commons.rng.sampling.distribution.ContinuousSampler)7 UniformRandomProvider (org.apache.commons.rng.UniformRandomProvider)6 SharedStateContinuousSampler (org.apache.commons.rng.sampling.distribution.SharedStateContinuousSampler)3 DiscreteSampler (org.apache.commons.rng.sampling.distribution.DiscreteSampler)2 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)1 ImagePlus (ij.ImagePlus)1 ImageStack (ij.ImageStack)1 File (java.io.File)1 Path (java.nio.file.Path)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 ImageJTrackProgress (uk.ac.sussex.gdsc.core.ij.ImageJTrackProgress)1 Ticker (uk.ac.sussex.gdsc.core.logging.Ticker)1 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)1 Pcg32 (uk.ac.sussex.gdsc.core.utils.rng.Pcg32)1