Search in sources :

Example 6 with DefaultOptSolverCallbacks

use of org.vcell.optimization.DefaultOptSolverCallbacks in project vcell by virtualcell.

the class AugmentedObjectiveFunctionTest method getExample2.

/**
 * Insert the method's description here.                    // Root-finding example
 * Creation date: (5/3/2002 2:49:06 PM)
 * @return opt.AugmentedObjectiveFunction
 */
public static AugmentedObjectiveFunction getExample2() {
    try {
        Expression scalarFn_exp = new Expression("1");
        Expression[] eqConstraints_exps = { new Expression("sin(x1+x2)-exp(x1-x2)"), new Expression("cos(x1+x2)-x1*x1*x2*x2") };
        Expression[] ineqConstraints_exps = {};
        String[] ids = { "x1", "x2" };
        ScalarFunction scalarFn = new DynamicScalarFunction(scalarFn_exp, ids);
        VectorFunction eqConstraints = new DynamicVectorFunction(eqConstraints_exps, ids);
        VectorFunction ineqConstraints = new DynamicVectorFunction(ineqConstraints_exps, ids);
        AugmentedObjectiveFunction aof = new AugmentedObjectiveFunction(scalarFn, eqConstraints, ineqConstraints, 2.0, 0.1, new DefaultOptSolverCallbacks());
        return aof;
    } catch (ExpressionException e) {
        e.printStackTrace();
        throw new RuntimeException(e.getMessage());
    }
}
Also used : DynamicScalarFunction(cbit.function.DynamicScalarFunction) DynamicScalarFunction(cbit.function.DynamicScalarFunction) ScalarFunction(cbit.function.ScalarFunction) Expression(cbit.vcell.parser.Expression) DefaultOptSolverCallbacks(org.vcell.optimization.DefaultOptSolverCallbacks) VectorFunction(cbit.function.VectorFunction) DynamicVectorFunction(cbit.function.DynamicVectorFunction) DynamicVectorFunction(cbit.function.DynamicVectorFunction) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 7 with DefaultOptSolverCallbacks

use of org.vcell.optimization.DefaultOptSolverCallbacks in project vcell by virtualcell.

the class CurveFitting method solve.

public static OptimizationResultSet solve(ExplicitFitObjectiveFunction.ExpressionDataPair[] expDataPairs, Parameter[] parameters, double[] time, double[][] data, String[] colNames, Weights weights) throws ExpressionException, OptimizationException, IOException {
    // choose optimization solver, currently we have Powell
    PowellOptimizationSolver optService = new PowellOptimizationSolver();
    OptimizationSpec optSpec = new OptimizationSpec();
    // create simple reference data, columns: t + dataColumns
    double[][] realData = new double[1 + data.length][time.length];
    for (// add time column
    int i = 0; // add time column
    i < time.length; // add time column
    i++) {
        realData[0][i] = time[i];
    }
    for (// add each data column to realData
    int i = 0; // add each data column to realData
    i < data.length; // add each data column to realData
    i++) {
        for (int j = 0; j < time.length; j++) {
            realData[1 + i][j] = data[i][j];
        }
    }
    SimpleReferenceData refData = new SimpleReferenceData(colNames, weights, realData);
    // send to optimization service
    optSpec.setObjectiveFunction(new ExplicitFitObjectiveFunction(expDataPairs, refData));
    double[] parameterValues = new double[parameters.length];
    for (int i = 0; i < parameters.length; i++) {
        parameterValues[i] = parameters[i].getInitialGuess();
        System.out.println("initial " + parameters[i].getName() + " = " + parameterValues[i] + ";\tLB = " + parameters[i].getLowerBound() + ";\tUB = " + parameters[i].getUpperBound());
    }
    // get the initial guess to send it to the f() function. ....
    for (int i = 0; i < parameters.length; i++) {
        optSpec.addParameter(parameters[i]);
    }
    // Parameters in OptimizationSolverSpec are solver type and objective function change tolerance.
    OptimizationSolverSpec optSolverSpec = new OptimizationSolverSpec(OptimizationSolverSpec.SOLVERTYPE_POWELL, 0.000001);
    OptSolverCallbacks optSolverCallbacks = new DefaultOptSolverCallbacks();
    OptimizationResultSet optResultSet = null;
    optResultSet = optService.solve(optSpec, optSolverSpec, optSolverCallbacks);
    return optResultSet;
}
Also used : PowellOptimizationSolver(cbit.vcell.opt.solvers.PowellOptimizationSolver) DefaultOptSolverCallbacks(org.vcell.optimization.DefaultOptSolverCallbacks) OptSolverCallbacks(org.vcell.optimization.OptSolverCallbacks) OptimizationResultSet(cbit.vcell.opt.OptimizationResultSet) ExplicitFitObjectiveFunction(cbit.vcell.opt.ExplicitFitObjectiveFunction) DefaultOptSolverCallbacks(org.vcell.optimization.DefaultOptSolverCallbacks) OptimizationSolverSpec(cbit.vcell.opt.OptimizationSolverSpec) OptimizationSpec(cbit.vcell.opt.OptimizationSpec) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData)

Example 8 with DefaultOptSolverCallbacks

use of org.vcell.optimization.DefaultOptSolverCallbacks in project vcell by virtualcell.

the class CurveFitting method solve.

public static OptimizationResultSet solve(ExplicitFitObjectiveFunction.ExpressionDataPair[] expDataPairs, Parameter[] parameters, double[] time, double[][] data, String[] colNames, Weights weights) throws ExpressionException, OptimizationException, IOException {
    // choose optimization solver, currently we have Powell and CFSQP
    PowellOptimizationSolver optService = new PowellOptimizationSolver();
    OptimizationSpec optSpec = new OptimizationSpec();
    // create simple reference data, columns: t + dataColumns
    double[][] realData = new double[1 + data.length][time.length];
    for (// add time column
    int i = 0; // add time column
    i < time.length; // add time column
    i++) {
        realData[0][i] = time[i];
    }
    for (// add each data column to realData
    int i = 0; // add each data column to realData
    i < data.length; // add each data column to realData
    i++) {
        for (int j = 0; j < time.length; j++) {
            realData[1 + i][j] = data[i][j];
        }
    }
    SimpleReferenceData refData = new SimpleReferenceData(colNames, weights, realData);
    // send to optimization service
    optSpec.setObjectiveFunction(new ExplicitFitObjectiveFunction(expDataPairs, refData));
    double[] parameterValues = new double[parameters.length];
    for (int i = 0; i < parameters.length; i++) {
        parameterValues[i] = parameters[i].getInitialGuess();
        System.out.println("initial " + parameters[i].getName() + " = " + parameterValues[i] + ";\tLB = " + parameters[i].getLowerBound() + ";\tUB = " + parameters[i].getUpperBound());
    }
    // get the initial guess to send it to the f() function. ....
    for (int i = 0; i < parameters.length; i++) {
        optSpec.addParameter(parameters[i]);
    }
    // Parameters in OptimizationSolverSpec are solver type and objective function change tolerance.
    OptimizationSolverSpec optSolverSpec = new OptimizationSolverSpec(OptimizationSolverSpec.SOLVERTYPE_POWELL, 0.000001);
    OptSolverCallbacks optSolverCallbacks = new DefaultOptSolverCallbacks();
    OptimizationResultSet optResultSet = null;
    optResultSet = optService.solve(optSpec, optSolverSpec, optSolverCallbacks);
    return optResultSet;
}
Also used : PowellOptimizationSolver(cbit.vcell.opt.solvers.PowellOptimizationSolver) DefaultOptSolverCallbacks(org.vcell.optimization.DefaultOptSolverCallbacks) OptSolverCallbacks(org.vcell.optimization.OptSolverCallbacks) OptimizationResultSet(cbit.vcell.opt.OptimizationResultSet) ExplicitFitObjectiveFunction(cbit.vcell.opt.ExplicitFitObjectiveFunction) DefaultOptSolverCallbacks(org.vcell.optimization.DefaultOptSolverCallbacks) OptimizationSolverSpec(cbit.vcell.opt.OptimizationSolverSpec) OptimizationSpec(cbit.vcell.opt.OptimizationSpec) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData)

Example 9 with DefaultOptSolverCallbacks

use of org.vcell.optimization.DefaultOptSolverCallbacks in project vcell by virtualcell.

the class CurveFitting method solveSpatial.

public static OptimizationResultSet solveSpatial(Simulation sim, Parameter[] parameters, SpatialReferenceData refData, File dataDir, FieldDataIdentifierSpec[] fieldDataIDSs) throws ExpressionException, OptimizationException, IOException {
    // choose optimization solver, currently we have Powell and CFSQP
    PowellOptimizationSolver optService = new PowellOptimizationSolver();
    OptimizationSpec optSpec = new OptimizationSpec();
    // send to optimization service
    optSpec.setObjectiveFunction(new PdeObjectiveFunction(sim.getMathDescription(), refData, dataDir, fieldDataIDSs));
    double[] parameterValues = new double[parameters.length];
    for (int i = 0; i < parameters.length; i++) {
        parameterValues[i] = parameters[i].getInitialGuess();
        System.out.println("initial " + parameters[i].getName() + " = " + parameterValues[i] + ";\tLB = " + parameters[i].getLowerBound() + ";\tUB = " + parameters[i].getUpperBound());
    }
    // get the initial guess to send it to the f() function. ....
    for (int i = 0; i < parameters.length; i++) {
        optSpec.addParameter(parameters[i]);
    }
    // Parameters in OptimizationSolverSpec are solver type and objective function change tolerance.
    OptimizationSolverSpec optSolverSpec = new OptimizationSolverSpec(OptimizationSolverSpec.SOLVERTYPE_POWELL, 0.000001);
    OptSolverCallbacks optSolverCallbacks = new DefaultOptSolverCallbacks();
    OptimizationResultSet optResultSet = null;
    optResultSet = optService.solve(optSpec, optSolverSpec, optSolverCallbacks);
    OptSolverResultSet optSolverResultSet = optResultSet.getOptSolverResultSet();
    String[] paramNames = optSolverResultSet.getParameterNames();
    double[] paramValues = optSolverResultSet.getBestEstimates();
    for (int i = 0; i < paramNames.length; i++) {
        System.out.println("finally:   " + paramNames[i] + " = " + paramValues[i]);
    }
    return optResultSet;
}
Also used : PowellOptimizationSolver(cbit.vcell.opt.solvers.PowellOptimizationSolver) DefaultOptSolverCallbacks(org.vcell.optimization.DefaultOptSolverCallbacks) OptSolverCallbacks(org.vcell.optimization.OptSolverCallbacks) OptimizationResultSet(cbit.vcell.opt.OptimizationResultSet) PdeObjectiveFunction(cbit.vcell.opt.PdeObjectiveFunction) DefaultOptSolverCallbacks(org.vcell.optimization.DefaultOptSolverCallbacks) OptimizationSolverSpec(cbit.vcell.opt.OptimizationSolverSpec) OptimizationSpec(cbit.vcell.opt.OptimizationSpec) OptSolverResultSet(cbit.vcell.opt.OptSolverResultSet)

Aggregations

DefaultOptSolverCallbacks (org.vcell.optimization.DefaultOptSolverCallbacks)9 OptimizationResultSet (cbit.vcell.opt.OptimizationResultSet)7 OptimizationSolverSpec (cbit.vcell.opt.OptimizationSolverSpec)7 OptimizationSpec (cbit.vcell.opt.OptimizationSpec)7 PowellOptimizationSolver (cbit.vcell.opt.solvers.PowellOptimizationSolver)7 OptSolverCallbacks (org.vcell.optimization.OptSolverCallbacks)7 OptSolverResultSet (cbit.vcell.opt.OptSolverResultSet)4 ExplicitFitObjectiveFunction (cbit.vcell.opt.ExplicitFitObjectiveFunction)3 SimpleReferenceData (cbit.vcell.opt.SimpleReferenceData)3 Expression (cbit.vcell.parser.Expression)3 DefaultScalarFunction (cbit.function.DefaultScalarFunction)2 DynamicScalarFunction (cbit.function.DynamicScalarFunction)2 DynamicVectorFunction (cbit.function.DynamicVectorFunction)2 ScalarFunction (cbit.function.ScalarFunction)2 VectorFunction (cbit.function.VectorFunction)2 ImplicitObjectiveFunction (cbit.vcell.opt.ImplicitObjectiveFunction)2 Parameter (cbit.vcell.opt.Parameter)2 PdeObjectiveFunction (cbit.vcell.opt.PdeObjectiveFunction)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 ProfileDistribution (cbit.vcell.opt.OptSolverResultSet.ProfileDistribution)1