Search in sources :

Example 1 with Erf

use of org.apache.commons.math3.special.Erf in project GDSC-SMLM by aherbert.

the class ErfTest method erfxHasLowError.

private void erfxHasLowError(BaseErf erf, double expected) {
    RandomGenerator rg = new Well19937c(30051977);
    int range = 8;
    double max = 0;
    for (int xi = -range; xi <= range; xi++) {
        for (int i = 0; i < 5; i++) {
            double x = xi + rg.nextDouble();
            double o = erf.erf(x);
            double e = org.apache.commons.math3.special.Erf.erf(x);
            double error = Math.abs(o - e);
            if (max < error)
                max = error;
            //System.out.printf("x=%f, e=%f, o=%f, error=%f\n", x, e, o, error);
            Assert.assertTrue(error < expected);
        }
    }
    System.out.printf("erfx %s max error = %g\n", erf.name, max);
}
Also used : Well19937c(org.apache.commons.math3.random.Well19937c) RandomGenerator(org.apache.commons.math3.random.RandomGenerator)

Example 2 with Erf

use of org.apache.commons.math3.special.Erf in project GDSC-SMLM by aherbert.

the class ErfTest method erfxxHasLowError.

private void erfxxHasLowError(BaseErf erf, double expected) {
    RandomGenerator rg = new Well19937c(30051977);
    int range = 3;
    double max = 0;
    for (int xi = -range; xi <= range; xi++) {
        for (int xi2 = -range; xi2 <= range; xi2++) {
            for (int i = 0; i < 5; i++) {
                double x = xi + rg.nextDouble();
                for (int j = 0; j < 5; j++) {
                    double x2 = xi2 + rg.nextDouble();
                    double o = erf.erf(x, x2);
                    double e = org.apache.commons.math3.special.Erf.erf(x, x2);
                    double error = Math.abs(o - e);
                    if (max < error)
                        max = error;
                    //System.out.printf("x=%f, x2=%f, e=%f, o=%f, error=%f\n", x, x2, e, o, error);
                    Assert.assertTrue(error < expected);
                }
            }
        }
    }
    System.out.printf("erfxx %s max error = %g\n", erf.name, max);
}
Also used : Well19937c(org.apache.commons.math3.random.Well19937c) RandomGenerator(org.apache.commons.math3.random.RandomGenerator)

Aggregations

RandomGenerator (org.apache.commons.math3.random.RandomGenerator)2 Well19937c (org.apache.commons.math3.random.Well19937c)2