Search in sources :

Example 16 with SimpleReferenceData

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

Aggregations

SimpleReferenceData (cbit.vcell.opt.SimpleReferenceData)16 ReferenceData (cbit.vcell.opt.ReferenceData)8 Element (org.jdom.Element)6 ODESolverResultSetColumnDescription (cbit.vcell.math.ODESolverResultSetColumnDescription)4 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)4 ExplicitFitObjectiveFunction (cbit.vcell.opt.ExplicitFitObjectiveFunction)4 OptimizationResultSet (cbit.vcell.opt.OptimizationResultSet)4 OptimizationSolverSpec (cbit.vcell.opt.OptimizationSolverSpec)4 OptimizationSpec (cbit.vcell.opt.OptimizationSpec)4 ExpressionException (cbit.vcell.parser.ExpressionException)4 Constraint (cbit.vcell.opt.Constraint)3 Parameter (cbit.vcell.opt.Parameter)3 SpatialReferenceData (cbit.vcell.opt.SpatialReferenceData)3 PowellOptimizationSolver (cbit.vcell.opt.solvers.PowellOptimizationSolver)3 Expression (cbit.vcell.parser.Expression)3 File (java.io.File)3 ParseException (java.text.ParseException)3 Vector (java.util.Vector)3 CSV (cbit.vcell.math.CSV)2 FunctionColumnDescription (cbit.vcell.math.FunctionColumnDescription)2