List of usage examples for org.apache.commons.math3.analysis.solvers BracketingNthOrderBrentSolver BracketingNthOrderBrentSolver
public BracketingNthOrderBrentSolver(final double relativeAccuracy, final double absoluteAccuracy, final int maximalOrder) throws NumberIsTooSmallException
From source file:org.micromanager.asidispim.fit.Fitter.java
/** * Finds the x value corresponding to the maximum function value within the * range of the provided data set./* www.j a v a 2s.co m*/ * * @param type one of the Fitter.FunctionType predefined functions * @param parms parameters describing the function. These need to match the * selected function or an IllegalArgumentEception will be thrown * @param data JFreeChart series, used to bracket the range in which the * maximum will be found * * @return x value corresponding to the maximum function value */ public static double getXofMaxY(XYSeries data, FunctionType type, double[] parms) { double xAtMax = 0.0; double minX = data.getMinX(); double maxX = data.getMaxX(); switch (type) { case NoFit: // find the position in data with the highest y value double highestScore = data.getY(0).doubleValue(); int highestIndex = 0; for (int i = 1; i < data.getItemCount(); i++) { double newVal = data.getY(i).doubleValue(); if (newVal > highestScore) { highestScore = newVal; highestIndex = i; } } return data.getX(highestIndex).doubleValue(); case Pol1: case Pol2: case Pol3: checkParms(type, parms); PolynomialFunction derivativePolFunction = (new PolynomialFunction(parms)).polynomialDerivative(); final double relativeAccuracy = 1.0e-12; final double absoluteAccuracy = 1.0e-8; final int maxOrder = 5; UnivariateSolver solver = new BracketingNthOrderBrentSolver(relativeAccuracy, absoluteAccuracy, maxOrder); xAtMax = solver.solve(100, derivativePolFunction, minX, maxX); break; case Gaussian: // for a Gaussian we can take the mean and be sure it is the maximum // note that this may be outside our range of X values, but // this will be caught by our sanity checks below xAtMax = parms[1]; } // sanity checks if (xAtMax > maxX) xAtMax = maxX; if (xAtMax < minX) xAtMax = minX; return xAtMax; }