Search in sources :

Example 1 with BracketFinder

use of org.apache.commons.math3.optim.univariate.BracketFinder in project GDSC-SMLM by aherbert.

the class FIRE method findMin.

private UnivariatePointValuePair findMin(UnivariatePointValuePair current, UnivariateOptimizer o, UnivariateFunction f, double qValue, double factor) {
    try {
        BracketFinder bracket = new BracketFinder();
        bracket.search(f, GoalType.MINIMIZE, qValue * factor, qValue / factor);
        UnivariatePointValuePair next = o.optimize(GoalType.MINIMIZE, new MaxEval(3000), new SearchInterval(bracket.getLo(), bracket.getHi(), bracket.getMid()), new UnivariateObjectiveFunction(f));
        if (next == null)
            return current;
        //System.out.printf("LineMin [%.1f]  %f = %f\n", factor, next.getPoint(), next.getValue());
        if (current != null)
            return (next.getValue() < current.getValue()) ? next : current;
        return next;
    } catch (Exception e) {
        return current;
    }
}
Also used : MaxEval(org.apache.commons.math3.optim.MaxEval) SearchInterval(org.apache.commons.math3.optim.univariate.SearchInterval) UnivariateObjectiveFunction(org.apache.commons.math3.optim.univariate.UnivariateObjectiveFunction) BracketFinder(org.apache.commons.math3.optim.univariate.BracketFinder) UnivariatePointValuePair(org.apache.commons.math3.optim.univariate.UnivariatePointValuePair) TooManyEvaluationsException(org.apache.commons.math3.exception.TooManyEvaluationsException)

Example 2 with BracketFinder

use of org.apache.commons.math3.optim.univariate.BracketFinder in project GDSC-SMLM by aherbert.

the class Fire method findMin.

private static UnivariatePointValuePair findMin(UnivariatePointValuePair current, UnivariateOptimizer optimiser, UnivariateFunction func, double qvalue, double factor) {
    try {
        final BracketFinder bracket = new BracketFinder();
        bracket.search(func, GoalType.MINIMIZE, qvalue * factor, qvalue / factor);
        final UnivariatePointValuePair next = optimiser.optimize(GoalType.MINIMIZE, new MaxEval(3000), new SearchInterval(bracket.getLo(), bracket.getHi(), bracket.getMid()), new UnivariateObjectiveFunction(func));
        if (next == null) {
            return current;
        }
        if (current != null) {
            return (next.getValue() < current.getValue()) ? next : current;
        }
        return next;
    } catch (final Exception ex) {
        return current;
    }
}
Also used : MaxEval(org.apache.commons.math3.optim.MaxEval) SearchInterval(org.apache.commons.math3.optim.univariate.SearchInterval) UnivariateObjectiveFunction(org.apache.commons.math3.optim.univariate.UnivariateObjectiveFunction) BracketFinder(org.apache.commons.math3.optim.univariate.BracketFinder) UnivariatePointValuePair(org.apache.commons.math3.optim.univariate.UnivariatePointValuePair) DataException(uk.ac.sussex.gdsc.core.data.DataException) ConversionException(uk.ac.sussex.gdsc.core.data.utils.ConversionException)

Aggregations

MaxEval (org.apache.commons.math3.optim.MaxEval)2 BracketFinder (org.apache.commons.math3.optim.univariate.BracketFinder)2 SearchInterval (org.apache.commons.math3.optim.univariate.SearchInterval)2 UnivariateObjectiveFunction (org.apache.commons.math3.optim.univariate.UnivariateObjectiveFunction)2 UnivariatePointValuePair (org.apache.commons.math3.optim.univariate.UnivariatePointValuePair)2 TooManyEvaluationsException (org.apache.commons.math3.exception.TooManyEvaluationsException)1 DataException (uk.ac.sussex.gdsc.core.data.DataException)1 ConversionException (uk.ac.sussex.gdsc.core.data.utils.ConversionException)1