Search in sources :

Example 56 with SeededTest

use of uk.ac.sussex.gdsc.test.junit5.SeededTest in project GDSC-SMLM by aherbert.

the class PrecomputedFunctionTest method precomputedGradient2FunctionWrapsPrecomputedValues.

@SeededTest
void precomputedGradient2FunctionWrapsPrecomputedValues(RandomSeed seed) {
    final int n = 3;
    final UniformRandomProvider r = RngUtils.create(seed.getSeed());
    final int size = 100;
    final double[] v = GdscSmlmTestUtils.generateDoubles(size, r);
    final double[][] g1 = new double[size][];
    final double[][] g2 = new double[size][];
    for (int i = 0; i < g1.length; i++) {
        g1[i] = GdscSmlmTestUtils.generateDoubles(n, r);
        g2[i] = GdscSmlmTestUtils.generateDoubles(n, r);
    }
    final Gradient2Function func = new PrecomputedGradient2Function(v, g1, g2);
    final double[][] g1o = new double[size][];
    final double[][] g2o = new double[size][];
    final double[] vo = evaluateGradient2Function(func, g1o, g2o);
    Assertions.assertArrayEquals(v, vo, "values");
    Assertions.assertArrayEquals(g1, g1o, "g1");
    Assertions.assertArrayEquals(g2, g2o, "g2");
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 57 with SeededTest

use of uk.ac.sussex.gdsc.test.junit5.SeededTest in project GDSC-SMLM by aherbert.

the class FactorialTest method testFactorialDouble.

/**
 * Test the factorial of a fractional number against Commons Math gamma(1+n).
 */
@SeededTest
void testFactorialDouble(RandomSeed seed) {
    final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
    final DoubleDoubleBiPredicate tol = TestHelper.doublesAreClose(5e-15).or(TestHelper.doublesEqual());
    for (int i = 0; i < 100; i++) {
        final double n = rng.nextDouble() * 180;
        final double expected = n < 1.5 ? 1 / (1 + Gamma.invGamma1pm1(n)) : Gamma.gamma(1 + n);
        TestAssertions.assertTest(expected, Factorial.value(n), tol, () -> Double.toString(n));
    }
}
Also used : DoubleDoubleBiPredicate(uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 58 with SeededTest

use of uk.ac.sussex.gdsc.test.junit5.SeededTest in project GDSC-SMLM by aherbert.

the class FastLogTest method canTestDoubleSpeedLog1P.

@SpeedTag
@SeededTest
void canTestDoubleSpeedLog1P(RandomSeed seed) {
    // No assertions, this is just a report
    Assumptions.assumeTrue(logger.isLoggable(Level.INFO));
    Assumptions.assumeTrue(TestSettings.allow(TestComplexity.MEDIUM));
    final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
    final double[] x = new double[1000000];
    for (int i = 0; i < x.length; i++) {
        x[i] = nextUniformDouble(rng);
    }
    final MathLog fl = new MathLog();
    final TimingService ts = new TimingService(5);
    // ts.execute(new DoubleTimingTask(new TestLog(fl), 0, x));
    ts.execute(new DoubleTimingTask(new Test1PLog(fl), 0, x));
    ts.execute(new DoubleTimingTask(new TestLog1P(fl), 0, x));
    ts.execute(new DoubleTimingTask(new TestLog1PApache(fl), 0, x));
    // ts.execute(new DoubleTimingTask(new TestLog(fl), 0, x));
    ts.execute(new DoubleTimingTask(new Test1PLog(fl), 0, x));
    ts.execute(new DoubleTimingTask(new TestLog1P(fl), 0, x));
    ts.execute(new DoubleTimingTask(new TestLog1PApache(fl), 0, x));
    final int size = ts.getSize();
    ts.repeat(size);
    logger.info(ts.getReport(size));
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) TimingService(uk.ac.sussex.gdsc.test.utils.TimingService) SpeedTag(uk.ac.sussex.gdsc.test.junit5.SpeedTag) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 59 with SeededTest

use of uk.ac.sussex.gdsc.test.junit5.SeededTest in project GDSC-SMLM by aherbert.

the class FastLogTest method canTestDoubleErrorRange.

@SeededTest
void canTestDoubleErrorRange(RandomSeed seed) {
    Assumptions.assumeTrue(logger.isLoggable(Level.INFO));
    Assumptions.assumeTrue(TestSettings.allow(TestComplexity.HIGH));
    final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
    final LocalList<TestFastLog> test = new LocalList<>();
    final int n = 13;
    test.add(new TestFastLog(IcsiFastLog.create(n, DataType.DOUBLE)));
    test.add(new TestFastLog(new FFastLog(n)));
    test.add(new TestFastLog(new DFastLog(n)));
    test.add(new TestFastLog(new TurboLog(n)));
    // Full range in blocks.
    // Only when the number is around 1 or min value are there significant errors
    final double[] d = new double[10000000];
    final double[] logD = null;
    // All
    // testDoubleErrorRange(test, n, d, logD, 0, 255, 0);
    // Only a problem around min value and x==1
    // testDoubleErrorRange(rng, test, n, d, logD, 0, 2, 0);
    testDoubleErrorRange(rng, test, n, d, logD, 1021, 1026, 0);
    testDoubleErrorRange(rng, test, n, d, logD, 2045, 2047, 0);
}
Also used : LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 60 with SeededTest

use of uk.ac.sussex.gdsc.test.junit5.SeededTest in project GDSC-SMLM by aherbert.

the class FastLogTest method canTestDoubleErrorLog1P.

@SeededTest
void canTestDoubleErrorLog1P(RandomSeed seed) {
    Assumptions.assumeTrue(logger.isLoggable(Level.INFO));
    Assumptions.assumeTrue(TestSettings.allow(TestComplexity.HIGH));
    // All float values is a lot so we do a representative set
    final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
    final double lower = Double.MIN_VALUE;
    final double upper = Double.MAX_VALUE;
    final double[] d = new double[100000];
    final double[] logD = new double[d.length];
    for (int i = 0; i < d.length; i++) {
        final double v = nextUniformDouble(rng);
        d[i] = v;
        logD[i] = Math.log1p(v);
    }
    runCanTestDoubleError(new Test1PLog(new MathLog()), d, logD);
    runCanTestDoubleError(new TestLog1P(new MathLog()), d, logD);
}
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