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

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

Introduction

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

Prototype

public Interval(final double lower, final double upper) 

Source Link

Document

Simple constructor.

Usage

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

/**
 * Runs a grid search for the maximum value of a univariate function.
 * /*  ww  w .  j  a  va 2 s  .co  m*/
 * @param fn the likelihood function to minimize
 * @param start lower bound of the interval to search
 * @param end upper bound of the interval to search
 * @param step grid step size
 * @return an Interval bracketing the minimum
 */
static Interval gridSearch(UnivariateFunction fn, double start, double end, double step) {
    double lowMax = start; // lower bound on interval surrounding alphaMax
    double alphaMax = start - step;
    double likMax = 0.0;

    double lastAlpha = start;
    double alpha = start;
    while (alpha < end) {
        double likelihood = fn.value(alpha);
        if (alphaMax < start || likelihood > likMax) {
            lowMax = lastAlpha;
            alphaMax = alpha;
            likMax = likelihood;
        }
        lastAlpha = alpha;
        alpha += step;
    }
    // make sure we've checked the rightmost endpoint (won't happen if 
    // end - start is not an integer multiple of step, because of roundoff
    // errors, etc)
    double likelihood = fn.value(end);
    if (likelihood > likMax) {
        lowMax = lastAlpha;
        alphaMax = end;
        likMax = likelihood;
    }
    return new Interval(lowMax, Math.min(end, alphaMax + step));
}

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

/**
 * Runs a grid search for the maximum value of a univariate function.
 *
 * @param fn the likelihood function to minimize
 * @param start lower bound of the interval to search
 * @param end upper bound of the interval to search
 * @param step grid step size/*ww  w  .  ja v a  2s  .  co m*/
 * @return an Interval bracketing the minimum
 */
static Interval gridSearch(UnivariateFunction fn, double start, double end, double step) {
    double lowMax = start; // lower bound on interval surrounding alphaMax
    double alphaMax = start - step;
    double likMax = 0.0;

    double lastAlpha = start;
    double alpha = start;
    while (alpha < end) {
        double likelihood = fn.value(alpha);
        if (alphaMax < start || likelihood > likMax) {
            lowMax = lastAlpha;
            alphaMax = alpha;
            likMax = likelihood;
        }
        lastAlpha = alpha;
        alpha += step;
    }
    // make sure we've checked the rightmost endpoint (won't happen if
    // end - start is not an integer multiple of step, because of roundoff
    // errors, etc)
    double likelihood = fn.value(end);
    if (likelihood > likMax) {
        lowMax = lastAlpha;
        alphaMax = end;
        likMax = likelihood;
    }
    return new Interval(lowMax, Math.min(end, alphaMax + step));
}