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;
}
Aggregations