Example usage for org.apache.commons.math3.geometry.euclidean.oned Interval getInf

List of usage examples for org.apache.commons.math3.geometry.euclidean.oned Interval getInf

Introduction

In this page you can find the example usage for org.apache.commons.math3.geometry.euclidean.oned Interval getInf.

Prototype

public double getInf() 

Source Link

Document

Get the lower bound of the interval.

Usage

From source file:com.google.cloud.genomics.dataflow.functions.verifybamid.Solver.java

/**
 * Maximizes a univariate function using a grid search followed by Brent's algorithm.
 *
 * @param fn the likelihood function to minimize
 * @param gridStart the lower bound for the grid search
 * @param gridEnd the upper bound for the grid search
 * @param gridStep step size for the grid search
 * @param relErr relative error tolerance for Brent's algorithm
 * @param absErr absolute error tolerance for Brent's algorithm
 * @param maxIter maximum # of iterations to perform in Brent's algorithm
 * @param maxEval maximum # of Likelihood function evaluations in Brent's algorithm
 *
 * @return the value of the parameter that maximizes the function
 *//*w  ww .j  av  a  2  s .c o m*/
public static double maximize(UnivariateFunction fn, double gridStart, double gridEnd, double gridStep,
        double relErr, double absErr, int maxIter, int maxEval) {
    Interval interval = gridSearch(fn, gridStart, gridEnd, gridStep);
    BrentOptimizer bo = new BrentOptimizer(relErr, absErr);
    UnivariatePointValuePair max = bo.optimize(new MaxIter(maxIter), new MaxEval(maxEval),
            new SearchInterval(interval.getInf(), interval.getSup()), new UnivariateObjectiveFunction(fn),
            GoalType.MAXIMIZE);
    return max.getPoint();
}

From source file:com.google.cloud.genomics.dataflow.functions.verifybamid.SolverTest.java

@Test
public void testGridSearch() {
    Interval interval = Solver.gridSearch(new Parabola(0.25), 0.0, 1.0, 0.1);
    assertEquals(Precision.compareTo(interval.getInf(), 0.1, 1), 0);
    assertEquals(Precision.compareTo(interval.getSup(), 0.3, 1), 0);

    interval = Solver.gridSearch(new Parabola(1.2), 0.0, 1.0, 0.1);
    assertEquals(Precision.compareTo(interval.getInf(), 0.9, 1), 0);
    assertEquals(Precision.compareTo(interval.getSup(), 1.0, 1), 0);

    interval = Solver.gridSearch(new Parabola(1.2), 0.0, 1.0, 0.3);
    assertEquals(Precision.compareTo(interval.getInf(), 0.9, 1), 0);
    assertEquals(Precision.compareTo(interval.getSup(), 1.0, 1), 0);
}