Search in sources :

Example 46 with RandomSeed

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

the class OffsetFunctionTest method offsetValueFunctionWrapsPrecomputedValues.

@SeededTest
void offsetValueFunctionWrapsPrecomputedValues(RandomSeed seed) {
    final int n = 3;
    final UniformRandomProvider r = RngUtils.create(seed.getSeed());
    final ValueFunction f0 = new FakeGradientFunction(3, n);
    final int size = f0.size();
    final double[] b1 = GdscSmlmTestUtils.generateDoubles(size, r);
    final double[] b2 = GdscSmlmTestUtils.generateDoubles(size, r);
    final ValueFunction f1 = OffsetValueFunction.wrapValueFunction(f0, b1);
    final ValueFunction f2 = OffsetValueFunction.wrapValueFunction(f1, b2);
    final double[] p = new double[n];
    for (int i = 0; i < n; i++) {
        p[i] = r.nextDouble();
    }
    final double[] v0 = evaluateValueFunction(f0, p);
    final double[] v1 = evaluateValueFunction(f1, p);
    final double[] v2 = evaluateValueFunction(f2, p);
    for (int i = 0; i < v0.length; i++) {
        final double e = v0[i] + b1[i] + b2[i];
        final double o1 = v1[i] + b2[i];
        final double o2 = v2[i];
        Assertions.assertEquals(e, o1, "o1");
        Assertions.assertEquals(e, o2, 1e-6, "o2");
    }
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 47 with RandomSeed

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

the class OffsetFunctionTest method offsetGradient2FunctionWrapsPrecomputedValues.

@SeededTest
void offsetGradient2FunctionWrapsPrecomputedValues(RandomSeed seed) {
    final int n = 3;
    final UniformRandomProvider r = RngUtils.create(seed.getSeed());
    final Gradient2Function f0 = new FakeGradientFunction(3, n);
    final int size = f0.size();
    final double[] b1 = GdscSmlmTestUtils.generateDoubles(size, r);
    final double[] b2 = GdscSmlmTestUtils.generateDoubles(size, r);
    final Gradient2Function f1 = OffsetGradient2Function.wrapGradient2Function(f0, b1);
    final Gradient2Function f2 = OffsetGradient2Function.wrapGradient2Function(f1, b2);
    final double[] p = new double[n];
    for (int i = 0; i < n; i++) {
        p[i] = r.nextDouble();
    }
    final double[] d0 = new double[n];
    final double[] d1 = new double[n];
    final double[] d2 = new double[n];
    final double[] d20 = new double[n];
    final double[] d21 = new double[n];
    final double[] d22 = new double[n];
    final double[] v0 = evaluateGradient2Function(f0, p, d0, d20);
    final double[] v1 = evaluateGradient2Function(f1, p, d1, d21);
    final double[] v2 = evaluateGradient2Function(f2, p, d2, d22);
    for (int i = 0; i < v0.length; i++) {
        final double e = v0[i] + b1[i] + b2[i];
        final double o1 = v1[i] + b2[i];
        final double o2 = v2[i];
        Assertions.assertEquals(e, o1, "o1");
        Assertions.assertEquals(e, o2, 1e-6, "o2");
    }
    Assertions.assertArrayEquals(d0, d1, "d1");
    Assertions.assertArrayEquals(d0, d2, "d2");
    Assertions.assertArrayEquals(d20, d21, "d21");
    Assertions.assertArrayEquals(d20, d22, "d22");
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 48 with RandomSeed

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

the class ScmosLikelihoodWrapperTest method fitEllipticalComputesGradient.

@SeededTest
void fitEllipticalComputesGradient(RandomSeed seed) {
    // The elliptical function gradient evaluation is worse
    final DoubleEquality tmp = eq;
    eq = eqPerDatum;
    functionComputesGradient(seed, GaussianFunctionFactory.FIT_ELLIPTICAL);
    eq = tmp;
}
Also used : DoubleEquality(uk.ac.sussex.gdsc.core.utils.DoubleEquality) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 49 with RandomSeed

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

the class PrecomputedFunctionTest method precomputedValueFunctionWrapsPrecomputedValues.

@SeededTest
void precomputedValueFunctionWrapsPrecomputedValues(RandomSeed seed) {
    final UniformRandomProvider r = RngUtils.create(seed.getSeed());
    final int size = 100;
    final double[] v = GdscSmlmTestUtils.generateDoubles(size, r);
    final ValueFunction func = new PrecomputedValueFunction(v);
    final double[] vo = evaluateValueFunction(func);
    Assertions.assertArrayEquals(v, vo, "values");
}
Also used : UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 50 with RandomSeed

use of uk.ac.sussex.gdsc.test.junit5.RandomSeed 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)

Aggregations

SeededTest (uk.ac.sussex.gdsc.test.junit5.SeededTest)161 UniformRandomProvider (org.apache.commons.rng.UniformRandomProvider)142 DoubleDoubleBiPredicate (uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate)17 Rectangle (java.awt.Rectangle)12 SpeedTag (uk.ac.sussex.gdsc.test.junit5.SpeedTag)12 TimingService (uk.ac.sussex.gdsc.test.utils.TimingService)11 SharedStateContinuousSampler (org.apache.commons.rng.sampling.distribution.SharedStateContinuousSampler)7 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)6 FloatProcessor (ij.process.FloatProcessor)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 ErfGaussian2DFunction (uk.ac.sussex.gdsc.smlm.function.gaussian.erf.ErfGaussian2DFunction)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 DoubleConvolutionValueProcedure (uk.ac.sussex.gdsc.smlm.utils.Convolution.DoubleConvolutionValueProcedure)4 FloatFloatBiPredicate (uk.ac.sussex.gdsc.test.api.function.FloatFloatBiPredicate)4 MixtureMultivariateNormalDistribution (org.apache.commons.math3.distribution.MixtureMultivariateNormalDistribution)3 MultivariateNormalMixtureExpectationMaximization (org.apache.commons.math3.distribution.fitting.MultivariateNormalMixtureExpectationMaximization)3 DoubleEquality (uk.ac.sussex.gdsc.core.utils.DoubleEquality)3