use of cbit.vcell.math.ODESolverResultSetColumnDescription in project vcell by virtualcell.
the class ReferenceDataPanel method subsample.
/**
* Comment
*/
private ReferenceData subsample() {
ReferenceData refData = fieldParameterEstimationTask.getModelOptimizationSpec().getReferenceData();
if (refData == null) {
return refData;
}
RowColumnResultSet rc = new RowColumnResultSet();
String[] columnNames = refData.getColumnNames();
for (int i = 0; i < columnNames.length; i++) {
rc.addDataColumn(new ODESolverResultSetColumnDescription(i == timeIndex ? ReservedVariable.TIME.getName() : columnNames[i]));
}
for (int i = 0; i < refData.getNumDataRows(); i++) {
rc.addRow((double[]) refData.getDataByRow(i).clone());
}
int desiredNumRows = refData.getNumDataRows() / 2;
if (desiredNumRows < 3) {
return refData;
}
try {
rc.trimRows(desiredNumRows);
double[] weights = null;
if (refData.getColumnWeights() != null) {
weights = (double[]) refData.getColumnWeights().clone();
} else {
weights = new double[refData.getColumnNames().length];
java.util.Arrays.fill(weights, 1.0);
}
SimpleReferenceData srd = new SimpleReferenceData(rc, weights);
return srd;
} catch (Exception e) {
e.printStackTrace(System.out);
DialogUtils.showErrorDialog(this, e.getMessage(), e);
return refData;
}
}
use of cbit.vcell.math.ODESolverResultSetColumnDescription in project vcell by virtualcell.
the class EstParams_OneDiffComponentPanel method plotDerivedSimulationResults.
private void plotDerivedSimulationResults(AnalysisParameters[] anaParams) {
try {
String description = null;
int totalROIlen = FRAPData.VFRAP_ROI_ENUM.values().length;
boolean[] wantsROITypes = new boolean[totalROIlen];
System.arraycopy(frapWorkspace.getWorkingFrapStudy().getSelectedROIsForErrorCalculation(), 0, wantsROITypes, 0, totalROIlen);
ODESolverResultSet fitOdeSolverResultSet = new ODESolverResultSet();
fitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
for (int j = 0; j < totalROIlen; j++) {
if (!wantsROITypes[j]) {
continue;
}
String currentROIName = FRAPData.VFRAP_ROI_ENUM.values()[j].name();
String name = (description == null ? /*"sim D="+diffusionRates[diffusionRateIndex]+"::"*/
"" : description) + currentROIName;
fitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(name));
}
int totalWantedROIlen = 0;
for (int i = 0; i < wantsROITypes.length; i++) {
if (wantsROITypes[i]) {
totalWantedROIlen++;
}
}
//
// populate time
//
double[] shiftedSimTimes = frapOptData.getReducedExpTimePoints();
int startIndexRecovery = frapOptData.getExpFrapStudy().getStartingIndexForRecovery();
for (int j = 0; j < shiftedSimTimes.length; j++) {
double[] row = new double[totalWantedROIlen + 1];
row[0] = shiftedSimTimes[j] + frapOptData.getExpFrapStudy().getFrapData().getImageDataset().getImageTimeStamps()[startIndexRecovery];
fitOdeSolverResultSet.addRow(row);
}
// populate values
double[][] currentOptFitData = getPureDiffusionPanel().getCurrentFitData();
// store results
setCurrentEstimationResults(currentOptFitData);
if (allDataHash != null && currentOptFitData != null) {
// populate optimization data
int columncounter = 0;
for (int j = 0; j < totalROIlen; j++) {
if (!wantsROITypes[j]) {
continue;
}
// if(!isSimData) //opt data
// {
double[] values = currentOptFitData[j];
for (int k = 0; k < values.length; k++) {
fitOdeSolverResultSet.setValue(k, columncounter + 1, values[k]);
}
// }
columncounter++;
}
// boolean hasSimData = false;
// anaParams[0] is the key in allDataHash to get the dataSource[]:exp & sim
DataSource[] selectedRowDataSourceArr = allDataHash.get(anaParams[0]);
if (selectedRowDataSourceArr != null) {
// referenceData is the exp data
// ReferenceData referenceData = (ReferenceData)selectedRowDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE];
// new DataSource.DataSourceReferenceData("exp", referenceData);
final DataSource expDataSource = selectedRowDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE];
DataSource optDataSource = new DataSource.DataSourceRowColumnResultSet("opt", fitOdeSolverResultSet);
DataSource[] newDataSourceArr = new DataSource[2];
newDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE] = expDataSource;
newDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_SIMDATASOURCE] = optDataSource;
if (currentOptFitData == null) {
multisourcePlotPane.setDataSources(null);
} else {
// the following paragraph of code is just to get selected color for selected ROIs
// and make them the same as we show on ChooseModel_RoiForErrorPanel/RoiForErrorPanel
// double valid ROI colors (not include cell and background)
int validROISize = FRAPData.VFRAP_ROI_ENUM.values().length - 2;
Color[] fullColors = ColorUtil.generateAutoColor(validROISize * 2, getBackground(), new Integer(0));
boolean[] selectedROIs = frapWorkspace.getWorkingFrapStudy().getSelectedROIsForErrorCalculation();
int selectedROICounter = 0;
for (int i = 0; i < selectedROIs.length; i++) {
if (selectedROIs[i]) {
selectedROICounter++;
}
}
// double the size, each ROI is a comparison of exp and sim
Color[] selectedColors = new Color[selectedROICounter * 2];
int selectedColorIdx = 0;
for (int i = 0; i < selectedROIs.length; i++) {
if (selectedROIs[i] && i == 0) {
selectedColors[selectedColorIdx] = fullColors[i];
selectedColors[selectedColorIdx + selectedROICounter] = fullColors[i + validROISize];
selectedColorIdx++;
}
if (// skip cell and background ROIs
selectedROIs[i] && i > 2) {
selectedColors[selectedColorIdx] = fullColors[i - 2];
selectedColors[selectedColorIdx + selectedROICounter] = fullColors[i - 2 + validROISize];
selectedColorIdx++;
}
}
int[] selectedIndices = multisourcePlotPane.getUnsortedSelectedIndices();
multisourcePlotPane.setDataSources(newDataSourceArr, selectedColors);
if (selectedIndices.length == 0) {
multisourcePlotPane.selectAll();
} else {
multisourcePlotPane.setUnsortedSelectedIndices(selectedIndices);
}
}
}
}
} catch (Exception e2) {
e2.printStackTrace();
DialogUtils.showErrorDialog(this, "Error graphing Optimizer data " + e2.getMessage());
}
}
use of cbit.vcell.math.ODESolverResultSetColumnDescription in project vcell by virtualcell.
the class EstParams_ReacBindingPanel method plotDerivedSimulationResults.
private void plotDerivedSimulationResults(AnalysisParameters[] anaParams) {
try {
if (getCurrentSimResults() == null || getCurrentRawSimTimePoints() == null || allDataHash == null || allDataHash.get(anaParams[0]) == null || (allDataHash.get(anaParams[0])[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE]) == null) {
multisourcePlotPane.setDataSources(null);
return;
}
String description = null;
int totalROIlen = FRAPData.VFRAP_ROI_ENUM.values().length;
boolean[] wantsROITypes = new boolean[totalROIlen];
System.arraycopy(frapWorkspace.getWorkingFrapStudy().getSelectedROIsForErrorCalculation(), 0, wantsROITypes, 0, totalROIlen);
ODESolverResultSet simSolverResultSet = new ODESolverResultSet();
simSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
for (int j = 0; j < totalROIlen; j++) {
if (!wantsROITypes[j]) {
continue;
}
String currentROIName = FRAPData.VFRAP_ROI_ENUM.values()[j].name();
String name = (description == null ? /*"sim D="+diffusionRates[diffusionRateIndex]+"::"*/
"" : description) + currentROIName;
simSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(name));
}
int totalWantedROIlen = 0;
for (int i = 0; i < wantsROITypes.length; i++) {
if (wantsROITypes[i]) {
totalWantedROIlen++;
}
}
FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
//
// populate time
//
double[] shiftedSimTimes = getCurrentRawSimTimePoints();
int startIndexRecovery = fStudy.getStartingIndexForRecovery();
for (int j = 0; j < shiftedSimTimes.length; j++) {
double[] row = new double[totalWantedROIlen + 1];
row[0] = shiftedSimTimes[j] + fStudy.getFrapData().getImageDataset().getImageTimeStamps()[startIndexRecovery];
simSolverResultSet.addRow(row);
}
//
// populate values
//
double[][] currentSimData = getCurrentSimResults();
// populate sim data
int columncounter = 0;
for (int j = 0; j < totalROIlen; j++) {
if (!wantsROITypes[j]) {
continue;
}
double[] values = currentSimData[j];
for (int k = 0; k < values.length; k++) {
simSolverResultSet.setValue(k, columncounter + 1, values[k]);
}
columncounter++;
}
// get exp data and generate datasource to display
// anaParams[0] is the key in allDataHash to get the dataSource[]:exp & sim
DataSource[] selectedRowDataSourceArr = allDataHash.get(anaParams[0]);
if (selectedRowDataSourceArr != null) {
// referenceData is the exp data
// ReferenceData referenceData = (ReferenceData)selectedRowDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE].getSource();
final DataSource expDataSource = /*new DataSource(referenceData,"exp")*/
selectedRowDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE];
// from simulation
final DataSource simDataSource = new DataSource.DataSourceRowColumnResultSet("sim", simSolverResultSet);
DataSource[] newDataSourceArr = new DataSource[2];
newDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE] = expDataSource;
newDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_SIMDATASOURCE] = simDataSource;
// the following paragraph of code is just to get selected color for selected ROIs
// and make them the same as we show on ChooseModel_RoiForErrorPanel/RoiForErrorPanel
// double valid ROI colors (not include cell and background)
int validROISize = FRAPData.VFRAP_ROI_ENUM.values().length - 2;
Color[] fullColors = ColorUtil.generateAutoColor(validROISize * 2, getBackground(), new Integer(0));
boolean[] selectedROIs = frapWorkspace.getWorkingFrapStudy().getSelectedROIsForErrorCalculation();
int selectedROICounter = 0;
for (int i = 0; i < selectedROIs.length; i++) {
if (selectedROIs[i]) {
selectedROICounter++;
}
}
// double the size, each ROI is a comparison of exp and sim
Color[] selectedColors = new Color[selectedROICounter * 2];
int selectedColorIdx = 0;
for (int i = 0; i < selectedROIs.length; i++) {
if (selectedROIs[i] && i == 0) {
selectedColors[selectedColorIdx] = fullColors[i];
selectedColors[selectedColorIdx + selectedROICounter] = fullColors[i + validROISize];
selectedColorIdx++;
}
if (// skip cell and background ROIs
selectedROIs[i] && i > 2) {
selectedColors[selectedColorIdx] = fullColors[i - 2];
selectedColors[selectedColorIdx + selectedROICounter] = fullColors[i - 2 + validROISize];
selectedColorIdx++;
}
}
multisourcePlotPane.setDataSources(newDataSourceArr, selectedColors);
multisourcePlotPane.selectAll();
}
} catch (Exception e2) {
e2.printStackTrace();
DialogUtils.showErrorDialog(this, "Error graphing Optimizer data " + e2.getMessage());
}
}
use of cbit.vcell.math.ODESolverResultSetColumnDescription in project vcell by virtualcell.
the class ModelOptimizationMapping method getRemappedReferenceData.
/**
* Gets the constraintData property (cbit.vcell.opt.ConstraintData) value.
* @return The constraintData property value.
* @see #setConstraintData
*/
private ReferenceData getRemappedReferenceData(MathMapping mathMapping) throws MappingException {
if (modelOptimizationSpec.getReferenceData() == null) {
return null;
}
//
// make sure time is mapped
//
ReferenceData refData = modelOptimizationSpec.getReferenceData();
ReferenceDataMappingSpec[] refDataMappingSpecs = modelOptimizationSpec.getReferenceDataMappingSpecs();
RowColumnResultSet rowColResultSet = new RowColumnResultSet();
Vector<SymbolTableEntry> modelObjectList = new Vector<SymbolTableEntry>();
Vector<double[]> dataList = new Vector<double[]>();
//
// find bound columns, (time is always mapped to the first column)
//
int mappedColumnCount = 0;
for (int i = 0; i < refDataMappingSpecs.length; i++) {
SymbolTableEntry modelObject = refDataMappingSpecs[i].getModelObject();
if (modelObject != null) {
int mappedColumnIndex = mappedColumnCount;
if (modelObject instanceof Model.ReservedSymbol && ((ReservedSymbol) modelObject).isTime()) {
mappedColumnIndex = 0;
}
String origRefDataColumnName = refDataMappingSpecs[i].getReferenceDataColumnName();
int origRefDataColumnIndex = refData.findColumn(origRefDataColumnName);
if (origRefDataColumnIndex < 0) {
throw new RuntimeException("reference data column named '" + origRefDataColumnName + "' not found");
}
double[] columnData = refData.getDataByColumn(origRefDataColumnIndex);
if (modelObjectList.contains(modelObject)) {
throw new RuntimeException("multiple reference data columns mapped to same model object '" + modelObject.getName() + "'");
}
modelObjectList.insertElementAt(modelObject, mappedColumnIndex);
dataList.insertElementAt(columnData, mappedColumnIndex);
mappedColumnCount++;
}
}
//
if (modelObjectList.size() == 0) {
throw new RuntimeException("reference data was not associated with model");
}
if (modelObjectList.size() == 1) {
throw new RuntimeException("reference data was not associated with model, must map time and at least one other column");
}
boolean bFoundTimeVar = false;
for (SymbolTableEntry ste : modelObjectList) {
if (ste instanceof Model.ReservedSymbol && ((ReservedSymbol) ste).isTime()) {
bFoundTimeVar = true;
break;
}
}
if (!bFoundTimeVar) {
throw new RuntimeException("must map time column of reference data to model");
}
//
for (int i = 0; i < modelObjectList.size(); i++) {
SymbolTableEntry modelObject = (SymbolTableEntry) modelObjectList.elementAt(i);
try {
// Find by name because MathSybolMapping has different 'objects' than refDataMapping 'objects'
Variable variable = mathMapping.getMathSymbolMapping().findVariableByName(modelObject.getName());
if (variable != null) {
String symbol = variable.getName();
rowColResultSet.addDataColumn(new ODESolverResultSetColumnDescription(symbol));
} else if (modelObject instanceof Model.ReservedSymbol && ((Model.ReservedSymbol) modelObject).isTime()) {
Model.ReservedSymbol time = (Model.ReservedSymbol) modelObject;
String symbol = time.getName();
rowColResultSet.addDataColumn(new ODESolverResultSetColumnDescription(symbol));
}
} catch (MathException | MatrixException | ExpressionException | ModelException e) {
e.printStackTrace();
throw new MappingException(e.getMessage(), e);
}
}
//
// populate data columns (time and rest)
//
double[] weights = new double[rowColResultSet.getColumnDescriptionsCount()];
weights[0] = 1.0;
int numRows = ((double[]) dataList.elementAt(0)).length;
int numColumns = modelObjectList.size();
for (int j = 0; j < numRows; j++) {
double[] row = new double[numColumns];
for (int i = 0; i < numColumns; i++) {
row[i] = ((double[]) dataList.elementAt(i))[j];
if (i > 0) {
weights[i] += row[i] * row[i];
}
}
rowColResultSet.addRow(row);
}
for (int i = 0; i < numColumns; i++) {
if (weights[i] == 0) {
weights[i] = 1;
} else {
weights[i] = 1 / weights[i];
}
}
SimpleReferenceData remappedRefData = new SimpleReferenceData(rowColResultSet, weights);
return remappedRefData;
}
use of cbit.vcell.math.ODESolverResultSetColumnDescription in project vcell by virtualcell.
the class MathTestingUtilities method getConstructedResultSet.
/**
* Insert the method's description here.
* Creation date: (1/17/2003 3:47:43 PM)
* @return cbit.vcell.solver.ode.ODESolverResultSet
* @param sim cbit.vcell.solver.Simulation
*/
public static ODESolverResultSet getConstructedResultSet(MathDescription mathDesc, double[] time) throws Exception {
if (mathDesc.getGeometry().getDimension() != 0) {
throw new RuntimeException("can only handle non-spatial simulations.");
}
Simulation sim = new Simulation(mathDesc);
SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(sim, 0);
ODESolverResultSet resultSet = new ODESolverResultSet();
resultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
for (int i = 0; i < time.length; i++) {
resultSet.addRow(new double[] { time[i] });
}
java.util.Enumeration<SubDomain> subDomainEnum = mathDesc.getSubDomains();
String errorString = "Variable(s) : ";
while (subDomainEnum.hasMoreElements()) {
SubDomain subDomain = subDomainEnum.nextElement();
java.util.Enumeration<Equation> enumEquations = subDomain.getEquations();
while (enumEquations.hasMoreElements()) {
Equation equation = enumEquations.nextElement();
Expression constructedSolution = equation.getExactSolution();
if (constructedSolution != null) {
constructedSolution = new Expression(constructedSolution);
constructedSolution.bindExpression(simSymbolTable);
constructedSolution = simSymbolTable.substituteFunctions(constructedSolution);
constructedSolution = constructedSolution.flatten();
resultSet.addFunctionColumn(new FunctionColumnDescription(constructedSolution, equation.getVariable().getName(), null, equation.getVariable().getName(), false));
} else {
errorString = errorString + equation.getVariable().getName() + ", ";
}
}
}
if (!errorString.equals("Variable(s) : ")) {
throw new RuntimeException(errorString + " don't have a constructed solution");
}
return resultSet;
}
Aggregations