Example usage for org.apache.commons.math.optimization.direct PowellOptimizer setMaxEvaluations

List of usage examples for org.apache.commons.math.optimization.direct PowellOptimizer setMaxEvaluations

Introduction

In this page you can find the example usage for org.apache.commons.math.optimization.direct PowellOptimizer setMaxEvaluations.

Prototype

public void setMaxEvaluations(int maxEvaluations) 

Source Link

Usage

From source file:Align_Projections.java

public void run() {

    detectorAngle = Double.valueOf(detectorAngleText.getText()).doubleValue();
    centerPixel = Double.valueOf(centerPixelText.getText()).doubleValue();
    horizontalBorder = Integer.valueOf(horizontalBorderText.getText()).intValue();
    topBorder = Integer.valueOf(topBorderText.getText()).intValue();
    bottomBorder = Integer.valueOf(bottomBorderText.getText()).intValue();

    // IJ.log("Starting worker thread");
    int count = 0;
    double[] x = new double[2];
    x[0] = centerPixel * tuningWeights[0];
    x[1] = detectorAngle * tuningWeights[1];
    PowellOptimizer maximizer = new PowellOptimizer(1E-4);
    maximizer.setConvergenceChecker(new ConvergenceCheckerWithManualCancel(this, 1E-4, 1E-4));
    maximizer.setMaxEvaluations(1000000);
    maximizer.setMaxIterations(1000000);
    try {// w  w  w  . j av  a2  s.co  m
        // IJ.log("Starting optimization first round");
        RealPointValuePair result = maximizer.optimize(this, GoalType.MAXIMIZE, x);
        centerPixel = result.getPoint()[0] / tuningWeights[0];
        detectorAngle = result.getPoint()[1] / tuningWeights[1];
        centerPixelText.setText(IJ.d2s(centerPixel, 6));
        detectorAngleText.setText(IJ.d2s(detectorAngle, 6));
        crossCorrelation = result.getValue();
        updateCrossCorrelation();
    } catch (GetMeOuttaHereException e) {
    } catch (Exception e) {
        IJ.log("Exception occurred in optimizer.");
        stopTuning = true;
    }
    // Now do the whole thing again, but with narrower tolerances (the defaults, which are roughly machine precision)
    if (!stopTuning) {
        maximizer = new PowellOptimizer();
        maximizer.setConvergenceChecker(new ConvergenceCheckerWithManualCancel(this));
        maximizer.setMaxEvaluations(1000000);
        maximizer.setMaxIterations(1000000);
        try {
            // IJ.log("Starting optimization second round");
            RealPointValuePair result = maximizer.optimize(this, GoalType.MAXIMIZE, x);
            centerPixel = result.getPoint()[0] / tuningWeights[0];
            detectorAngle = result.getPoint()[1] / tuningWeights[1];
            centerPixelText.setText(IJ.d2s(centerPixel, 6));
            detectorAngleText.setText(IJ.d2s(detectorAngle, 6));
            crossCorrelation = result.getValue();
            updateCrossCorrelation();
        } catch (GetMeOuttaHereException e) {
        } catch (Exception e) {
            IJ.log("Exception occurred in optimizer.");
        }
    }

    UpdateOverlayAndControls();
    optimizeButton.setLabel("Optimize");
    optimizeButton.setEnabled(true);
    updateButton.setEnabled(true);
    applyButton.setEnabled(true);
    resetButton.setEnabled(true);
    detectorAngleText.setEnabled(true);
    centerPixelText.setEnabled(true);
    horizontalBorderText.setEnabled(true);
    topBorderText.setEnabled(true);
    bottomBorderText.setEnabled(true);
    // IJ.log("Exiting worker thread");
}