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;
}
}
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;
}
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);
}
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;
}
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);
}
Aggregations