Search in sources :

Example 1 with DefaultScalarFunction

use of cbit.function.DefaultScalarFunction in project vcell by virtualcell.

the class FRAPOptimizationUtils method estimate.

// estimate best parameters and return the least error
public static double estimate(FRAPOptData argOptData, Parameter[] inParams, String[] outParaNames, double[] outParaVals, boolean[] eoi) throws Exception {
    /*PowellSolver  solver = new PowellSolver();
		LookupTableObjectiveFunction func = new LookupTableObjectiveFunction(argOptData);
		
		//best point found. we have only one dimension here.
		double[] p = new double[1];
		p[0] = iniDiffGuess;
		//current direction set
		double[][] xi = new double[1][1];
		for (int i=0;i<1;i++)
		{
		   for (int j=0;j<1;j++)
		   {
		       xi[i][j]=(i == j ? 1.0 : 0.0);
		   }
		}
		//run powell with initial guess, initial direction set and objective function
		double minError = solver.powell(1, p, xi, FTOL, func);
		parameters[FRAPOptData.idxOptDiffRate] = p[0];
		parameters[FRAPOptData.idxMinError] = minError;*/
    // long startTime =System.currentTimeMillis();
    // create optimization solver
    PowellOptimizationSolver optSolver = new PowellOptimizationSolver();
    // create optimization spec
    OptimizationSpec optSpec = new OptimizationSpec();
    // add opt function
    DefaultScalarFunction scalarFunc = new LookupTableObjectiveFunction(argOptData, eoi);
    optSpec.setObjectiveFunction(new ImplicitObjectiveFunction(scalarFunc));
    // create solver spec
    OptimizationSolverSpec optSolverSpec = new OptimizationSolverSpec(OptimizationSolverSpec.SOLVERTYPE_POWELL, FRAPOptimizationUtils.FTOL);
    // create solver call back
    OptSolverCallbacks optSolverCallbacks = new DefaultOptSolverCallbacks();
    // create optimization result set
    OptimizationResultSet optResultSet = null;
    for (int i = 0; i < inParams.length; i++) {
        // add parameters
        optSpec.addParameter(inParams[i]);
    }
    optResultSet = optSolver.solve(optSpec, optSolverSpec, optSolverCallbacks);
    OptSolverResultSet optSolverResultSet = optResultSet.getOptSolverResultSet();
    // if the parameters are 5, we have to go over again to see if we get the best answer.
    if (// 5 parameters
    inParams.length == 5) {
        OptimizationSpec optSpec2 = new OptimizationSpec();
        optSpec2.setObjectiveFunction(new ImplicitObjectiveFunction(scalarFunc));
        Parameter[] inParamsFromResult = generateInParamSet(inParams, optSolverResultSet.getBestEstimates());
        for (int i = 0; i < inParamsFromResult.length; i++) {
            // add parameters
            optSpec2.addParameter(inParamsFromResult[i]);
        }
        OptimizationResultSet tempOptResultSet = optSolver.solve(optSpec2, optSolverSpec, optSolverCallbacks);
        OptSolverResultSet tempOptSolverResultSet = tempOptResultSet.getOptSolverResultSet();
        if (optSolverResultSet.getLeastObjectiveFunctionValue() > tempOptSolverResultSet.getLeastObjectiveFunctionValue()) {
            optSolverResultSet = tempOptSolverResultSet;
        }
    }
    // System.out.println("obj function value:"+optResultSet.getObjectiveFunctionValue());
    // System.out.println("");
    // copy results to output parameters
    String[] names = optSolverResultSet.getParameterNames();
    double[] values = optSolverResultSet.getBestEstimates();
    for (int i = 0; i < names.length; i++) {
        outParaNames[i] = names[i];
        outParaVals[i] = values[i];
    }
    // System.out.println("total: " + ( endTime - startTime) );
    return optSolverResultSet.getLeastObjectiveFunctionValue();
}
Also used : PowellOptimizationSolver(cbit.vcell.opt.solvers.PowellOptimizationSolver) DefaultOptSolverCallbacks(org.vcell.optimization.DefaultOptSolverCallbacks) OptSolverCallbacks(org.vcell.optimization.OptSolverCallbacks) OptimizationResultSet(cbit.vcell.opt.OptimizationResultSet) OptSolverResultSet(cbit.vcell.opt.OptSolverResultSet) DefaultScalarFunction(cbit.function.DefaultScalarFunction) DefaultOptSolverCallbacks(org.vcell.optimization.DefaultOptSolverCallbacks) ImplicitObjectiveFunction(cbit.vcell.opt.ImplicitObjectiveFunction) Parameter(cbit.vcell.opt.Parameter) OptimizationSolverSpec(cbit.vcell.opt.OptimizationSolverSpec) OptimizationSpec(cbit.vcell.opt.OptimizationSpec)

Example 2 with DefaultScalarFunction

use of cbit.function.DefaultScalarFunction in project vcell by virtualcell.

the class OptContextSolver method estimate.

public static double estimate(OptContext optContext, Parameter[] inParams, String[] outParaNames, double[] outParaVals) throws Exception {
    // long startTime =System.currentTimeMillis();
    // create optimization solver
    PowellOptimizationSolver optSolver = new PowellOptimizationSolver();
    // create optimization spec
    OptimizationSpec optSpec = new OptimizationSpec();
    DefaultScalarFunction scalarFunc = new OptContextObjectiveFunction(optContext);
    optSpec.setObjectiveFunction(new ImplicitObjectiveFunction(scalarFunc));
    // create solver spec
    OptimizationSolverSpec optSolverSpec = new OptimizationSolverSpec(OptimizationSolverSpec.SOLVERTYPE_POWELL, FTOL);
    // create solver call back
    OptSolverCallbacks optSolverCallbacks = new DefaultOptSolverCallbacks();
    // create optimization result set
    OptimizationResultSet optResultSet = null;
    for (int i = 0; i < inParams.length; i++) {
        // add parameters
        optSpec.addParameter(inParams[i]);
    }
    optResultSet = optSolver.solve(optSpec, optSolverSpec, optSolverCallbacks);
    OptSolverResultSet optSolverResultSet = optResultSet.getOptSolverResultSet();
    // System.out.println("obj function value:"+optResultSet.getObjectiveFunctionValue());
    // System.out.println("");
    // copy results to output parameters
    String[] names = optSolverResultSet.getParameterNames();
    double[] values = optSolverResultSet.getBestEstimates();
    for (int i = 0; i < names.length; i++) {
        outParaNames[i] = names[i];
        outParaVals[i] = values[i];
    }
    // System.out.println("total: " + ( endTime - startTime) );
    return optSolverResultSet.getLeastObjectiveFunctionValue();
}
Also used : PowellOptimizationSolver(cbit.vcell.opt.solvers.PowellOptimizationSolver) DefaultOptSolverCallbacks(org.vcell.optimization.DefaultOptSolverCallbacks) OptSolverCallbacks(org.vcell.optimization.OptSolverCallbacks) OptimizationResultSet(cbit.vcell.opt.OptimizationResultSet) OptSolverResultSet(cbit.vcell.opt.OptSolverResultSet) DefaultScalarFunction(cbit.function.DefaultScalarFunction) DefaultOptSolverCallbacks(org.vcell.optimization.DefaultOptSolverCallbacks) ImplicitObjectiveFunction(cbit.vcell.opt.ImplicitObjectiveFunction) OptimizationSolverSpec(cbit.vcell.opt.OptimizationSolverSpec) OptimizationSpec(cbit.vcell.opt.OptimizationSpec)

Aggregations

DefaultScalarFunction (cbit.function.DefaultScalarFunction)2 ImplicitObjectiveFunction (cbit.vcell.opt.ImplicitObjectiveFunction)2 OptSolverResultSet (cbit.vcell.opt.OptSolverResultSet)2 OptimizationResultSet (cbit.vcell.opt.OptimizationResultSet)2 OptimizationSolverSpec (cbit.vcell.opt.OptimizationSolverSpec)2 OptimizationSpec (cbit.vcell.opt.OptimizationSpec)2 PowellOptimizationSolver (cbit.vcell.opt.solvers.PowellOptimizationSolver)2 DefaultOptSolverCallbacks (org.vcell.optimization.DefaultOptSolverCallbacks)2 OptSolverCallbacks (org.vcell.optimization.OptSolverCallbacks)2 Parameter (cbit.vcell.opt.Parameter)1