Search in sources :

Example 1 with DoublePredicate

use of uk.ac.sussex.gdsc.test.api.function.DoublePredicate in project GDSC-SMLM by aherbert.

the class PoissonFunctionTest method probabilityMatchesLogProbabilty.

private static void probabilityMatchesLogProbabilty(final double gain, final double mu) {
    final double o = mu;
    final PoissonFunction f = new PoissonFunction(1.0 / gain);
    final double p = 0;
    final int[] range = getRange(gain, mu);
    final int min = range[0];
    final int max = range[1];
    // Allow a relative difference or an exact match (for the case of -Infinity)
    final DoublePredicate isNegativeInfinity = TestHelper.doubleEquals(Double.NEGATIVE_INFINITY);
    final DoubleDoubleBiPredicate predicate = TestHelper.doublesAreClose(1e-8, 0).or(TestHelper.and(isNegativeInfinity, isNegativeInfinity));
    for (int x = min; x <= max; x++) {
        final double v1 = Math.log(f.likelihood(x, o));
        final double v2 = f.logLikelihood(x, o);
        // System.out.printf("x=%d, v1=%s, v2=%s%n", x, v1, v2);
        TestAssertions.assertTest(v1, v2, predicate, FunctionUtils.getSupplier("g=%f, mu=%f, x=%d", gain, mu, x));
    }
}
Also used : DoubleDoubleBiPredicate(uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate) DoublePredicate(uk.ac.sussex.gdsc.test.api.function.DoublePredicate)

Aggregations

DoubleDoubleBiPredicate (uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate)1 DoublePredicate (uk.ac.sussex.gdsc.test.api.function.DoublePredicate)1