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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
}
}
}
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]);
}
}
Aggregations