Example usage for org.apache.commons.math.analysis.integration RombergIntegrator RombergIntegrator

List of usage examples for org.apache.commons.math.analysis.integration RombergIntegrator RombergIntegrator

Introduction

In this page you can find the example usage for org.apache.commons.math.analysis.integration RombergIntegrator RombergIntegrator.

Prototype

public RombergIntegrator() 

Source Link

Document

Construct an integrator.

Usage

From source file:dr.math.distributions.ReflectedNormalDistribution.java

public static void main(String[] args) {

    //        final ReflectedNormalDistribution rnd = new ReflectedNormalDistribution(2, 2, 0.5, 2, 1e-6);
    final ReflectedNormalDistribution rnd = new ReflectedNormalDistribution(2, 2, 1, 2, 1e-6);

    rnd.pdf(1);// ww w  . j  a v  a2  s  .c  o m

    UnivariateRealFunction f = new UnivariateRealFunction() {
        public double value(double v) throws FunctionEvaluationException {
            return rnd.pdf(v);
        }
    };

    final UnivariateRealIntegrator integrator = new RombergIntegrator();
    integrator.setAbsoluteAccuracy(1e-14);
    integrator.setMaximalIterationCount(16); // fail if it takes too much time

    double x;
    try {
        x = integrator.integrate(f, rnd.lower, rnd.upper);
        //                      ptotErr += cdf != 0.0 ? Math.abs(x-cdf)/cdf : x;
        //                      np += 1;
        //assertTrue("" + shape + "," + scale + "," + value + " " + Math.abs(x-cdf)/x + "> 1e-6", Math.abs(1-cdf/x) < 1e-6);
        System.out.println("Integrated pdf = " + x);

        //System.out.println(shape + ","  + scale + " " + value);
    } catch (ConvergenceException e) {
        // can't integrate , skip test
        //  System.out.println(shape + ","  + scale + " skipped");
    } catch (FunctionEvaluationException e) {

        throw new RuntimeException("I have no idea why I am here.");

    }

}