Search in sources :

Example 1 with FunctionToOptimize

use of com.sri.ai.expresso.optimization.FunctionToOptimize in project aic-praise by aic-sri-international.

the class RegularSymbolicParameterEstimation method optimize.

/**
 * Call the optimizer of Java Commons Math with the objectiveFunction and the gradient given in the arguments.
 */
public PointValuePair optimize(Expression expressionToOptimize, Vector<Expression> gradient) {
    NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, new SimpleValueChecker(1e-13, 1e-13));
    final FunctionToOptimize f = new FunctionToOptimize(expressionToOptimize);
    final GradientToOptimize gradientToOptimize = new GradientToOptimize(expressionToOptimize, gradient);
    ObjectiveFunction objectiveFunction = new ObjectiveFunction(f);
    MultivariateVectorFunction gradientMultivariateFunction = gradientToOptimize;
    ObjectiveFunctionGradient objectiveFunctionGradient = new ObjectiveFunctionGradient(gradientMultivariateFunction);
    double[] startPoint = new double[] { 0.5, 0.5 };
    final PointValuePair optimum = optimizer.optimize(new MaxEval(10000), objectiveFunction, objectiveFunctionGradient, GoalType.MAXIMIZE, new InitialGuess(startPoint));
    return optimum;
}
Also used : MaxEval(org.apache.commons.math3.optim.MaxEval) InitialGuess(org.apache.commons.math3.optim.InitialGuess) GradientToOptimize(com.sri.ai.expresso.optimization.GradientToOptimize) ObjectiveFunction(org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction) NonLinearConjugateGradientOptimizer(org.apache.commons.math3.optim.nonlinear.scalar.gradient.NonLinearConjugateGradientOptimizer) SimpleValueChecker(org.apache.commons.math3.optim.SimpleValueChecker) MultivariateVectorFunction(org.apache.commons.math3.analysis.MultivariateVectorFunction) FunctionToOptimize(com.sri.ai.expresso.optimization.FunctionToOptimize) ObjectiveFunctionGradient(org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunctionGradient) PointValuePair(org.apache.commons.math3.optim.PointValuePair)

Aggregations

FunctionToOptimize (com.sri.ai.expresso.optimization.FunctionToOptimize)1 GradientToOptimize (com.sri.ai.expresso.optimization.GradientToOptimize)1 MultivariateVectorFunction (org.apache.commons.math3.analysis.MultivariateVectorFunction)1 InitialGuess (org.apache.commons.math3.optim.InitialGuess)1 MaxEval (org.apache.commons.math3.optim.MaxEval)1 PointValuePair (org.apache.commons.math3.optim.PointValuePair)1 SimpleValueChecker (org.apache.commons.math3.optim.SimpleValueChecker)1 ObjectiveFunction (org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction)1 ObjectiveFunctionGradient (org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunctionGradient)1 NonLinearConjugateGradientOptimizer (org.apache.commons.math3.optim.nonlinear.scalar.gradient.NonLinearConjugateGradientOptimizer)1