use of org.vcell.optimization.ParameterEstimationTaskSimulatorIDA in project vcell by virtualcell.
the class ParameterEstimationRunTaskPanel method plot.
private void plot() {
try {
java.util.Vector<DataSource> dataSourceList = new java.util.Vector<DataSource>();
java.util.Vector<String> nameVector = new java.util.Vector<String>();
ModelOptimizationSpec modelOptimizationSpec = parameterEstimationTask.getModelOptimizationSpec();
final ReferenceDataMappingSpec[] mappingSpecs = modelOptimizationSpec.getReferenceDataMappingSpecs();
int timeIndex = modelOptimizationSpec.getReferenceDataTimeColumnIndex();
ReferenceData referenceData = modelOptimizationSpec.getReferenceData();
if (referenceData != null) {
dataSourceList.add(new DataSource.DataSourceReferenceData("EXPT", timeIndex, referenceData));
String[] refColumnNames = referenceData.getColumnNames();
for (int i = 0; i < refColumnNames.length; i++) {
if (i == timeIndex) {
continue;
}
nameVector.add(refColumnNames[i]);
break;
}
}
ParameterEstimationTaskSimulatorIDA parestSimulator = new ParameterEstimationTaskSimulatorIDA();
ODESolverResultSet odeSolverResultSet = parestSimulator.getOdeSolverResultSet(parameterEstimationTask);
if (odeSolverResultSet != null) {
dataSourceList.add(new DataSource.DataSourceRowColumnResultSet("EST", odeSolverResultSet));
if (mappingSpecs != null) {
for (int i = 0; i < mappingSpecs.length; i++) {
if (i == timeIndex) {
continue;
}
Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(mappingSpecs[i].getModelObject());
nameVector.add(var.getName());
break;
}
}
}
DataSource[] dataSources = (DataSource[]) BeanUtils.getArray(dataSourceList, DataSource.class);
MultisourcePlotPane multisourcePlotPane = new MultisourcePlotPane();
multisourcePlotPane.setGroupingListSorter(new Comparator<SortDataReferenceHelper>() {
@Override
public int compare(SortDataReferenceHelper o1, SortDataReferenceHelper o2) {
DataSource ds01 = o1.dataReference.getDataSource();
DataSource ds02 = o2.dataReference.getDataSource();
// System.out.println(ds01.getClass().getSimpleName()+" "+o1.dataReference.getIdentifier()+" "+ds02.getClass().getSimpleName()+" "+o2.dataReference.getIdentifier());
if (ds01 instanceof DataSource.DataSourceReferenceData) {
if (ds02 instanceof DataSource.DataSourceReferenceData) {
// both reference data, sort names
ReferenceDataMappingSpec mspec01 = null;
ReferenceDataMappingSpec mspec02 = null;
for (ReferenceDataMappingSpec rdMappingSpec : mappingSpecs) {
// Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(rdMappingSpec.getModelObject());
if (rdMappingSpec.getModelObject() instanceof ReservedSymbol) {
continue;
}
if (o1.dataReference.getIdentifier().equals(rdMappingSpec.getReferenceDataColumnName())) {
mspec01 = rdMappingSpec;
o1.setReferenceDataMappingSpec(rdMappingSpec);
} else if (o2.dataReference.getIdentifier().equals(rdMappingSpec.getReferenceDataColumnName())) {
mspec02 = rdMappingSpec;
o2.setReferenceDataMappingSpec(rdMappingSpec);
}
}
if (mspec01 == null && mspec02 == null) {
return o1.dataReference.getIdentifier().compareToIgnoreCase(o2.dataReference.getIdentifier());
} else if (mspec01 != null && mspec02 != null) {
return mspec01.getReferenceDataColumnName().compareToIgnoreCase(mspec02.getReferenceDataColumnName());
} else if (mspec01 != null && mspec02 == null) {
return -1;
} else {
return 1;
}
} else {
// compare ref to ode
ReferenceDataMappingSpec mspec01 = null;
ReferenceDataMappingSpec mspec02 = null;
for (ReferenceDataMappingSpec rdMappingSpec : mappingSpecs) {
Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(rdMappingSpec.getModelObject());
if (rdMappingSpec.getModelObject() instanceof ReservedSymbol) {
continue;
}
if (o1.dataReference.getIdentifier().equals(rdMappingSpec.getReferenceDataColumnName())) {
mspec01 = rdMappingSpec;
o1.setReferenceDataMappingSpec(rdMappingSpec);
} else if (o2.dataReference.getIdentifier().equals(var.getName())) {
mspec02 = rdMappingSpec;
o2.setReferenceDataMappingSpec(rdMappingSpec);
}
}
if (mspec01 == null && mspec02 == null) {
return -1;
} else if (mspec01 != null && mspec02 == null) {
return -1;
} else if (mspec02 != null && mspec01 == null) {
return 1;
} else {
// BeanUtils.forceStringSize(mspec02.getReferenceDataColumnName(), 25, " ", true));
return mspec01.getReferenceDataColumnName().compareToIgnoreCase(mspec02.getReferenceDataColumnName());
}
}
} else {
if (ds02 instanceof DataSource.DataSourceRowColumnResultSet) {
// both OdeSolverResultSet data, sort names
ReferenceDataMappingSpec mspec01 = null;
ReferenceDataMappingSpec mspec02 = null;
for (ReferenceDataMappingSpec rdMappingSpec : mappingSpecs) {
Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(rdMappingSpec.getModelObject());
if (rdMappingSpec.getModelObject() instanceof ReservedSymbol) {
continue;
}
if (o1.dataReference.getIdentifier().equals(var.getName())) {
mspec01 = rdMappingSpec;
o1.setReferenceDataMappingSpec(rdMappingSpec);
} else if (o2.dataReference.getIdentifier().equals(var.getName())) {
mspec02 = rdMappingSpec;
o2.setReferenceDataMappingSpec(rdMappingSpec);
}
}
if (mspec01 == null && mspec02 == null) {
return o1.dataReference.getIdentifier().compareToIgnoreCase(o2.dataReference.getIdentifier());
} else if (mspec01 != null && mspec02 != null) {
return mspec01.getReferenceDataColumnName().compareToIgnoreCase(mspec02.getReferenceDataColumnName());
} else if (mspec01 != null && mspec02 == null) {
return -1;
} else {
return 1;
}
} else {
// compare ode to ref
ReferenceDataMappingSpec mspec01 = null;
ReferenceDataMappingSpec mspec02 = null;
for (ReferenceDataMappingSpec rdMappingSpec : mappingSpecs) {
Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(rdMappingSpec.getModelObject());
if (rdMappingSpec.getModelObject() instanceof ReservedSymbol) {
continue;
}
if (o2.dataReference.getIdentifier().equals(rdMappingSpec.getReferenceDataColumnName())) {
mspec02 = rdMappingSpec;
o2.setReferenceDataMappingSpec(rdMappingSpec);
} else if (o1.dataReference.getIdentifier().equals(var.getName())) {
mspec01 = rdMappingSpec;
o1.setReferenceDataMappingSpec(rdMappingSpec);
}
}
if (mspec01 == null && mspec02 == null) {
return 1;
} else if (mspec01 != null && mspec02 == null) {
return -1;
} else if (mspec02 != null && mspec01 == null) {
return 1;
} else {
// BeanUtils.forceStringSize(mspec02.getReferenceDataColumnName(), 25, " ", true));
return mspec01.getReferenceDataColumnName().compareToIgnoreCase(mspec02.getReferenceDataColumnName());
}
}
}
}
});
multisourcePlotPane.setDataSources(dataSources);
String[] nameArray = new String[nameVector.size()];
nameArray = (String[]) BeanUtils.getArray(nameVector, String.class);
multisourcePlotPane.select(nameArray);
DialogUtils.showComponentCloseDialog(JOptionPane.getFrameForComponent(this), multisourcePlotPane, "Data Plot");
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
use of org.vcell.optimization.ParameterEstimationTaskSimulatorIDA in project vcell by virtualcell.
the class ParameterEstimationRunTaskPanel method solve.
private void solve() throws NumberFormatException {
CopasiOptimizationMethod com = optimizationMethodParameterTableModel.copasiOptimizationMethod;
OptimizationSolverSpec optSolverSpec = new OptimizationSolverSpec(com);
// get num runs for stochstic opt mehtods before starting solving...
if (com.getType().isStochasticMethod()) {
int numRuns = Integer.parseInt(((String) numberOfRunComboBox.getSelectedItem()));
optSolverSpec.setNumOfRuns(numRuns);
}
parameterEstimationTask.setOptimizationSolverSpec(optSolverSpec);
parameterEstimationTask.getModelOptimizationSpec().setComputeProfileDistributions(computeProfileDistributionsCheckBox.isSelected());
optSolverCallbacks.reset();
Double endValue = com.getEndValue();
optSolverCallbacks.setEvaluation(0, Double.POSITIVE_INFINITY, 0, endValue, 0);
// (endValue != null);
getRunStatusDialog().showProgressBar(com);
Collection<AsynchClientTask> taskList = ClientRequestManager.updateMath(this, parameterEstimationTask.getSimulationContext(), false, NetworkGenerationRequirements.ComputeFullStandardTimeout);
AsynchClientTask task1 = new AsynchClientTask("checking issues", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
StringBuffer issueText = new StringBuffer();
java.util.Vector<Issue> issueList = new java.util.Vector<Issue>();
IssueContext issueContext = new IssueContext();
parameterEstimationTask.gatherIssues(issueContext, issueList);
boolean bFailed = false;
for (int i = 0; i < issueList.size(); i++) {
Issue issue = (Issue) issueList.elementAt(i);
issueText.append(issue.getMessage() + "\n");
if (issue.getSeverity() == Issue.SEVERITY_ERROR) {
bFailed = true;
break;
}
}
if (bFailed) {
throw new OptimizationException(issueText.toString());
}
parameterEstimationTask.refreshMappings();
}
};
taskList.add(task1);
AsynchClientTask task2 = new AsynchClientTask("solving", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
MathMappingCallback mathMappingCallback = new MathMappingCallbackTaskAdapter(getClientTaskStatusSupport());
// OptimizationResultSet optResultSet = CopasiOptimizationSolver.solveLocalPython(new ParameterEstimationTaskSimulatorIDA(),parameterEstimationTask,optSolverCallbacks,mathMappingCallback);
OptimizationResultSet optResultSet = CopasiOptimizationSolver.solveRemoteApi(new ParameterEstimationTaskSimulatorIDA(), parameterEstimationTask, optSolverCallbacks, mathMappingCallback);
hashTable.put(ORS_KEY, optResultSet);
}
};
taskList.add(task2);
AsynchClientTask setResultTask = new AsynchClientTask("set results", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
OptimizationResultSet optResultSet = (OptimizationResultSet) hashTable.get(ORS_KEY);
parameterEstimationTask.setOptimizationResultSet(optResultSet);
}
};
taskList.add(setResultTask);
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), taskList.toArray(new AsynchClientTask[taskList.size()]), getRunStatusDialog(), true, true, true, null, false);
}
use of org.vcell.optimization.ParameterEstimationTaskSimulatorIDA in project vcell by virtualcell.
the class OptimizationService method optimize.
public static OptimizationResultSet optimize(ParameterEstimationTask parameterEstimationTask) throws Exception {
// if (OperatingSystemInfo.getInstance().isMac()){
// throw new RuntimeException("parameter estimation not currently available on Mac\n\n try Windows or Linux.\n\n coming soon on Mac.");
// }
copasiOptCallbacks.reset();
updateMath(parameterEstimationTask.getSimulationContext(), NetworkGenerationRequirements.ComputeFullStandardTimeout);
StringBuffer issueText = new StringBuffer();
java.util.Vector<Issue> issueList = new java.util.Vector<Issue>();
IssueContext issueContext = new IssueContext();
parameterEstimationTask.gatherIssues(issueContext, issueList);
boolean bFailed = false;
for (int i = 0; i < issueList.size(); i++) {
Issue issue = (Issue) issueList.elementAt(i);
issueText.append(issue.getMessage() + "\n");
if (issue.getSeverity() == Issue.SEVERITY_ERROR) {
bFailed = true;
break;
}
}
if (bFailed) {
throw new OptimizationException(issueText.toString());
}
parameterEstimationTask.refreshMappings();
OptimizationResultSet optResultSet = CopasiOptimizationSolver.solveLocalPython(new ParameterEstimationTaskSimulatorIDA(), parameterEstimationTask, copasiOptCallbacks, callback);
return optResultSet;
}
Aggregations