Search in sources :

Example 46 with Expression

use of cbit.vcell.parser.Expression in project vcell by virtualcell.

the class ParameterEstimationTaskSimulatorIDA method getOdeSolverResultSet.

private ODESolverResultSet getOdeSolverResultSet(ParameterEstimationTask parameterEstimationTask, OptimizationSpec optSpec, OptimizationResultSet optResultSet) throws Exception {
    if (optResultSet == null) {
        return null;
    }
    String[] parameterNames = optResultSet.getOptSolverResultSet().getParameterNames();
    double[] bestEstimates = optResultSet.getOptSolverResultSet().getBestEstimates();
    // if we don't have parameter names or best estimates, return null. if we have them, we can run a simulation and generate a solution
    if (parameterNames == null || parameterNames.length == 0 || bestEstimates == null || bestEstimates.length == 0) {
        return null;
    }
    // check if we have solution or not, if not, generate a solution since we have the best estimates
    if (optResultSet.getSolutionNames() == null) {
        RowColumnResultSet rcResultSet = getRowColumnRestultSetByBestEstimations(parameterEstimationTask, parameterNames, bestEstimates);
        optResultSet.setSolutionFromRowColumnResultSet(rcResultSet);
    }
    String[] solutionNames = optResultSet.getSolutionNames();
    if (solutionNames != null && solutionNames.length > 0) {
        ODESolverResultSet odeSolverResultSet = new ODESolverResultSet();
        // add data column descriptions
        for (int i = 0; i < solutionNames.length; i++) {
            odeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(solutionNames[i]));
        }
        // 
        // add row data
        // 
        int numRows = optResultSet.getSolutionValues(0).length;
        for (int i = 0; i < numRows; i++) {
            odeSolverResultSet.addRow(optResultSet.getSolutionRow(i));
        }
        // 
        // make temporary simulation (with overrides for parameter values)
        // 
        MathDescription mathDesc = parameterEstimationTask.getSimulationContext().getMathDescription();
        Simulation simulation = new Simulation(mathDesc);
        SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(simulation, 0);
        // 
        for (int i = 0; i < optSpec.getParameters().length; i++) {
            cbit.vcell.opt.Parameter parameter = optSpec.getParameters()[i];
            simulation.getMathOverrides().putConstant(new Constant(parameter.getName(), new Expression(parameter.getInitialGuess())));
        }
        // 
        for (int i = 0; i < parameterNames.length; i++) {
            simulation.getMathOverrides().putConstant(new Constant(parameterNames[i], new Expression(optResultSet.getOptSolverResultSet().getBestEstimates()[i])));
        }
        // 
        // add functions (evaluating them at optimal parameter)
        // 
        Vector<AnnotatedFunction> annotatedFunctions = simSymbolTable.createAnnotatedFunctionsList(mathDesc);
        for (AnnotatedFunction f : annotatedFunctions) {
            Expression funcExp = f.getExpression();
            for (int j = 0; j < parameterNames.length; j++) {
                funcExp.substituteInPlace(new Expression(parameterNames[j]), new Expression(optResultSet.getOptSolverResultSet().getBestEstimates()[j]));
            }
            odeSolverResultSet.addFunctionColumn(new FunctionColumnDescription(funcExp, f.getName(), null, f.getName(), false));
        }
        return odeSolverResultSet;
    } else {
        return null;
    }
}
Also used : MathDescription(cbit.vcell.math.MathDescription) Constant(cbit.vcell.math.Constant) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 47 with Expression

use of cbit.vcell.parser.Expression in project vcell by virtualcell.

the class XmlReader method getBoundaryConditionValue.

private BoundaryConditionValue getBoundaryConditionValue(Element param, PdeEquation pde) throws XmlParseException, MathException {
    // retrieve values
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    Expression valueExpr = unMangleExpression(param.getAttributeValue(XMLTags.BoundaryValueExpressionTag));
    if (name != null && valueExpr != null) {
        BoundaryConditionValue bcv = pde.new BoundaryConditionValue(name, valueExpr);
        return bcv;
    }
    return null;
}
Also used : BoundaryConditionValue(cbit.vcell.math.PdeEquation.BoundaryConditionValue) Expression(cbit.vcell.parser.Expression)

Example 48 with Expression

use of cbit.vcell.parser.Expression in project vcell by virtualcell.

the class XmlReader method getParticleInitialConditionCount.

private ParticleInitialConditionCount getParticleInitialConditionCount(Element param) {
    String temp = param.getChildText(XMLTags.ParticleCountTag, vcNamespace);
    Expression countExp = null;
    if (temp != null && temp.length() > 0) {
        countExp = unMangleExpression(temp);
    }
    temp = param.getChildText(XMLTags.ParticleLocationXTag, vcNamespace);
    Expression locXExp = null;
    if (temp != null && temp.length() > 0) {
        locXExp = unMangleExpression(temp);
    }
    temp = param.getChildText(XMLTags.ParticleLocationYTag, vcNamespace);
    Expression locYExp = null;
    if (temp != null && temp.length() > 0) {
        locYExp = unMangleExpression(temp);
    }
    temp = param.getChildText(XMLTags.ParticleLocationZTag, vcNamespace);
    Expression locZExp = null;
    if (temp != null && temp.length() > 0) {
        locZExp = unMangleExpression(temp);
    }
    return new ParticleInitialConditionCount(countExp, locXExp, locYExp, locZExp);
}
Also used : Expression(cbit.vcell.parser.Expression) ParticleInitialConditionCount(cbit.vcell.math.ParticleProperties.ParticleInitialConditionCount)

Example 49 with Expression

use of cbit.vcell.parser.Expression in project vcell by virtualcell.

the class XmlReader method getProjectionDataGenerator.

private ProjectionDataGenerator getProjectionDataGenerator(Element element) {
    String name = unMangle(element.getAttributeValue(XMLTags.NameAttrTag));
    String domainStr = unMangle(element.getAttributeValue(XMLTags.DomainAttrTag));
    Domain domain = null;
    if (domainStr != null) {
        domain = new Domain(domainStr);
    }
    Element e = element.getChild(XMLTags.ProjectionAxis, vcNamespace);
    String axis = e.getText();
    // ProjectionDataGenerator.Axis axis = ProjectionDataGenerator.Axis.valueOf(s);
    e = element.getChild(XMLTags.ProjectionOperation, vcNamespace);
    String operation = e.getText();
    // ProjectionDataGenerator.Operation operation = ProjectionDataGenerator.Operation.valueOf(s);
    e = element.getChild(XMLTags.FunctionTag, vcNamespace);
    String s = e.getText();
    Expression exp = unMangleExpression(s);
    ProjectionDataGenerator projectionDataGenerator = new ProjectionDataGenerator(name, domain, axis, operation, exp);
    return projectionDataGenerator;
}
Also used : Expression(cbit.vcell.parser.Expression) Element(org.jdom.Element) ProjectionDataGenerator(cbit.vcell.math.ProjectionDataGenerator) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain) PointSubDomain(cbit.vcell.math.PointSubDomain) Domain(cbit.vcell.math.Variable.Domain)

Example 50 with Expression

use of cbit.vcell.parser.Expression in project vcell by virtualcell.

the class XmlReader method getParticleProperties.

private ParticleProperties getParticleProperties(Element param, MathDescription mathDesc) throws XmlParseException {
    // Retrieve the variable reference
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    Variable varref = mathDesc.getVariable(name);
    if (varref == null) {
        throw new XmlParseException("The variable " + name + " for a PdeEquation, could not be resolved!");
    }
    ArrayList<ParticleInitialCondition> initialConditions = new ArrayList<ParticleInitialCondition>();
    Iterator<Element> iterator = param.getChildren(XMLTags.ParticleInitialCountTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        Element tempelement = (Element) iterator.next();
        initialConditions.add(getParticleInitialConditionCount(tempelement));
    }
    iterator = param.getChildren(XMLTags.ParticleInitialCountTag_old, vcNamespace).iterator();
    while (iterator.hasNext()) {
        Element tempelement = (Element) iterator.next();
        initialConditions.add(getParticleInitialConditionCount(tempelement));
    }
    iterator = param.getChildren(XMLTags.ParticleInitialConcentrationTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        Element tempelement = (Element) iterator.next();
        String temp = tempelement.getChildText(XMLTags.ParticleDistributionTag, vcNamespace);
        Expression distExp = null;
        if (temp != null && temp.length() > 0) {
            distExp = unMangleExpression(temp);
        }
        initialConditions.add(new ParticleInitialConditionConcentration(distExp));
    }
    String temp = param.getChildText(XMLTags.ParticleDiffusionTag, vcNamespace);
    Expression diffExp = null;
    if (temp != null && temp.length() > 0) {
        diffExp = unMangleExpression(temp);
    }
    String driftXString = param.getChildText(XMLTags.ParticleDriftXTag, vcNamespace);
    Expression driftXExp = null;
    if (driftXString != null && driftXString.length() > 0) {
        driftXExp = unMangleExpression(driftXString);
    }
    String driftYString = param.getChildText(XMLTags.ParticleDriftYTag, vcNamespace);
    Expression driftYExp = null;
    if (driftYString != null && driftYString.length() > 0) {
        driftYExp = unMangleExpression(driftYString);
    }
    String driftZString = param.getChildText(XMLTags.ParticleDriftZTag, vcNamespace);
    Expression driftZExp = null;
    if (driftZString != null && driftZString.length() > 0) {
        driftZExp = unMangleExpression(driftZString);
    }
    return new ParticleProperties(varref, diffExp, driftXExp, driftYExp, driftZExp, initialConditions);
}
Also used : FilamentVariable(cbit.vcell.math.FilamentVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) StochVolVariable(cbit.vcell.math.StochVolVariable) RandomVariable(cbit.vcell.math.RandomVariable) VolumeRandomVariable(cbit.vcell.math.VolumeRandomVariable) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) InsideVariable(cbit.vcell.math.InsideVariable) VolVariable(cbit.vcell.math.VolVariable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) PointVariable(cbit.vcell.math.PointVariable) MembraneRandomVariable(cbit.vcell.math.MembraneRandomVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) ParticleVariable(cbit.vcell.math.ParticleVariable) MemVariable(cbit.vcell.math.MemVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) ParticleInitialConditionConcentration(cbit.vcell.math.ParticleProperties.ParticleInitialConditionConcentration) Expression(cbit.vcell.parser.Expression) ParticleInitialCondition(cbit.vcell.math.ParticleProperties.ParticleInitialCondition) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ParticleProperties(cbit.vcell.math.ParticleProperties)

Aggregations

Expression (cbit.vcell.parser.Expression)549 ExpressionException (cbit.vcell.parser.ExpressionException)163 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)76 PropertyVetoException (java.beans.PropertyVetoException)73 Variable (cbit.vcell.math.Variable)69 ArrayList (java.util.ArrayList)58 Vector (java.util.Vector)56 MathException (cbit.vcell.math.MathException)55 VolVariable (cbit.vcell.math.VolVariable)53 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)51 SpeciesContext (cbit.vcell.model.SpeciesContext)50 Element (org.jdom.Element)47 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)45 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)45 Model (cbit.vcell.model.Model)43 Function (cbit.vcell.math.Function)42 Constant (cbit.vcell.math.Constant)41 ModelParameter (cbit.vcell.model.Model.ModelParameter)41 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)41 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)38