Search in sources :

Example 36 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class AugmentedObjectiveFunction method f.

/**
 * f method comment.
 */
public double f(double[] x) {
    double penalty = 0.0;
    try {
        optSolverCallbacks.setPenaltyMu(new Double(mu));
        penalty = getPenalty(x);
        // }
        if (penalty > 1000) {
            System.out.println("aborting point, penalty = " + penalty);
            return penalty;
        }
        double objFunValue = fobj.f(x) / 1000.0;
        // 
        // send info on evaluation
        // 
        OptSolverCallbacks.EvaluationHolder evaluationHolder = new OptSolverCallbacks.EvaluationHolder((double[]) x.clone(), (penalty + objFunValue));
        ODESolverResultSet resultSet = null;
        optSolverCallbacks.addEvaluation(evaluationHolder, resultSet);
        return penalty + objFunValue;
    } catch (Exception e) {
        e.printStackTrace(System.out);
        System.out.println("penalty = " + penalty);
        if (penalty > 0) {
            System.out.println("too high ... aborting augmentedObjective function");
            return penalty + 1;
        } else {
            throw new cbit.vcell.opt.OptimizationException(e.getMessage(), x);
        }
    }
}
Also used : OptSolverCallbacks(org.vcell.optimization.OptSolverCallbacks) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet)

Example 37 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet 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);
}
Also used : OptimizationResultSet(cbit.vcell.opt.OptimizationResultSet) OptimizationException(cbit.vcell.opt.OptimizationException) OptSolverResultSet(cbit.vcell.opt.OptSolverResultSet) Parameter(cbit.vcell.opt.Parameter) OptimizationStatus(cbit.vcell.opt.OptimizationStatus) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) OptRunResultSet(cbit.vcell.opt.OptSolverResultSet.OptRunResultSet)

Aggregations

ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)37 ODESolverResultSetColumnDescription (cbit.vcell.math.ODESolverResultSetColumnDescription)18 FunctionColumnDescription (cbit.vcell.math.FunctionColumnDescription)11 Expression (cbit.vcell.parser.Expression)10 DataSource (cbit.vcell.modelopt.DataSource)9 ReferenceData (cbit.vcell.opt.ReferenceData)8 ExpressionException (cbit.vcell.parser.ExpressionException)7 Simulation (cbit.vcell.solver.Simulation)7 SimulationSymbolTable (cbit.vcell.solver.SimulationSymbolTable)6 SolverException (cbit.vcell.solver.SolverException)6 IOException (java.io.IOException)6 Variable (cbit.vcell.math.Variable)4 SimulationTask (cbit.vcell.messaging.server.SimulationTask)4 SimpleReferenceData (cbit.vcell.opt.SimpleReferenceData)4 SbmlException (org.vcell.sbml.SbmlException)4 SBMLImportException (org.vcell.sbml.vcell.SBMLImportException)4 BioModel (cbit.vcell.biomodel.BioModel)3 Function (cbit.vcell.math.Function)3 MathDescription (cbit.vcell.math.MathDescription)3 MathException (cbit.vcell.math.MathException)3