use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class OutputFunctionContext method getAutoCompleteSymbolFilter.
public AutoCompleteSymbolFilter getAutoCompleteSymbolFilter(final Domain functionDomain) {
AutoCompleteSymbolFilter stef = new AutoCompleteSymbolFilter() {
public boolean accept(SymbolTableEntry ste) {
if (simulationOwner.getGeometry().getDimension() > 0) {
if (functionDomain == null) {
return true;
}
if (ste.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX) || ste.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
return false;
}
if (ste instanceof ReservedVariable) {
return true;
}
if (ste instanceof AnnotatedFunction) {
return functionDomain.compareEqual(((AnnotatedFunction) ste).getDomain());
}
if (ste instanceof Variable) {
Variable var = (Variable) ste;
if (var.getDomain() == null) {
return true;
}
GeometryClass gc = simulationOwner.getGeometry().getGeometryClass(functionDomain.getName());
GeometryClass vargc = simulationOwner.getGeometry().getGeometryClass(var.getDomain().getName());
if (gc instanceof SurfaceClass && vargc instanceof SubVolume) {
if (((SurfaceClass) gc).isAdjacentTo((SubVolume) vargc)) {
return true;
} else {
return false;
}
} else {
return var.getDomain().compareEqual(functionDomain);
}
}
}
return true;
}
public boolean acceptFunction(String funcName) {
return true;
}
};
return stef;
}
use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class ModelOptimizationSpec method calculateTimeDependentModelObjects.
/**
* Insert the method's description here.
* Creation date: (11/29/2005 5:10:51 PM)
* @return cbit.vcell.parser.SymbolTableEntry[]
*/
public static SymbolTableEntry[] calculateTimeDependentModelObjects(SimulationContext simulationContext) {
Graph digraph = new Graph();
//
// add time
//
Model model = simulationContext.getModel();
Node timeNode = new Node("t", model.getTIME());
digraph.addNode(timeNode);
//
// add all species concentrations (that are not fixed with a constant initial condition).
//
SpeciesContextSpec[] scs = simulationContext.getReactionContext().getSpeciesContextSpecs();
for (int i = 0; scs != null && i < scs.length; i++) {
SpeciesContextSpecParameter initParam = scs[i].getInitialConditionParameter();
Expression iniExp = initParam == null ? null : initParam.getExpression();
if (!scs[i].isConstant() || (iniExp != null && !iniExp.isNumeric())) {
String speciesContextScopedName = scs[i].getSpeciesContext().getNameScope().getAbsoluteScopePrefix() + scs[i].getSpeciesContext().getName();
Node speciesContextNode = new Node(speciesContextScopedName, scs[i].getSpeciesContext());
digraph.addNode(speciesContextNode);
digraph.addEdge(new Edge(speciesContextNode, timeNode));
}
}
//
// add all model (global) parameters that are not simple constants
//
ModelParameter[] modelParams = model.getModelParameters();
for (int i = 0; modelParams != null && i < modelParams.length; i++) {
Expression exp = modelParams[i].getExpression();
if (exp != null) {
String[] symbols = exp.getSymbols();
if (symbols != null && symbols.length > 0) {
//
// add parameter to graph as a node (if not already there).
//
String parameterScopedName = modelParams[i].getNameScope().getAbsoluteScopePrefix() + modelParams[i].getName();
Node parameterNode = digraph.getNode(parameterScopedName);
if (parameterNode == null) {
parameterNode = new Node(parameterScopedName, modelParams[i]);
digraph.addNode(parameterNode);
}
//
for (int k = 0; symbols != null && k < symbols.length; k++) {
SymbolTableEntry ste = exp.getSymbolBinding(symbols[k]);
if (ste == null) {
throw new RuntimeException("Error, symbol '" + symbols[k] + "' not bound in parameter '" + modelParams[i].getName() + "'");
}
String symbolScopedName = ste.getNameScope().getAbsoluteScopePrefix() + ste.getName();
Node symbolNode = digraph.getNode(symbolScopedName);
if (symbolNode == null) {
symbolNode = new Node(symbolScopedName, ste);
digraph.addNode(symbolNode);
}
digraph.addEdge(new Edge(parameterNode, symbolNode));
}
}
}
}
//
// add all reaction parameters that are not simple constants
//
ReactionStep[] reactionSteps = model.getReactionSteps();
for (int i = 0; reactionSteps != null && i < reactionSteps.length; i++) {
Parameter[] parameters = reactionSteps[i].getKinetics().getKineticsParameters();
for (int j = 0; parameters != null && j < parameters.length; j++) {
Expression exp = parameters[j].getExpression();
if (exp != null) {
String[] symbols = exp.getSymbols();
if (symbols != null && symbols.length > 0) {
//
// add parameter to graph as a node (if not already there).
//
String parameterScopedName = parameters[j].getNameScope().getAbsoluteScopePrefix() + parameters[j].getName();
Node parameterNode = digraph.getNode(parameterScopedName);
if (parameterNode == null) {
parameterNode = new Node(parameterScopedName, parameters[j]);
digraph.addNode(parameterNode);
}
//
for (int k = 0; symbols != null && k < symbols.length; k++) {
SymbolTableEntry ste = exp.getSymbolBinding(symbols[k]);
if (ste == null) {
throw new RuntimeException("Error, symbol '" + symbols[k] + "' not bound in parameter '" + parameters[j].getName() + "'");
}
String symbolScopedName = ste.getNameScope().getAbsoluteScopePrefix() + ste.getName();
Node symbolNode = digraph.getNode(symbolScopedName);
if (symbolNode == null) {
symbolNode = new Node(symbolScopedName, ste);
digraph.addNode(symbolNode);
}
digraph.addEdge(new Edge(parameterNode, symbolNode));
}
}
}
}
}
//
for (Structure structure : model.getStructures()) {
if (structure instanceof Membrane && ((MembraneMapping) simulationContext.getGeometryContext().getStructureMapping(structure)).getCalculateVoltage()) {
MembraneVoltage membraneVoltage = ((Membrane) structure).getMembraneVoltage();
String membraneVoltageScopedName = membraneVoltage.getNameScope().getAbsoluteScopePrefix() + membraneVoltage.getName();
Node membraneVoltageNode = digraph.getNode(membraneVoltageScopedName);
if (membraneVoltageNode == null) {
membraneVoltageNode = new Node(membraneVoltageScopedName, membraneVoltage);
digraph.addNode(membraneVoltageNode);
}
digraph.addEdge(new Edge(membraneVoltageNode, timeNode));
}
}
Node[] timeDependentNodes = digraph.getDigraphAttractorSet(timeNode);
SymbolTableEntry[] steArray = new SymbolTableEntry[timeDependentNodes.length];
for (int i = 0; i < steArray.length; i++) {
steArray[i] = (SymbolTableEntry) timeDependentNodes[i].getData();
}
return steArray;
}
use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class ParameterEstimationTaskXMLPersistence method getParameterEstimationTask.
/**
* Insert the method's description here.
* Creation date: (5/5/2006 4:50:36 PM)
* @return cbit.vcell.modelopt.ParameterEstimationTask
* @param element org.jdom.Element
* @param simContext cbit.vcell.mapping.SimulationContext
*/
public static ParameterEstimationTask getParameterEstimationTask(Element parameterEstimationTaskElement, SimulationContext simContext) throws ExpressionException, MappingException, MathException, java.beans.PropertyVetoException {
Namespace ns = parameterEstimationTaskElement.getNamespace();
ParameterEstimationTask parameterEstimationTask = new ParameterEstimationTask(simContext);
String name = parameterEstimationTaskElement.getAttributeValue(NameAttribute);
parameterEstimationTask.setName(name);
Element annotationElement = parameterEstimationTaskElement.getChild(AnnotationTag, ns);
if (annotationElement != null) {
String annotationText = annotationElement.getText();
parameterEstimationTask.setAnnotation(annotationText);
}
//
// read ParameterMappingSpecs
//
Element parameterMappingSpecListElement = parameterEstimationTaskElement.getChild(ParameterMappingSpecListTag, ns);
if (parameterMappingSpecListElement != null) {
List<Element> parameterMappingSpecElementList = parameterMappingSpecListElement.getChildren(ParameterMappingSpecTag, ns);
for (Element parameterMappingSpecElement : parameterMappingSpecElementList) {
String parameterName = parameterMappingSpecElement.getAttributeValue(ParameterReferenceAttribute);
SymbolTableEntry ste = getSymbolTableEntry(simContext, parameterName);
if (ste instanceof Parameter) {
Parameter parameter = (Parameter) ste;
ParameterMappingSpec parameterMappingSpec = parameterEstimationTask.getModelOptimizationSpec().getParameterMappingSpec(parameter);
if (parameterMappingSpec != null) {
String lowLimitString = parameterMappingSpecElement.getAttributeValue(LowLimitAttribute);
if (lowLimitString != null) {
parameterMappingSpec.setLow(parseDouble(lowLimitString));
}
String highLimitString = parameterMappingSpecElement.getAttributeValue(HighLimitAttribute);
if (highLimitString != null) {
parameterMappingSpec.setHigh(parseDouble(highLimitString));
}
String currentValueString = parameterMappingSpecElement.getAttributeValue(CurrentValueAttribute);
if (currentValueString != null) {
parameterMappingSpec.setCurrent(Double.parseDouble(currentValueString));
}
String selectedString = parameterMappingSpecElement.getAttributeValue(SelectedAttribute);
if (selectedString != null) {
parameterMappingSpec.setSelected(Boolean.valueOf(selectedString).booleanValue());
}
}
} else {
System.out.println("couldn't read parameterMappingSpec '" + parameterName + "', ste=" + ste);
}
}
}
//
// read ReferenceData
//
Element referenceDataElement = parameterEstimationTaskElement.getChild(ReferenceDataTag, ns);
if (referenceDataElement != null) {
String numRowsText = referenceDataElement.getAttributeValue(NumRowsAttribute);
String numColsText = referenceDataElement.getAttributeValue(NumColumnsAttribute);
// int numRows = Integer.parseInt(numRowsText);
int numCols = Integer.parseInt(numColsText);
//
// read columns
//
String[] columnNames = new String[numCols];
double[] columnWeights = new double[numCols];
int columnCounter = 0;
Element dataColumnListElement = referenceDataElement.getChild(DataColumnListTag, ns);
List<Element> dataColumnList = dataColumnListElement.getChildren(DataColumnTag, ns);
for (Element dataColumnElement : dataColumnList) {
columnNames[columnCounter] = dataColumnElement.getAttributeValue(NameAttribute);
columnWeights[columnCounter] = Double.parseDouble(dataColumnElement.getAttributeValue(WeightAttribute));
columnCounter++;
}
//
// read rows
//
Vector<double[]> rowDataVector = new Vector<double[]>();
Element dataRowListElement = referenceDataElement.getChild(DataRowListTag, ns);
List<Element> dataRowList = dataRowListElement.getChildren(DataRowTag, ns);
for (Element dataRowElement : dataRowList) {
String rowText = dataRowElement.getText();
CommentStringTokenizer tokens = new CommentStringTokenizer(rowText);
double[] rowData = new double[numCols];
for (int j = 0; j < numCols; j++) {
if (tokens.hasMoreTokens()) {
String token = tokens.nextToken();
rowData[j] = Double.parseDouble(token);
} else {
throw new RuntimeException("failed to read row data for ReferenceData");
}
}
rowDataVector.add(rowData);
}
ReferenceData referenceData = new SimpleReferenceData(columnNames, columnWeights, rowDataVector);
parameterEstimationTask.getModelOptimizationSpec().setReferenceData(referenceData);
}
//
// read ReferenceDataMappingSpecs
//
Element referenceDataMappingSpecListElement = parameterEstimationTaskElement.getChild(ReferenceDataMappingSpecListTag, ns);
if (referenceDataMappingSpecListElement != null) {
List<Element> referenceDataMappingSpecList = referenceDataMappingSpecListElement.getChildren(ReferenceDataMappingSpecTag, ns);
for (Element referenceDataMappingSpecElement : referenceDataMappingSpecList) {
String referenceDataColumnName = referenceDataMappingSpecElement.getAttributeValue(ReferenceDataColumnNameAttribute);
String referenceDataModelSymbolName = referenceDataMappingSpecElement.getAttributeValue(ReferenceDataModelSymbolAttribute);
ReferenceDataMappingSpec referenceDataMappingSpec = parameterEstimationTask.getModelOptimizationSpec().getReferenceDataMappingSpec(referenceDataColumnName);
SymbolTableEntry modelSymbolTableEntry = null;
if (referenceDataModelSymbolName != null) {
modelSymbolTableEntry = getSymbolTableEntry(simContext, referenceDataModelSymbolName);
if (referenceDataMappingSpec != null && modelSymbolTableEntry != null) {
referenceDataMappingSpec.setModelObject(modelSymbolTableEntry);
}
}
}
}
//
// read OptimizationSolverSpec
//
Element optimizationSolverSpecElement = parameterEstimationTaskElement.getChild(OptimizationSolverSpecTag, ns);
if (optimizationSolverSpecElement != null) {
OptimizationSolverSpec optSolverSpec = null;
String optimizationSolverTypeName = optimizationSolverSpecElement.getAttributeValue(OptimizationSolverTypeAttribute);
// getting parameters
Element optimizationSolverParameterList = optimizationSolverSpecElement.getChild(OptimizationListOfParametersTag, ns);
if (optimizationSolverParameterList != null) {
List<Element> listOfSolverParams = optimizationSolverParameterList.getChildren(OptimizationParameterTag, ns);
CopasiOptimizationMethod copasiOptMethod = null;
if (listOfSolverParams != null && listOfSolverParams.size() > 0) {
List<CopasiOptimizationParameter> copasiSolverParams = new ArrayList<CopasiOptimizationParameter>();
for (Element solverParam : listOfSolverParams) {
String paramName = solverParam.getAttributeValue(OptimizationParameterNameAttribute);
double paramValue = Double.parseDouble(solverParam.getAttributeValue(OptimizationParameterValueAttribute));
CopasiOptimizationParameter copasiParam = new CopasiOptimizationParameter(getCopasiOptimizationParameterTypeByName(paramName), paramValue);
copasiSolverParams.add(copasiParam);
}
copasiOptMethod = new CopasiOptimizationMethod(getCopasiOptimizationMethodTypeByName(optimizationSolverTypeName), copasiSolverParams.toArray(new CopasiOptimizationParameter[copasiSolverParams.size()]));
} else // no parameters
{
copasiOptMethod = new CopasiOptimizationMethod(getCopasiOptimizationMethodTypeByName(optimizationSolverTypeName), new CopasiOptimizationParameter[0]);
}
optSolverSpec = new OptimizationSolverSpec(copasiOptMethod);
// add number of runs attribute
String numOfRunsStr = optimizationSolverSpecElement.getAttributeValue(OptimizationSolverNumOfRunsAttribute);
if (numOfRunsStr != null) {
int numOfRuns = Integer.parseInt(numOfRunsStr);
optSolverSpec.setNumOfRuns(numOfRuns);
}
}
parameterEstimationTask.setOptimizationSolverSpec(optSolverSpec);
}
if (// optimization solver spec is null create a default copasi evolutionary programming
optimizationSolverSpecElement == null || parameterEstimationTask.getOptimizationSolverSpec() == null) {
OptimizationSolverSpec optSolverSpec = new OptimizationSolverSpec(new CopasiOptimizationMethod(CopasiOptimizationMethodType.EvolutionaryProgram));
parameterEstimationTask.setOptimizationSolverSpec(optSolverSpec);
}
// read optimization solver result set
Element optimizationResultSetElement = parameterEstimationTaskElement.getChild(OptXmlTags.OptimizationResultSet_Tag, ns);
if (optimizationResultSetElement != null) {
OptimizationResultSet optResultSet = null;
// read optsolverResultSet
if (optimizationResultSetElement.getChild(OptXmlTags.bestOptRunResultSet_Tag, ns) != null) {
Element optSolverResultSetElement = optimizationResultSetElement.getChild(OptXmlTags.bestOptRunResultSet_Tag, ns);
OptSolverResultSet optSolverResultSet = null;
// get best parameters, best func value, number of evaluations and construct an optRunResultSet
Element paramListElement = optSolverResultSetElement.getChild(OptimizationListOfParametersTag, ns);
OptRunResultSet optRunResultSet = null;
List<String> paramNames = new ArrayList<String>();
List<Double> paramValues = new ArrayList<Double>();
if (paramListElement != null && !paramListElement.getChildren().isEmpty()) {
List<Element> paramElements = paramListElement.getChildren(OptimizationParameterTag, ns);
if (paramElements != null) {
for (Element paramElement : paramElements) {
String paramName = paramElement.getAttributeValue(OptimizationParameterNameAttribute);
double paramValue = Double.parseDouble(paramElement.getAttributeValue(OptimizationParameterValueAttribute));
paramNames.add(paramName);
paramValues.add(paramValue);
}
}
}
Element bestFuncValueElement = optSolverResultSetElement.getChild(OptXmlTags.ObjectiveFunction_Tag, ns);
double bestFuncValue = Double.parseDouble(bestFuncValueElement.getAttributeValue(OptimizationParameterValueAttribute));
Element numEvaluationsElement = optSolverResultSetElement.getChild(OptXmlTags.OptSolverResultSetFunctionEvaluations_Tag, ns);
long numEvaluations = Long.parseLong(numEvaluationsElement.getAttributeValue(OptimizationParameterValueAttribute));
// change List<Double> to double[]
double[] values = new double[paramValues.size()];
int index = 0;
for (Double value : paramValues) {
values[index++] = value;
}
optRunResultSet = new OptRunResultSet(values, bestFuncValue, numEvaluations, null);
// create optSolverResultSet
optSolverResultSet = new OptSolverResultSet(paramNames.toArray(new String[paramNames.size()]), optRunResultSet);
// create optimization result set
optResultSet = new OptimizationResultSet(optSolverResultSet, null);
}
parameterEstimationTask.setOptimizationResultSet(optResultSet);
}
return parameterEstimationTask;
}
use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class ParameterEstimationTaskXMLPersistence method getXML.
/**
* Insert the method's description here.
* Creation date: (5/5/2006 9:02:39 AM)
* @return java.lang.String
* @param parameterEstimationTask cbit.vcell.modelopt.ParameterEstimationTask
*/
public static Element getXML(ParameterEstimationTask parameterEstimationTask) {
Element parameterEstimationTaskElement = new Element(XMLTags.ParameterEstimationTaskTag);
// name attribute
parameterEstimationTaskElement.setAttribute(NameAttribute, mangle(parameterEstimationTask.getName()));
// annotation content (optional)
String annotation = parameterEstimationTask.getAnnotation();
if (annotation != null && annotation.length() > 0) {
org.jdom.Element annotationElement = new org.jdom.Element(AnnotationTag);
annotationElement.setText(mangle(annotation));
parameterEstimationTaskElement.addContent(annotationElement);
}
//
// add ParameterMappingSpecs
//
ParameterMappingSpec[] parameterMappingSpecs = parameterEstimationTask.getModelOptimizationSpec().getParameterMappingSpecs();
if (parameterMappingSpecs != null && parameterMappingSpecs.length > 0) {
Element parameterMappingSpecListElement = new Element(ParameterMappingSpecListTag);
for (int i = 0; i < parameterMappingSpecs.length; i++) {
Element parameterMappingSpecElement = new Element(ParameterMappingSpecTag);
Parameter parameter = parameterMappingSpecs[i].getModelParameter();
parameterMappingSpecElement.setAttribute(ParameterReferenceAttribute, parameter.getNameScope().getAbsoluteScopePrefix() + parameter.getName());
parameterMappingSpecElement.setAttribute(LowLimitAttribute, Double.toString(parameterMappingSpecs[i].getLow()));
parameterMappingSpecElement.setAttribute(HighLimitAttribute, Double.toString(parameterMappingSpecs[i].getHigh()));
parameterMappingSpecElement.setAttribute(CurrentValueAttribute, Double.toString(parameterMappingSpecs[i].getCurrent()));
parameterMappingSpecElement.setAttribute(SelectedAttribute, String.valueOf(parameterMappingSpecs[i].isSelected()));
parameterMappingSpecListElement.addContent(parameterMappingSpecElement);
}
parameterEstimationTaskElement.addContent(parameterMappingSpecListElement);
}
//
// add ReferenceData
//
ReferenceData referenceData = parameterEstimationTask.getModelOptimizationSpec().getReferenceData();
if (referenceData != null && referenceData.getNumDataColumns() > 0) {
Element referenceDataElement = new Element(ReferenceDataTag);
referenceDataElement.setAttribute(NumRowsAttribute, Integer.toString(referenceData.getNumDataRows()));
referenceDataElement.setAttribute(NumColumnsAttribute, Integer.toString(referenceData.getNumDataColumns()));
Element dataColumnListElement = new Element(DataColumnListTag);
for (int i = 0; i < referenceData.getColumnNames().length; i++) {
Element dataColumnElement = new Element(DataColumnTag);
dataColumnElement.setAttribute(NameAttribute, referenceData.getColumnNames()[i]);
dataColumnElement.setAttribute(WeightAttribute, Double.toString(referenceData.getColumnWeights()[i]));
dataColumnListElement.addContent(dataColumnElement);
}
referenceDataElement.addContent(dataColumnListElement);
Element dataRowListElement = new Element(DataRowListTag);
for (int i = 0; i < referenceData.getNumDataRows(); i++) {
Element dataRowElement = new Element(DataRowTag);
String rowText = "";
for (int j = 0; j < referenceData.getNumDataColumns(); j++) {
if (j > 0) {
rowText += " ";
}
rowText += referenceData.getDataByRow(i)[j];
}
dataRowElement.addContent(rowText);
dataRowListElement.addContent(dataRowElement);
}
referenceDataElement.addContent(dataRowListElement);
parameterEstimationTaskElement.addContent(referenceDataElement);
}
//
// add ReferenceDataMappingSpecs
//
ReferenceDataMappingSpec[] referenceDataMappingSpecs = parameterEstimationTask.getModelOptimizationSpec().getReferenceDataMappingSpecs();
if (referenceDataMappingSpecs != null && referenceDataMappingSpecs.length > 0) {
Element referenceDataMappingSpecListElement = new Element(ReferenceDataMappingSpecListTag);
for (int i = 0; i < referenceDataMappingSpecs.length; i++) {
SymbolTableEntry modelSymbol = referenceDataMappingSpecs[i].getModelObject();
Element referenceDataMappingSpecElement = new Element(ReferenceDataMappingSpecTag);
referenceDataMappingSpecElement.setAttribute(ReferenceDataColumnNameAttribute, referenceDataMappingSpecs[i].getReferenceDataColumnName());
if (modelSymbol != null) {
referenceDataMappingSpecElement.setAttribute(ReferenceDataModelSymbolAttribute, modelSymbol.getName());
}
referenceDataMappingSpecListElement.addContent(referenceDataMappingSpecElement);
}
parameterEstimationTaskElement.addContent(referenceDataMappingSpecListElement);
}
//
if (parameterEstimationTask.getOptimizationSolverSpec() != null) {
OptimizationSolverSpec solverSpec = parameterEstimationTask.getOptimizationSolverSpec();
if (solverSpec.getCopasiOptimizationMethod() != null) {
CopasiOptimizationMethod copasiOptMethod = solverSpec.getCopasiOptimizationMethod();
Element optimizationSolverSpecElement = new Element(OptimizationSolverSpecTag);
optimizationSolverSpecElement.setAttribute(OptimizationSolverTypeAttribute, copasiOptMethod.getType().getName());
optimizationSolverSpecElement.setAttribute(OptimizationSolverNumOfRunsAttribute, solverSpec.getNumOfRuns() + "");
// adding solve parameter list to optimization solver spec
CopasiOptimizationParameter[] solverParams = copasiOptMethod.getParameters();
if (solverParams != null && solverParams.length > 0) {
Element listOfSolverParams = new Element(OptimizationListOfParametersTag);
for (CopasiOptimizationParameter solverParam : solverParams) {
Element optSolverParam = new Element(OptimizationParameterTag);
optSolverParam.setAttribute(OptimizationParameterNameAttribute, solverParam.getType().getDisplayName());
optSolverParam.setAttribute(OptimizationParameterValueAttribute, solverParam.getValue() + "");
listOfSolverParams.addContent(optSolverParam);
}
optimizationSolverSpecElement.addContent(listOfSolverParams);
}
parameterEstimationTaskElement.addContent(optimizationSolverSpecElement);
}
}
// add optimization solver result set
if (parameterEstimationTask.getOptimizationResultSet() != null) {
OptimizationResultSet optResultSet = parameterEstimationTask.getOptimizationResultSet();
Element optimizationResultSetElement = new Element(OptXmlTags.OptimizationResultSet_Tag);
if (optResultSet.getOptSolverResultSet() != null) {
OptSolverResultSet optSolverResultSet = optResultSet.getOptSolverResultSet();
Element optSolverResultSetElement = new Element(OptXmlTags.bestOptRunResultSet_Tag);
// write best parameters
String[] paramNames = optSolverResultSet.getParameterNames();
double[] bestValues = optSolverResultSet.getBestEstimates();
if (paramNames != null && paramNames.length > 0 && bestValues != null && bestValues.length > 0 && paramNames.length == bestValues.length) {
Element listOfBestParams = new Element(OptimizationListOfParametersTag);
for (int i = 0; i < paramNames.length; i++) {
Element resultParam = new Element(OptimizationParameterTag);
resultParam.setAttribute(OptimizationParameterNameAttribute, paramNames[i]);
resultParam.setAttribute(OptimizationParameterValueAttribute, bestValues[i] + "");
listOfBestParams.addContent(resultParam);
}
optSolverResultSetElement.addContent(listOfBestParams);
}
// write objective function value
double objectiveFuncValue = optSolverResultSet.getLeastObjectiveFunctionValue();
Element objFuncElement = new Element(OptXmlTags.ObjectiveFunction_Tag);
objFuncElement.setAttribute(OptimizationParameterValueAttribute, objectiveFuncValue + "");
optSolverResultSetElement.addContent(objFuncElement);
// write num function evaluations
long numFuncEvaluations = optSolverResultSet.getObjFunctionEvaluations();
Element numFuncEvaluationsElement = new Element(OptXmlTags.OptSolverResultSetFunctionEvaluations_Tag);
numFuncEvaluationsElement.setAttribute(OptimizationParameterValueAttribute, numFuncEvaluations + "");
optSolverResultSetElement.addContent(numFuncEvaluationsElement);
optimizationResultSetElement.addContent(optSolverResultSetElement);
}
parameterEstimationTaskElement.addContent(optimizationResultSetElement);
}
return parameterEstimationTaskElement;
}
use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class ReactionRule method getAutoCompleteSymbolFilter.
public AutoCompleteSymbolFilter getAutoCompleteSymbolFilter() {
AutoCompleteSymbolFilter stef = new AutoCompleteSymbolFilter() {
public boolean accept(SymbolTableEntry ste) {
if (ste instanceof StructureSize) {
if (((StructureSize) ste).getStructure() != structure) {
return false;
}
} else {
if (structure instanceof Membrane) {
Membrane membrane = (Membrane) structure;
StructureTopology structTopology = getModel().getStructureTopology();
if (ste instanceof SpeciesContext) {
Structure entryStructure = ((SpeciesContext) ste).getStructure();
if (entryStructure != membrane && entryStructure != structTopology.getInsideFeature(membrane) && entryStructure != structTopology.getOutsideFeature(membrane)) {
return false;
}
} else if (ste instanceof MembraneVoltage) {
if (((MembraneVoltage) ste).getMembrane() != membrane) {
return false;
}
}
} else {
if (ste instanceof SpeciesContext) {
Structure entryStructure = ((SpeciesContext) ste).getStructure();
if (entryStructure != structure) {
return false;
}
} else if (ste instanceof MembraneVoltage) {
return false;
}
}
}
return true;
}
public boolean acceptFunction(String funcName) {
return true;
}
};
return stef;
}
Aggregations