Search in sources :

Example 6 with OptimizationData

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

the class CustomPowellOptimizer method parseOptimizationData.

/**
	 * Scans the list of (required and optional) optimization data that
	 * characterize the problem.
	 *
	 * @param optData
	 *            Optimization data.
	 *            The following data will be looked for:
	 *            <ul>
	 *            <li>{@link PositionChecker}</li>
	 *            <li>{@link BasisStep}</li>
	 *            </ul>
	 */
@Override
protected void parseOptimizationData(OptimizationData... optData) {
    // Allow base class to register its own data.
    super.parseOptimizationData(optData);
    // not provided in the argument list.
    for (OptimizationData data : optData) {
        if (data instanceof PositionChecker) {
            positionChecker = (PositionChecker) data;
            continue;
        }
        if (data instanceof BasisStep) {
            basis = ((BasisStep) data).getStep();
            continue;
        }
    }
    checkParameters();
}
Also used : PositionChecker(org.apache.commons.math3.optim.PositionChecker) OptimizationData(org.apache.commons.math3.optim.OptimizationData)

Example 7 with OptimizationData

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

the class BFGSOptimizer method parseOptimizationData.

/**
	 * Scans the list of (required and optional) optimization data that
	 * characterize the problem.
	 *
	 * @param optData
	 *            Optimization data.
	 *            The following data will be looked for:
	 *            <ul>
	 *            <li>{@link GradientChecker}</li>
	 *            <li>{@link PositionChecker}</li>
	 *            <li>{@link MaximumStepLength}</li>
	 *            </ul>
	 */
@Override
protected void parseOptimizationData(OptimizationData... optData) {
    // Allow base class to register its own data.
    super.parseOptimizationData(optData);
    // not provided in the argument list.
    for (OptimizationData data : optData) {
        if (data instanceof PositionChecker) {
            positionChecker = (PositionChecker) data;
        } else if (data instanceof StepLength) {
            maximumStepLength = ((StepLength) data).getStep();
        } else if (data instanceof GradientTolerance) {
            gradientTolerance = ((GradientTolerance) data).getTolerance();
        } else if (data instanceof MaximumRestarts) {
            restarts = ((MaximumRestarts) data).getRestarts();
        } else if (data instanceof MaximumRoundoffRestarts) {
            roundoffRestarts = ((MaximumRoundoffRestarts) data).getRestarts();
        }
    }
    checkParameters();
}
Also used : PositionChecker(org.apache.commons.math3.optim.PositionChecker) OptimizationData(org.apache.commons.math3.optim.OptimizationData)

Example 8 with OptimizationData

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

the class BFGSOptimizer method checkParameters.

/**
	 * Checks if there are lower or upper bounds that are not -Infinity or +Infinity
	 * 
	 * @throws MathUnsupportedOperationException
	 *             if invalid bounds were passed to the {@link #optimize(OptimizationData[]) optimize} method.
	 */
private void checkParameters() {
    lower = getLowerBound();
    upper = getUpperBound();
    isLower = checkArray(lower, Double.NEGATIVE_INFINITY);
    isUpper = checkArray(upper, Double.POSITIVE_INFINITY);
    // Check that the upper bound is above the lower bound
    if (isUpper && isLower) {
        for (int i = 0; i < lower.length; i++) if (lower[i] > upper[i])
            throw new MathUnsupportedOperationException(createError("Lower bound must be below upper bound"));
    }
    // Numerical Recipes set the position convergence very low
    if (positionChecker == null)
        positionChecker = new PositionChecker(4 * epsilon, 0);
    // Ensure that the step length is strictly positive
    if (maximumStepLength == null) {
        for (int i = 0; i < maximumStepLength.length; i++) {
            if (maximumStepLength[i] <= 0)
                throw new MathUnsupportedOperationException(createError("Maximum step length must be strictly positive"));
        }
    }
// Set a tolerance? If not then the routine will iterate until position convergence
//if (gradientTolerance == 0)
//	gradientTolerance = 1e-6;
}
Also used : PositionChecker(org.apache.commons.math3.optim.PositionChecker) MathUnsupportedOperationException(org.apache.commons.math3.exception.MathUnsupportedOperationException)

Example 9 with OptimizationData

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

the class BoundedNonLinearConjugateGradientOptimizer method parseOptimizationData.

/**
	 * Scans the list of (required and optional) optimization data that
	 * characterize the problem.
	 *
	 * @param optData
	 *            Optimization data.
	 *            The following data will be looked for:
	 *            <ul>
	 *            <li>{@link BracketingStep}</li>
	 *            </ul>
	 */
@Override
protected void parseOptimizationData(OptimizationData... optData) {
    // Allow base class to register its own data.
    super.parseOptimizationData(optData);
    // not provided in the argument list.
    for (OptimizationData data : optData) {
        if (data instanceof BracketingStep) {
            initialStep = ((BracketingStep) data).getBracketingStep();
            // changed to "continue".
            break;
        }
    }
    checkParameters();
}
Also used : OptimizationData(org.apache.commons.math3.optim.OptimizationData)

Aggregations

OptimizationData (org.apache.commons.math3.optim.OptimizationData)8 TooManyEvaluationsException (org.apache.commons.math3.exception.TooManyEvaluationsException)5 TooManyIterationsException (org.apache.commons.math3.exception.TooManyIterationsException)5 InitialGuess (org.apache.commons.math3.optim.InitialGuess)5 MaxEval (org.apache.commons.math3.optim.MaxEval)5 PointValuePair (org.apache.commons.math3.optim.PointValuePair)5 SimpleBounds (org.apache.commons.math3.optim.SimpleBounds)5 ObjectiveFunction (org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction)5 CMAESOptimizer (org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CMAESOptimizer)5 ConvergenceException (org.apache.commons.math3.exception.ConvergenceException)4 PositionChecker (org.apache.commons.math3.optim.PositionChecker)3 SimpleValueChecker (org.apache.commons.math3.optim.SimpleValueChecker)3 CustomPowellOptimizer (org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CustomPowellOptimizer)3 RandomGenerator (org.apache.commons.math3.random.RandomGenerator)3 MultivariateMatrixFunction (org.apache.commons.math3.analysis.MultivariateMatrixFunction)2 LeastSquaresBuilder (org.apache.commons.math3.fitting.leastsquares.LeastSquaresBuilder)2 Optimum (org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum)2 LeastSquaresProblem (org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem)2 LevenbergMarquardtOptimizer (org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer)2 DiagonalMatrix (org.apache.commons.math3.linear.DiagonalMatrix)2