Search in sources :

Example 16 with SeededTest

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");
        }
    }
}
Also used : DenseMatrix64F(org.ejml.data.DenseMatrix64F) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 17 with SeededTest

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);
        }
    }
}
Also used : ChiSquaredDistribution(org.apache.commons.math3.distribution.ChiSquaredDistribution) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 18 with SeededTest

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");
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) ChiSquareTest(org.apache.commons.math3.stat.inference.ChiSquareTest) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 19 with SeededTest

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);
            }
        }
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 20 with SeededTest

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);
            }
        }
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Aggregations

SeededTest (uk.ac.sussex.gdsc.test.junit5.SeededTest)172 UniformRandomProvider (org.apache.commons.rng.UniformRandomProvider)142 DoubleDoubleBiPredicate (uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate)18 Rectangle (java.awt.Rectangle)12 SpeedTag (uk.ac.sussex.gdsc.test.junit5.SpeedTag)12 TimingService (uk.ac.sussex.gdsc.test.utils.TimingService)12 SharedStateContinuousSampler (org.apache.commons.rng.sampling.distribution.SharedStateContinuousSampler)7 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)6 FloatProcessor (ij.process.FloatProcessor)6 ErfGaussian2DFunction (uk.ac.sussex.gdsc.smlm.function.gaussian.erf.ErfGaussian2DFunction)6 DummyGradientFunction (uk.ac.sussex.gdsc.smlm.function.DummyGradientFunction)5 SingleFreeCircularErfGaussian2DFunction (uk.ac.sussex.gdsc.smlm.function.gaussian.erf.SingleFreeCircularErfGaussian2DFunction)5 TimingResult (uk.ac.sussex.gdsc.test.utils.TimingResult)5 ArrayList (java.util.ArrayList)4 Gaussian2DFunction (uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction)4 MixtureMultivariateGaussianDistribution (uk.ac.sussex.gdsc.smlm.math3.distribution.fitting.MultivariateGaussianMixtureExpectationMaximization.MixtureMultivariateGaussianDistribution)4 MultivariateGaussianDistribution (uk.ac.sussex.gdsc.smlm.math3.distribution.fitting.MultivariateGaussianMixtureExpectationMaximization.MixtureMultivariateGaussianDistribution.MultivariateGaussianDistribution)4 FloatFloatBiPredicate (uk.ac.sussex.gdsc.test.api.function.FloatFloatBiPredicate)4 MultivariateNormalMixtureExpectationMaximization (org.apache.commons.math3.distribution.fitting.MultivariateNormalMixtureExpectationMaximization)3 DoubleEquality (uk.ac.sussex.gdsc.core.utils.DoubleEquality)3