commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mister Mak <>
Subject [math] Struggling with opimization
Date Thu, 23 May 2013 13:40:44 GMT

I am new to Commons Math (3.2 on MacOS 10.5.8) and am struggling to
maximize a simple function.  I think I need to use the optimization
classes, but the user guide (
seems to refer mainly to functions that are deprecated according to the
API.  Mucking around through the API, I think I have found some other
functions that are not deprecated, but it's really not clear to me how to
use them.

What I have done so far is:

import org.apache.commons.math3.analysis.*;
import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.*;
import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction;
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType;

then somewhere I define a mutlivariate function:

class TestFcMulti implements MultivariateFunction {
    public double value(double[] par) {
        return - par[0] * par[0];

but then the following code does not work:

    public Test_MC() {

        TestFcMulti tf = new TestFcMulti();
        ObjectiveFunction obFc = new ObjectiveFunction(tf);
        SimplexOptimizer so = new SimplexOptimizer(0.01, 0.01);

        so.optimize(obFc, GoalType.MAXIMIZE); // Doesn't work
        so.optimize(); // Doesn't work

Is there a simple example somewhere, or can someone explain what to do?



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message