Search in sources :

Example 1 with ScalarFunction

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

the class AugmentedObjectiveFunctionTest method getExample1.

/**
 * Insert the method's description here.
 * Creation date: (5/3/2002 2:49:06 PM)
 * @return opt.AugmentedObjectiveFunction
 */
public static AugmentedObjectiveFunction getExample1() {
    try {
        Expression scalarFn_exp = new Expression("pow(x1-2,4)+pow(x1-2*x2,2)");
        Expression[] eqConstraints_exps = { new Expression("pow(x1,2)-x2") };
        Expression[] ineqConstraints_exps = { new Expression("pow(x1,2)-x2") };
        ;
        String[] ids = { "x1", "x2" };
        ScalarFunction scalarFn = new DynamicScalarFunction(scalarFn_exp, ids);
        VectorFunction eqConstraints = new DynamicVectorFunction(eqConstraints_exps, ids);
        VectorFunction ineqConstraints = new DynamicVectorFunction(ineqConstraints_exps, ids);
        AugmentedObjectiveFunction aof = new AugmentedObjectiveFunction(scalarFn, eqConstraints, ineqConstraints, 2.0, 0.1, new DefaultOptSolverCallbacks());
        return aof;
    } catch (ExpressionException e) {
        e.printStackTrace();
        throw new RuntimeException(e.getMessage());
    }
}
Also used : DynamicScalarFunction(cbit.function.DynamicScalarFunction) DynamicScalarFunction(cbit.function.DynamicScalarFunction) ScalarFunction(cbit.function.ScalarFunction) Expression(cbit.vcell.parser.Expression) DefaultOptSolverCallbacks(org.vcell.optimization.DefaultOptSolverCallbacks) VectorFunction(cbit.function.VectorFunction) DynamicVectorFunction(cbit.function.DynamicVectorFunction) DynamicVectorFunction(cbit.function.DynamicVectorFunction) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 2 with ScalarFunction

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

the class OptUtils method getAugmentedObjectiveFunction.

/**
 * Insert the method's description here.
 * Creation date: (8/4/2005 3:26:14 PM)
 * @return function.AugmentedObjectiveFunction
 * @param optSpec cbit.vcell.opt.OptimizationSpec
 * @param power double
 * @param mu double
 */
public static AugmentedObjectiveFunction getAugmentedObjectiveFunction(OptimizationSpec optSpec, double power, double mu, OptSolverCallbacks optSolverCallbacks) throws cbit.vcell.parser.ExpressionException {
    Parameter[] parameters = optSpec.getParameters();
    // 
    // build symbol list
    // 
    String[] origSymbols = optSpec.getParameterNames();
    String[] scaledSymbols = optSpec.getScaledParameterNames();
    double[] scaleFactors = optSpec.getScaleFactors();
    ScalarFunction objFunction = null;
    if (optSpec.getObjectiveFunction() instanceof ExplicitObjectiveFunction) {
        ExplicitObjectiveFunction explicitObjectiveFunction = (ExplicitObjectiveFunction) optSpec.getObjectiveFunction();
        // 
        // build objective function
        // 
        objFunction = new DynamicScalarFunction(explicitObjectiveFunction.getScaledExpression(origSymbols, scaledSymbols, scaleFactors), scaledSymbols);
    } else if (optSpec.getObjectiveFunction() instanceof ImplicitObjectiveFunction) {
        ImplicitObjectiveFunction implicitObjectiveFunction = (ImplicitObjectiveFunction) optSpec.getObjectiveFunction();
        // 
        // build objective function
        // 
        objFunction = implicitObjectiveFunction.getObjectiveFunction();
    } else if (optSpec.getObjectiveFunction() instanceof ExplicitFitObjectiveFunction) {
        ExplicitFitObjectiveFunction explicitFitObjectiveFunction = (ExplicitFitObjectiveFunction) optSpec.getObjectiveFunction();
        objFunction = explicitFitObjectiveFunction.getScalarFunction();
    } else {
        throw new RuntimeException("unsupported objective function type : " + optSpec.getObjectiveFunction().getClass().getName());
    }
    // 
    // build equality and inequality constraints
    // 
    DynamicVectorFunction equalityConstraints = null;
    DynamicVectorFunction inequalityConstraints = null;
    Constraint[] constraints = optSpec.getConstraints();
    Vector equExpList = new Vector();
    Vector inequExpList = new Vector();
    // 
    for (int i = 0; i < constraints.length; i++) {
        ConstraintType type = constraints[i].getConstraintType();
        if (type.equals(ConstraintType.LinearEquality) || type.equals(ConstraintType.NonlinearEquality)) {
            equExpList.add(constraints[i].getExpression());
        } else {
            inequExpList.add(constraints[i].getExpression());
        }
    }
    // 
    for (int i = 0; i < parameters.length; i++) {
        if (!Double.isInfinite(parameters[i].getLowerBound())) {
            inequExpList.add(new Expression("(" + parameters[i].getLowerBound() + " - " + parameters[i].getName() + ")/" + scaleFactors[i]));
        }
        if (!Double.isInfinite(parameters[i].getUpperBound())) {
            inequExpList.add(new Expression("(" + parameters[i].getName() + " - " + parameters[i].getUpperBound() + ")/" + scaleFactors[i]));
        }
    }
    if (equExpList.size() > 0) {
        Expression[] exps = (Expression[]) org.vcell.util.BeanUtils.getArray(equExpList, Expression.class);
        equalityConstraints = new DynamicVectorFunction(exps, origSymbols);
    }
    if (inequExpList.size() > 0) {
        Expression[] exps = (Expression[]) org.vcell.util.BeanUtils.getArray(inequExpList, Expression.class);
        inequalityConstraints = new DynamicVectorFunction(exps, origSymbols);
    }
    AugmentedObjectiveFunction augmentedObjFunc = new AugmentedObjectiveFunction(objFunction, equalityConstraints, inequalityConstraints, power, mu, optSolverCallbacks);
    return augmentedObjFunc;
}
Also used : Constraint(cbit.vcell.opt.Constraint) ExplicitFitObjectiveFunction(cbit.vcell.opt.ExplicitFitObjectiveFunction) Constraint(cbit.vcell.opt.Constraint) DynamicScalarFunction(cbit.function.DynamicScalarFunction) ScalarFunction(cbit.function.ScalarFunction) DynamicScalarFunction(cbit.function.DynamicScalarFunction) Expression(cbit.vcell.parser.Expression) ExplicitObjectiveFunction(cbit.vcell.opt.ExplicitObjectiveFunction) Parameter(cbit.vcell.opt.Parameter) ImplicitObjectiveFunction(cbit.vcell.opt.ImplicitObjectiveFunction) DynamicVectorFunction(cbit.function.DynamicVectorFunction) ConstraintType(cbit.vcell.opt.ConstraintType) Vector(java.util.Vector)

Example 3 with ScalarFunction

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

the class AugmentedObjectiveFunctionTest method getExample2.

/**
 * Insert the method's description here.                    // Root-finding example
 * Creation date: (5/3/2002 2:49:06 PM)
 * @return opt.AugmentedObjectiveFunction
 */
public static AugmentedObjectiveFunction getExample2() {
    try {
        Expression scalarFn_exp = new Expression("1");
        Expression[] eqConstraints_exps = { new Expression("sin(x1+x2)-exp(x1-x2)"), new Expression("cos(x1+x2)-x1*x1*x2*x2") };
        Expression[] ineqConstraints_exps = {};
        String[] ids = { "x1", "x2" };
        ScalarFunction scalarFn = new DynamicScalarFunction(scalarFn_exp, ids);
        VectorFunction eqConstraints = new DynamicVectorFunction(eqConstraints_exps, ids);
        VectorFunction ineqConstraints = new DynamicVectorFunction(ineqConstraints_exps, ids);
        AugmentedObjectiveFunction aof = new AugmentedObjectiveFunction(scalarFn, eqConstraints, ineqConstraints, 2.0, 0.1, new DefaultOptSolverCallbacks());
        return aof;
    } catch (ExpressionException e) {
        e.printStackTrace();
        throw new RuntimeException(e.getMessage());
    }
}
Also used : DynamicScalarFunction(cbit.function.DynamicScalarFunction) DynamicScalarFunction(cbit.function.DynamicScalarFunction) ScalarFunction(cbit.function.ScalarFunction) Expression(cbit.vcell.parser.Expression) DefaultOptSolverCallbacks(org.vcell.optimization.DefaultOptSolverCallbacks) VectorFunction(cbit.function.VectorFunction) DynamicVectorFunction(cbit.function.DynamicVectorFunction) DynamicVectorFunction(cbit.function.DynamicVectorFunction) ExpressionException(cbit.vcell.parser.ExpressionException)

Aggregations

DynamicScalarFunction (cbit.function.DynamicScalarFunction)3 DynamicVectorFunction (cbit.function.DynamicVectorFunction)3 ScalarFunction (cbit.function.ScalarFunction)3 Expression (cbit.vcell.parser.Expression)3 VectorFunction (cbit.function.VectorFunction)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 DefaultOptSolverCallbacks (org.vcell.optimization.DefaultOptSolverCallbacks)2 Constraint (cbit.vcell.opt.Constraint)1 ConstraintType (cbit.vcell.opt.ConstraintType)1 ExplicitFitObjectiveFunction (cbit.vcell.opt.ExplicitFitObjectiveFunction)1 ExplicitObjectiveFunction (cbit.vcell.opt.ExplicitObjectiveFunction)1 ImplicitObjectiveFunction (cbit.vcell.opt.ImplicitObjectiveFunction)1 Parameter (cbit.vcell.opt.Parameter)1 Vector (java.util.Vector)1