Search in sources :

Example 6 with OptRunResultSet

use of cbit.vcell.opt.OptSolverResultSet.OptRunResultSet in project vcell by virtualcell.

the class OptXmlReader method getOptimizationResultSet.

public static OptSolverResultSet getOptimizationResultSet(String xmlString) {
    Element optResultSetElement = stringToXML(xmlString);
    if (!optResultSetElement.getName().equals(OptXmlTags.OptSolverResultSet_Tag)) {
        throw new RuntimeException("unexpected element '" + optResultSetElement.getName() + "', expecting " + OptXmlTags.OptSolverResultSet_Tag);
    }
    List<Element> paramElementList = optResultSetElement.getChildren(OptXmlTags.Parameter_Tag);
    String[] parameterNames = new String[paramElementList.size()];
    int count = 0;
    for (Element parameterElement : paramElementList) {
        parameterNames[count] = parameterElement.getAttributeValue(OptXmlTags.ParameterName_Attr);
        count++;
    }
    Element bestRunElement = optResultSetElement.getChild(OptXmlTags.bestOptRunResultSet_Tag);
    try {
        OptRunResultSet bestResultSet = getOptRunResultSet(bestRunElement);
        OptSolverResultSet optResultSet = new OptSolverResultSet(parameterNames, bestResultSet);
        return optResultSet;
    } catch (DataConversionException e) {
        e.printStackTrace(System.out);
        throw new RuntimeException(e.getMessage());
    }
}
Also used : Element(org.jdom.Element) OptRunResultSet(cbit.vcell.opt.OptSolverResultSet.OptRunResultSet) DataConversionException(org.jdom.DataConversionException) OptSolverResultSet(cbit.vcell.opt.OptSolverResultSet)

Example 7 with OptRunResultSet

use of cbit.vcell.opt.OptSolverResultSet.OptRunResultSet 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

OptRunResultSet (cbit.vcell.opt.OptSolverResultSet.OptRunResultSet)7 OptSolverResultSet (cbit.vcell.opt.OptSolverResultSet)5 OptimizationResultSet (cbit.vcell.opt.OptimizationResultSet)4 OptimizationStatus (cbit.vcell.opt.OptimizationStatus)4 OptimizationException (cbit.vcell.opt.OptimizationException)3 Element (org.jdom.Element)3 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)2 File (java.io.File)2 IOException (java.io.IOException)2 OptParameterValue (org.vcell.optimization.thrift.OptParameterValue)2 OptProblem (org.vcell.optimization.thrift.OptProblem)2 OptResultSet (org.vcell.optimization.thrift.OptResultSet)2 OptRun (org.vcell.optimization.thrift.OptRun)2 MathException (cbit.vcell.math.MathException)1 Parameter (cbit.vcell.model.Parameter)1 CopasiOptimizationMethod (cbit.vcell.opt.CopasiOptimizationMethod)1 CopasiOptimizationParameter (cbit.vcell.opt.CopasiOptimizationParameter)1 OptimizationSolverSpec (cbit.vcell.opt.OptimizationSolverSpec)1 Parameter (cbit.vcell.opt.Parameter)1 ReferenceData (cbit.vcell.opt.ReferenceData)1