use of cbit.vcell.opt.OptimizationResultSet in project vcell by virtualcell.
the class ParameterEstimationTask method setOptimizationResultSet.
/**
* Sets the optimizationResultSet property (cbit.vcell.opt.OptimizationResultSet) value.
* @param optimizationResultSet The new value for the property.
* @see #getOptimizationResultSet
*/
public void setOptimizationResultSet(OptimizationResultSet optimizationResultSet) {
OptimizationResultSet oldValue = fieldOptimizationResultSet;
fieldOptimizationResultSet = optimizationResultSet;
firePropertyChange(PROPERTY_NAME_OPTIMIZATION_RESULT_SET, oldValue, optimizationResultSet);
}
use of cbit.vcell.opt.OptimizationResultSet in project vcell by virtualcell.
the class PowellOptimizationSolver method solve.
/**
* Insert the method's description here.
* Creation date: (3/5/00 11:15:15 PM)
* @return double[]
* @param optSpec cbit.vcell.opt.OptimizationSpec
* @exception java.io.IOException The exception description.
* @exception cbit.vcell.parser.ExpressionException The exception description.
* @exception cbit.vcell.opt.OptimizationException The exception description.
*/
public OptimizationResultSet solve(OptimizationSpec os, OptimizationSolverSpec optSolverSpec, OptSolverCallbacks optSolverCallbacks) throws java.io.IOException, cbit.vcell.parser.ExpressionException, OptimizationException {
final double power = 2.0;
final double MU_START = 0.1;
final double MU_END = 100000.0;
final double MU_STEP = 10.0;
AugmentedObjectiveFunction augmentedObjFunc = OptUtils.getAugmentedObjectiveFunction(os, power, MU_START, optSolverCallbacks);
//
// initialize starting guess
//
Parameter[] parameters = os.getParameters();
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]);
}
//
// get initial direction set
//
double[][] xi = new double[parameterValues.length][parameterValues.length];
for (int i = 0; i < parameterValues.length; i++) {
for (int j = 0; j < parameterValues.length; j++) {
xi[i][j] = (i == j ? 1.0 : 0.0);
}
}
final double ftol = 1e-6;
double fret = augmentedObjFunc.f(parameterValues);
PowellSolver powellSolver = new PowellSolver();
for (double mu = MU_START; mu <= MU_END; mu *= MU_STEP) {
try {
if (optSolverCallbacks.getStopRequested()) {
break;
}
augmentedObjFunc.setMu(mu);
fret = powellSolver.powell(parameterValues.length, parameterValues, xi, ftol, augmentedObjFunc);
System.out.println("mu=" + mu + ", function value=" + fret);
if (augmentedObjFunc.getPenalty(parameterValues) == 0.0) {
break;
}
} catch (Exception ex) {
ex.printStackTrace();
break;
}
}
OptimizationStatus optStatus = new OptimizationStatus(OptimizationStatus.NORMAL_TERMINATION, "Normal Termination");
ODESolverResultSet odeSolverResultSet = null;
if (optSolverCallbacks.getStopRequested()) {
optStatus = new OptimizationStatus(OptimizationStatus.STOPPED_BY_USER, "Stopped by user");
}
parameterValues = optSolverCallbacks.getBestEvaluation().getParameterValues();
fret = optSolverCallbacks.getBestEvaluation().getObjectiveFunctionValue();
odeSolverResultSet = optSolverCallbacks.getBestResultSet();
for (int i = 0; i < parameters.length; i++) {
System.out.println("final " + parameters[i].getName() + " = " + parameterValues[i]);
}
OptRunResultSet bestResult = new OptRunResultSet(parameterValues, new Double(fret), optSolverCallbacks.getEvaluationCount(), optStatus);
return new OptimizationResultSet(new OptSolverResultSet(os.getParameterNames(), bestResult), odeSolverResultSet);
}
use of cbit.vcell.opt.OptimizationResultSet 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;
}
use of cbit.vcell.opt.OptimizationResultSet 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;
}
use of cbit.vcell.opt.OptimizationResultSet 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