use of org.apache.commons.rng.UniformRandomProvider 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 org.apache.commons.rng.UniformRandomProvider in project GDSC-SMLM by aherbert.
the class GaussianFilterTest method filter1IsSameAsFilter2.
private void filter1IsSameAsFilter2(RandomSeed seed, GFilter f1, GFilter f2, boolean weighted, double tolerance) {
final UniformRandomProvider rand = RngUtils.create(seed.getSeed());
final float[] data = createData(rand, size, size);
float[] weights = null;
if (weighted) {
final ContinuousSampler ed = SamplerUtils.createExponentialSampler(rand, 57);
weights = new float[data.length];
for (int i = 0; i < weights.length; i++) {
weights[i] = (float) (1.0 / Math.max(0.01, ed.sample()));
}
// w[i] = (float) (1.0 / Math.max(0.01, rand.nextGaussian() * 0.2 + 2));
// w[i] = 0.5f;
f1.setWeights(weights);
f2.setWeights(weights);
}
for (final double sigma : sigmas) {
final float[] e = data.clone();
f2.run(e, sigma);
final float[] o = data.clone();
f1.run(o, sigma);
double max = 0;
for (int i = 0; i < e.length; i++) {
final double d = DoubleEquality.relativeError(e[i], o[i]);
if (max < d) {
max = d;
}
}
logger.fine(FunctionUtils.getSupplier("%s vs %s w=%b @ %.1f = %g", f1.getName(), f2.getName(), weighted, sigma, max));
Assertions.assertTrue(max < tolerance);
}
}
use of org.apache.commons.rng.UniformRandomProvider 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));
}
}
}
use of org.apache.commons.rng.UniformRandomProvider in project GDSC-SMLM by aherbert.
the class MedianFilterTest method floatRollingMedian3x3InternalAndRollingMedianNxNInternalReturnSameResult.
@SeededTest
public void floatRollingMedian3x3InternalAndRollingMedianNxNInternalReturnSameResult(RandomSeed seed) {
final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
final MedianFilter filter = new MedianFilter();
for (final int width : primes) {
for (final int height : primes) {
floatCompareRollingMedian3x3InternalAndRollingMedianNxNInternal(rg, filter, width, height);
}
}
}
use of org.apache.commons.rng.UniformRandomProvider in project GDSC-SMLM by aherbert.
the class MedianFilterTest method floatBlockMedianNxNInternalAndRollingMedianNxNInternalReturnSameResult.
@SeededTest
public void floatBlockMedianNxNInternalAndRollingMedianNxNInternalReturnSameResult(RandomSeed seed) {
final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
final MedianFilter filter = new MedianFilter();
for (final int width : primes) {
for (final int height : primes) {
for (final int boxSize : boxSizes) {
floatCompareBlockMedianNxNInternalAndRollingMedianNxNInternal(rg, filter, width, height, boxSize);
}
}
}
}
Aggregations