Example usage for org.apache.commons.math3.optimization.direct SimplexOptimizer SimplexOptimizer

List of usage examples for org.apache.commons.math3.optimization.direct SimplexOptimizer SimplexOptimizer

Introduction

In this page you can find the example usage for org.apache.commons.math3.optimization.direct SimplexOptimizer SimplexOptimizer.

Prototype

public SimplexOptimizer(double rel, double abs) 

Source Link

Usage

From source file:edu.stanford.cfuller.imageanalysistools.fitting.GaussianFitter3D.java

/**
 * Fits a 3D Gaussian to a supplied object, starting from an initial guess of the parameters of that Gaussian.
 *
 * The Gaussian is contrained to be symmetric in the x and y dimensions (that is, it will have equal variance in both dimensions).
 *
 * @param toFit         The {@link ImageObject} to be fit to a Gaussian.
 * @param initialGuess  The initial guess at the parameters of the Gaussian.  These must be supplied in the order: amplitude, x-y stddev, z stddev, x position, y position, z position, background.  Positions should be supplied in absolute coordinates from the original image, not relative to the box around the object being fit.
 * @param ppg           The number of photons corresponding to one greylevel in the original image.
 * @return              The best fit Gaussian parameters, in the same order as the initial guess had to be supplied.
 *///from   www. j a va 2  s  . c  o  m
public RealVector fit(ImageObject toFit, RealVector initialGuess, double ppg) {

    //parameter ordering: amplitude, stddev x-y, stddev z, x/y/z coords, background

    double tol = 1.0e-6;

    SimplexOptimizer nmm = new SimplexOptimizer(tol, tol);

    NelderMeadSimplex nms = new NelderMeadSimplex(initialGuess.getDimension());

    nmm.setSimplex(nms);

    PointValuePair pvp = nmm.optimize(10000000, new MLObjectiveFunction(toFit, ppg),
            org.apache.commons.math3.optimization.GoalType.MINIMIZE, initialGuess.toArray());

    RealVector result = new ArrayRealVector(pvp.getPoint());

    return result;

}