use of uk.ac.sussex.gdsc.test.junit5.SeededTest in project GDSC-SMLM by aherbert.
the class ChiSquaredDistributionTableTest method canComputeChiSquared.
@SeededTest
void canComputeChiSquared() {
// We have to use the transpose of the table
final DenseMatrix64F m = new DenseMatrix64F(chi2);
CommonOps.transpose(m);
final int max = m.numCols;
final double[] et = m.data;
for (int i = 0, j = 0; i < p.length; i++) {
final ChiSquaredDistributionTable upperTable = ChiSquaredDistributionTable.createUpperTailed(p[i], max);
// Use 1-p as the significance level to get the same critical values
final ChiSquaredDistributionTable lowerTable = ChiSquaredDistributionTable.createLowerTailed(1 - p[i], max);
for (int df = 1; df <= max; df++) {
final double o = upperTable.getCrititalValue(df);
final double e = et[j++];
// logger.fine(FunctionUtils.getSupplier("p=%.3f,df=%d = %f", p[i], df, o);
Assertions.assertEquals(e, o, 1e-2);
// The test only stores 2 decimal places so use the computed value to set upper/lower
final double upper = o * 1.01;
final double lower = o * 0.99;
Assertions.assertTrue(upperTable.reject(upper, df), "Upper did not reject higher");
Assertions.assertFalse(upperTable.reject(o, df), "Upper did not reject actual value");
Assertions.assertFalse(upperTable.reject(lower, df), "Upper did not accept lower");
Assertions.assertTrue(lowerTable.reject(lower, df), "Lower did not reject lower");
Assertions.assertFalse(lowerTable.reject(o, df), "Lower did not accept actual value");
Assertions.assertFalse(lowerTable.reject(upper, df), "Lower did not accept higher");
}
}
}
use of uk.ac.sussex.gdsc.test.junit5.SeededTest in project GDSC-SMLM by aherbert.
the class ChiSquaredDistributionTableTest method canComputeProbability.
// @formatter:on
@SeededTest
void canComputeProbability() {
for (final int df : new int[] { 5, 10 }) {
double obs;
double exp;
double chi = 0;
final ChiSquaredDistribution d = new ChiSquaredDistribution(null, df);
obs = ChiSquaredDistributionTable.computePValue(chi, df);
exp = d.cumulativeProbability(chi);
Assertions.assertEquals(exp, obs, 1e-10);
chi = 1;
for (int i = 0; i < 10; i++, chi *= 2) {
obs = ChiSquaredDistributionTable.computePValue(chi, df);
exp = d.cumulativeProbability(chi);
Assertions.assertEquals(exp, obs, 1e-10);
obs = ChiSquaredDistributionTable.computeQValue(chi, df);
exp = 1 - exp;
Assertions.assertEquals(exp, obs, 1e-10);
}
}
}
use of uk.ac.sussex.gdsc.test.junit5.SeededTest in project GDSC-SMLM by aherbert.
the class ChiSquaredDistributionTableTest method canPerformChiSquaredTest.
@SeededTest
void canPerformChiSquaredTest(RandomSeed seed) {
final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
final ChiSquareTest test = new ChiSquareTest();
for (final int n : new int[] { 10, 50, 100 }) {
final double[] x = SimpleArrayUtils.newArray(n, 0.5, 1.0);
final long[] l = new long[x.length];
for (int i = 0; i < x.length; i++) {
l[i] = GdscSmlmTestUtils.createPoissonSampler(rng, x[i]).sample();
}
final double chi2 = test.chiSquare(x, l);
final double ep = test.chiSquareTest(x, l);
final int df = x.length - 1;
final double o = ChiSquaredDistributionTable.computeQValue(chi2, df);
Assertions.assertEquals(ep, o, 1e-10);
final ChiSquaredDistributionTable upperTable = ChiSquaredDistributionTable.createUpperTailed(o, df);
final double upper = chi2 * 1.01;
final double lower = chi2 * 0.99;
Assertions.assertTrue(upperTable.reject(upper, df), "Upper did not reject higher");
Assertions.assertFalse(upperTable.reject(o, df), "Upper did not reject actual value");
Assertions.assertFalse(upperTable.reject(lower, df), "Upper did not accept lower");
}
}
use of uk.ac.sussex.gdsc.test.junit5.SeededTest in project GDSC-SMLM by aherbert.
the class SumFilterTest method intBlockSumNxNInternalAndStripedBlockSumNxNInternalReturnSameResult.
@SeededTest
void intBlockSumNxNInternalAndStripedBlockSumNxNInternalReturnSameResult(RandomSeed seed) {
final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
final SumFilter filter = new SumFilter();
for (final int width : primes) {
for (final int height : primes) {
for (final int boxSize : boxSizes) {
intCompareBlockSumNxNInternalAndStripedBlockSumNxNInternal(rg, filter, width, height, boxSize);
}
}
}
}
use of uk.ac.sussex.gdsc.test.junit5.SeededTest in project GDSC-SMLM by aherbert.
the class SumFilterTest method intBlockSumNxNInternalAndRollingBlockSumNxNInternalReturnSameResult.
@SeededTest
void intBlockSumNxNInternalAndRollingBlockSumNxNInternalReturnSameResult(RandomSeed seed) {
final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
final SumFilter filter = new SumFilter();
for (final int width : primes) {
for (final int height : primes) {
for (final int boxSize : boxSizes) {
intCompareBlockSumNxNInternalAndRollingBlockSumNxNInternal(rg, filter, width, height, boxSize);
}
}
}
}
Aggregations