Search in sources :

Example 1 with NonLinearConjugateGradientOptimizer

use of org.apache.commons.math3.optim.nonlinear.scalar.gradient.NonLinearConjugateGradientOptimizer in project aic-praise by aic-sri-international.

the class RegularParameterEstimation method optimizeModel.

/**
 * Call the optimizer of Java Commons Math.
 */
public PointValuePair optimizeModel() {
    NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, new SimpleValueChecker(1e-13, 1e-13));
    final LoglikelihoodToOptimize f = new LoglikelihoodToOptimize(expressionBasedModel, queries);
    final GradientLoglikelihoodToOptimize gradientToOptimize = new GradientLoglikelihoodToOptimize(expressionBasedModel, queries);
    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) 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) ObjectiveFunctionGradient(org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunctionGradient) PointValuePair(org.apache.commons.math3.optim.PointValuePair)

Example 2 with NonLinearConjugateGradientOptimizer

use of org.apache.commons.math3.optim.nonlinear.scalar.gradient.NonLinearConjugateGradientOptimizer 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)

Example 3 with NonLinearConjugateGradientOptimizer

use of org.apache.commons.math3.optim.nonlinear.scalar.gradient.NonLinearConjugateGradientOptimizer in project aic-expresso by aic-sri-international.

the class OptimizationWithNonlinearConjugateGradientDescent method optimize.

/**
 * Main method. It computes the optimum of the function and returns a PointValuePair which contains the argopt and the optimum.
 * Both can be computed directly with findOptimum and findArgopt.
 */
public PointValuePair optimize(NonLinearConjugateGradientOptimizer optimizer) {
    final FunctionToOptimize f = new FunctionToOptimize(this.expressionToOptimize);
    final FunctionToOptimizeGradient gradient = new FunctionToOptimizeGradient(expressionToOptimize);
    ObjectiveFunction objectiveFunction = new ObjectiveFunction(f);
    MultivariateVectorFunction gradientMultivariateFunction = gradient;
    ObjectiveFunctionGradient objectiveFunctionGradient = new ObjectiveFunctionGradient(gradientMultivariateFunction);
    final PointValuePair optimum = optimizer.optimize(this.maxEval, objectiveFunction, objectiveFunctionGradient, this.goalType, this.initialGuess);
    return optimum;
}
Also used : ObjectiveFunction(org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction) MultivariateVectorFunction(org.apache.commons.math3.analysis.MultivariateVectorFunction) ObjectiveFunctionGradient(org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunctionGradient) PointValuePair(org.apache.commons.math3.optim.PointValuePair)

Aggregations

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