use of uk.ac.sussex.gdsc.test.junit5.RandomSeed 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 uk.ac.sussex.gdsc.test.junit5.RandomSeed 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 uk.ac.sussex.gdsc.test.junit5.RandomSeed 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]);
}
}
use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class FisherInformationMatrixTest method inversionDoesNotMatchReciprocal.
@SeededTest
void inversionDoesNotMatchReciprocal(RandomSeed seed) {
final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
for (int n = 1; n < 10; n++) {
final FisherInformationMatrix m = createFisherInformationMatrix(rg, n, 0);
final double[] crlb = m.crlb();
final double[] crlb2 = m.crlbReciprocal();
// These increasingly do not match with increasing number of parameters.
if (logger.isLoggable(level)) {
logger.log(level, FunctionUtils.getSupplier("%s =? %s", Arrays.toString(crlb), Arrays.toString(crlb2)));
}
if (n > 1) {
// Just do a sum so we have a test
Assertions.assertThrows(AssertionFailedError.class, () -> {
Assertions.assertEquals(MathUtils.sum(crlb), MathUtils.sum(crlb2));
});
}
}
}
use of uk.ac.sussex.gdsc.test.junit5.RandomSeed in project GDSC-SMLM by aherbert.
the class GaussianFilterTest method floatFilterInternalIsFasterThanDoubleFilterInternal.
@SpeedTag
@SeededTest
void floatFilterInternalIsFasterThanDoubleFilterInternal(RandomSeed seed) {
Assumptions.assumeTrue(TestSettings.allow(TestComplexity.HIGH));
final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
final float[][] data = new float[10][];
for (int i = 0; i < data.length; i++) {
data[i] = createData(rg, size, size);
}
final TimingService ts = new TimingService();
for (final double sigma : sigmas) {
ts.execute(new MyTimingTask(new FloatFilter(true), data, sigma));
ts.execute(new MyTimingTask(new DpFilter(false), data, sigma));
ts.execute(new MyTimingTask(new DoubleFilter(true), data, sigma));
}
final int size = ts.getSize();
ts.repeat();
if (logger.isLoggable(Level.INFO)) {
logger.info(ts.getReport(size));
}
final int n = size / sigmas.length;
for (int i = 0, j = size; i < sigmas.length; i++, j += n) {
for (int k = 1; k < n; k++) {
final TimingResult slow = ts.get(j + k);
final TimingResult fast = ts.get(j);
logger.log(TestLogUtils.getTimingRecord(slow, fast));
}
}
}
Aggregations