Search in sources :

Example 11 with OptimizationSolverSpec

use of cbit.vcell.opt.OptimizationSolverSpec 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

OptimizationSolverSpec (cbit.vcell.opt.OptimizationSolverSpec)11 OptimizationResultSet (cbit.vcell.opt.OptimizationResultSet)10 OptimizationSpec (cbit.vcell.opt.OptimizationSpec)7 PowellOptimizationSolver (cbit.vcell.opt.solvers.PowellOptimizationSolver)7 DefaultOptSolverCallbacks (org.vcell.optimization.DefaultOptSolverCallbacks)7 OptSolverCallbacks (org.vcell.optimization.OptSolverCallbacks)7 OptSolverResultSet (cbit.vcell.opt.OptSolverResultSet)6 SimpleReferenceData (cbit.vcell.opt.SimpleReferenceData)5 CopasiOptimizationMethod (cbit.vcell.opt.CopasiOptimizationMethod)3 ExplicitFitObjectiveFunction (cbit.vcell.opt.ExplicitFitObjectiveFunction)3 DefaultScalarFunction (cbit.function.DefaultScalarFunction)2 Parameter (cbit.vcell.model.Parameter)2 CopasiOptimizationParameter (cbit.vcell.opt.CopasiOptimizationParameter)2 ImplicitObjectiveFunction (cbit.vcell.opt.ImplicitObjectiveFunction)2 Parameter (cbit.vcell.opt.Parameter)2 PdeObjectiveFunction (cbit.vcell.opt.PdeObjectiveFunction)2 ReferenceData (cbit.vcell.opt.ReferenceData)2 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)2 Element (org.jdom.Element)2 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1