Example usage for org.apache.commons.math FunctionEvaluationException FunctionEvaluationException

List of usage examples for org.apache.commons.math FunctionEvaluationException FunctionEvaluationException

Introduction

In this page you can find the example usage for org.apache.commons.math FunctionEvaluationException FunctionEvaluationException.

Prototype

public FunctionEvaluationException(Throwable cause, double[] argument) 

Source Link

Document

Constructs an exception with specified root cause.

Usage

From source file:OughtaFocus.java

private double runAutofocusAlgorithm() throws Exception {
    UnivariateRealFunction scoreFun = new UnivariateRealFunction() {
        public double value(double d) throws FunctionEvaluationException {
            try {
                return measureFocusScore(d);
            } catch (Exception e) {
                throw new FunctionEvaluationException(e, d);
            }/*from   w  ww . ja v  a  2  s  . c  om*/
        }
    };
    BrentOptimizer brentOptimizer = new BrentOptimizer();
    brentOptimizer.setAbsoluteAccuracy(tolerance);
    imageCount_ = 0;

    CMMCore core = app_.getMMCore();
    double z = core.getPosition(core.getFocusDevice());
    startZUm_ = z;
    //      getCurrentFocusScore();
    double zResult = brentOptimizer.optimize(scoreFun, GoalType.MAXIMIZE, z - searchRange / 2,
            z + searchRange / 2);
    ReportingUtils.logMessage("OughtaFocus Iterations: " + brentOptimizer.getIterationCount() + ", z="
            + TextUtils.FMT2.format(zResult) + ", dz=" + TextUtils.FMT2.format(zResult - startZUm_) + ", t="
            + (System.currentTimeMillis() - startTimeMs_));
    return zResult;
}