Search in sources :

Example 1 with ReferenceData

use of cbit.vcell.opt.ReferenceData 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);
    }
}
Also used : Variable(cbit.vcell.math.Variable) MultisourcePlotPane(cbit.vcell.modelopt.gui.MultisourcePlotPane) ReferenceDataMappingSpec(cbit.vcell.modelopt.ReferenceDataMappingSpec) ReservedSymbol(cbit.vcell.model.Model.ReservedSymbol) ModelOptimizationSpec(cbit.vcell.modelopt.ModelOptimizationSpec) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ParameterEstimationTaskSimulatorIDA(org.vcell.optimization.ParameterEstimationTaskSimulatorIDA) OptimizationException(cbit.vcell.opt.OptimizationException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) DataSource(cbit.vcell.modelopt.DataSource) SortDataReferenceHelper(cbit.vcell.modelopt.gui.MultisourcePlotListModel.SortDataReferenceHelper) ReferenceData(cbit.vcell.opt.ReferenceData)

Example 2 with ReferenceData

use of cbit.vcell.opt.ReferenceData in project vcell by virtualcell.

the class ReferenceDataPanel method updateReferenceDataFromFile.

/**
 * Comment
 */
private void updateReferenceDataFromFile() {
    try {
        VCFileChooser fileChooser = new VCFileChooser();
        fileChooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_ONLY);
        fileChooser.setMultiSelectionEnabled(false);
        fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_CSV);
        // Set the default file filter...
        fileChooser.setFileFilter(FileFilters.FILE_FILTER_CSV);
        // remove all selector
        fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
        File defaultPath = null;
        if (getUserPreferences() != null) {
            defaultPath = getUserPreferences().getCurrentDialogPath();
            if (defaultPath != null) {
                fileChooser.setCurrentDirectory(defaultPath);
            }
        }
        fileChooser.setDialogTitle("Import Data File");
        if (fileChooser.showOpenDialog(this) != javax.swing.JFileChooser.APPROVE_OPTION) {
            // user didn't choose save
            throw UserCancelException.CANCEL_FILE_SELECTION;
        } else {
            File selectedFile = fileChooser.getSelectedFile();
            if (selectedFile == null) {
                // no file selected (no name given)
                throw UserCancelException.CANCEL_FILE_SELECTION;
            } else {
                if (getUserPreferences() != null) {
                    File newPath = selectedFile.getParentFile();
                    if (!newPath.equals(defaultPath)) {
                        getUserPreferences().setCurrentDialogPath(newPath);
                    }
                }
                CSV csv = new CSV();
                RowColumnResultSet rowColumnResultSet = csv.importFrom(new java.io.FileReader(selectedFile));
                double[] weights = new double[rowColumnResultSet.getDataColumnCount()];
                java.util.Arrays.fill(weights, 1.0);
                ReferenceData referenceData = new SimpleReferenceData(rowColumnResultSet, weights);
                updateReferenceData(referenceData);
            }
        }
    } catch (UserCancelException e) {
    // ignore
    } catch (Exception e) {
        e.printStackTrace();
        if (e instanceof ParseException) {
            showHelp((ParseException) e);
        } else {
            DialogUtils.showErrorDialog(this, e.getMessage(), e);
        }
    }
}
Also used : SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) CSV(cbit.vcell.math.CSV) VCFileChooser(org.vcell.util.gui.VCFileChooser) UserCancelException(org.vcell.util.UserCancelException) ParseException(java.text.ParseException) File(java.io.File) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ParseException(java.text.ParseException) UserCancelException(org.vcell.util.UserCancelException) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet)

Example 3 with ReferenceData

use of cbit.vcell.opt.ReferenceData 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;
    }
}
Also used : SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ParseException(java.text.ParseException) UserCancelException(org.vcell.util.UserCancelException) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet)

Example 4 with ReferenceData

use of cbit.vcell.opt.ReferenceData in project vcell by virtualcell.

the class EstParams_CompareResultsDescriptor method aboutToDisplayPanel.

public void aboutToDisplayPanel() {
    FRAPStudy fStudy = frapWorkspace.getWorkingFrapStudy();
    // create Mean square error for different models under different ROIs
    // if(fStudy.getAnalysisMSESummaryData() == null)
    // {
    fStudy.createAnalysisMSESummaryData();
    // }
    // auto find best model for user if best model is not selected.
    double[][] mseSummaryData = fStudy.getAnalysisMSESummaryData();
    // for(int i =0; i<10; i++)
    // System.out.print(mseSummaryData[0][i]+"  ");
    // find best model with significance and has least error
    int bestModel = FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT;
    if (// best model is saved and there is no model selection change
    fStudy.getBestModelIndex() != null) {
        bestModel = fStudy.getBestModelIndex().intValue();
    } else // need to find the best model
    {
        // check model significance if more than one model
        if (fStudy.getSelectedModels().size() > 1) {
            if (getFrapWorkspace().getWorkingFrapStudy().getFrapOptData() != null || getFrapWorkspace().getWorkingFrapStudy().getFrapOptFunc() != null) {
                ProfileSummaryData[][] allProfileSumData = FRAPOptimizationUtils.getAllProfileSummaryData(fStudy);
                FRAPModel[] frapModels = frapWorkspace.getWorkingFrapStudy().getModels();
                int confidenceIdx = ((EstParams_CompareResultsPanel) this.getPanelComponent()).getSelectedConfidenceIndex();
                boolean[] modelSignificance = new boolean[FRAPModel.NUM_MODEL_TYPES];
                Arrays.fill(modelSignificance, true);
                if (frapModels[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] != null && frapModels[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() != null && allProfileSumData != null && allProfileSumData[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] != null) {
                    for (int i = 0; i < FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF; i++) {
                        ConfidenceInterval[] intervals = allProfileSumData[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT][i].getConfidenceIntervals();
                        if (intervals[confidenceIdx].getUpperBound() == frapModels[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters()[i].getUpperBound() && intervals[confidenceIdx].getLowerBound() == frapModels[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters()[i].getLowerBound()) {
                            modelSignificance[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] = false;
                            break;
                        }
                    }
                }
                if (frapModels[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] != null && frapModels[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters() != null && allProfileSumData != null && allProfileSumData[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] != null) {
                    for (int i = 0; i < FRAPModel.NUM_MODEL_PARAMETERS_TWO_DIFF; i++) {
                        ConfidenceInterval[] intervals = allProfileSumData[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS][i].getConfidenceIntervals();
                        if (intervals[confidenceIdx].getUpperBound() == frapModels[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters()[i].getUpperBound() && intervals[confidenceIdx].getLowerBound() == frapModels[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters()[i].getLowerBound()) {
                            modelSignificance[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] = false;
                            break;
                        }
                    }
                }
                if (frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] != null && frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters() != null && allProfileSumData != null && allProfileSumData[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] != null) {
                    for (int i = 0; i < FRAPModel.NUM_MODEL_PARAMETERS_REACTION_OFF_RATE; i++) {
                        if (i == FRAPModel.INDEX_BLEACH_MONITOR_RATE) {
                            ConfidenceInterval[] intervals = allProfileSumData[FRAPModel.IDX_MODEL_REACTION_OFF_RATE][FRAPModel.INDEX_BLEACH_MONITOR_RATE].getConfidenceIntervals();
                            if (intervals[confidenceIdx].getUpperBound() == frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters()[FRAPModel.INDEX_BLEACH_MONITOR_RATE].getUpperBound() && intervals[confidenceIdx].getLowerBound() == frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters()[FRAPModel.INDEX_BLEACH_MONITOR_RATE].getLowerBound()) {
                                modelSignificance[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] = false;
                                break;
                            }
                        } else if (i == FRAPModel.INDEX_OFF_RATE) {
                            ConfidenceInterval[] intervals = allProfileSumData[FRAPModel.IDX_MODEL_REACTION_OFF_RATE][FRAPModel.INDEX_OFF_RATE].getConfidenceIntervals();
                            if (intervals[confidenceIdx].getUpperBound() == frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters()[FRAPModel.INDEX_OFF_RATE].getUpperBound() && intervals[confidenceIdx].getLowerBound() == frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters()[FRAPModel.INDEX_OFF_RATE].getLowerBound()) {
                                modelSignificance[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] = false;
                                break;
                            }
                        }
                    }
                }
                // check least error model with significance
                double minError = 1E8;
                if (mseSummaryData != null) {
                    // exclude cell and bkground ROIs, include sum of error
                    int secDimLen = FRAPData.VFRAP_ROI_ENUM.values().length - 2 + 1;
                    if (modelSignificance[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] == modelSignificance[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] && modelSignificance[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] == modelSignificance[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS]) {
                        // if all models' significance are the same, find the least error
                        for (int i = 0; i < FRAPModel.NUM_MODEL_TYPES; i++) {
                            if ((minError > mseSummaryData[i][secDimLen - 1])) {
                                minError = mseSummaryData[i][secDimLen - 1];
                                bestModel = i;
                            }
                        }
                    } else {
                        // if models' significance are different, find the least error with significance
                        for (int i = 0; i < FRAPModel.NUM_MODEL_TYPES; i++) {
                            if (modelSignificance[i] && (minError > mseSummaryData[i][secDimLen - 1])) {
                                minError = mseSummaryData[i][secDimLen - 1];
                                bestModel = i;
                            }
                        }
                    }
                }
            }
        } else // only one model is selected and the selected model should be the best model
        {
            for (int i = 0; i < fStudy.getModels().length; i++) {
                if (fStudy.getModels()[i] != null) {
                    bestModel = i;
                    break;
                }
            }
        }
    }
    ((EstParams_CompareResultsPanel) this.getPanelComponent()).setBestModelRadioButton(bestModel);
    // set data source to multiSourcePlotPane
    // length should be fStudy.getSelectedModels().size()+1, however, reaction binding may not have data
    ArrayList<DataSource> comparableDataSource = new ArrayList<DataSource>();
    // add exp data
    ReferenceData expReferenceData = FRAPOptimizationUtils.doubleArrayToSimpleRefData(fStudy.getDimensionReducedExpData(), fStudy.getFrapData().getImageDataset().getImageTimeStamps(), fStudy.getStartingIndexForRecovery(), fStudy.getSelectedROIsForErrorCalculation());
    final DataSource expDataSource = new DataSource.DataSourceReferenceData("exp", expReferenceData);
    comparableDataSource.add(expDataSource);
    // add opt/sim data
    // using the same loop, disable the radio button if the model is not included
    // adjust radio buttons
    ((EstParams_CompareResultsPanel) this.getPanelComponent()).disableAllRadioButtons();
    ArrayList<Integer> selectedModelIndexes = fStudy.getSelectedModels();
    for (int i = 0; i < selectedModelIndexes.size(); i++) {
        DataSource newDataSource = null;
        double[] timePoints = fStudy.getFrapData().getImageDataset().getImageTimeStamps();
        int startingIndex = fStudy.getStartingIndexForRecovery();
        double[] truncatedTimes = new double[timePoints.length - startingIndex];
        System.arraycopy(timePoints, startingIndex, truncatedTimes, 0, truncatedTimes.length);
        if (selectedModelIndexes.get(i).equals(FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT)) {
            // adjust radio button
            ((EstParams_CompareResultsPanel) this.getPanelComponent()).enableRadioButton(FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT);
            FRAPModel temModel = fStudy.getFrapModel(FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT);
            ODESolverResultSet temSolverResultSet = FRAPOptimizationUtils.doubleArrayToSolverResultSet(temModel.getData(), truncatedTimes, 0, fStudy.getSelectedROIsForErrorCalculation());
            newDataSource = new DataSource.DataSourceRowColumnResultSet("opt_DF1", temSolverResultSet);
        } else if (selectedModelIndexes.get(i).equals(FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS)) {
            // adjust radio button
            ((EstParams_CompareResultsPanel) this.getPanelComponent()).enableRadioButton(FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS);
            FRAPModel temModel = fStudy.getFrapModel(FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS);
            ODESolverResultSet temSolverResultSet = FRAPOptimizationUtils.doubleArrayToSolverResultSet(temModel.getData(), truncatedTimes, 0, fStudy.getSelectedROIsForErrorCalculation());
            newDataSource = new DataSource.DataSourceRowColumnResultSet("opt_DF2", temSolverResultSet);
        } else if (selectedModelIndexes.get(i).equals(FRAPModel.IDX_MODEL_REACTION_OFF_RATE)) {
            // adjust radio button
            ((EstParams_CompareResultsPanel) this.getPanelComponent()).enableRadioButton(FRAPModel.IDX_MODEL_REACTION_OFF_RATE);
            FRAPModel temModel = fStudy.getFrapModel(FRAPModel.IDX_MODEL_REACTION_OFF_RATE);
            if (temModel.getData() != null) {
                ODESolverResultSet temSolverResultSet = FRAPOptimizationUtils.doubleArrayToSolverResultSet(temModel.getData(), truncatedTimes, 0, // for reaction off model, display curve under bleached region only
                FRAPStudy.createSelectedROIsForReactionOffRateModel());
                newDataSource = new DataSource.DataSourceRowColumnResultSet("sim_Koff", temSolverResultSet);
            }
        }
        if (newDataSource != null) {
            comparableDataSource.add(newDataSource);
        }
    }
    // set data to multiSourcePlotPane
    ((EstParams_CompareResultsPanel) this.getPanelComponent()).setPlotData(comparableDataSource.toArray(new DataSource[comparableDataSource.size()]));
}
Also used : ArrayList(java.util.ArrayList) FRAPModel(cbit.vcell.microscopy.FRAPModel) DataSource(cbit.vcell.modelopt.DataSource) ReferenceData(cbit.vcell.opt.ReferenceData) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ConfidenceInterval(org.vcell.optimization.ConfidenceInterval)

Example 5 with ReferenceData

use of cbit.vcell.opt.ReferenceData 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;
}
Also used : ParameterVariable(cbit.vcell.math.ParameterVariable) Variable(cbit.vcell.math.Variable) ReservedSymbol(cbit.vcell.model.Model.ReservedSymbol) ReservedSymbol(cbit.vcell.model.Model.ReservedSymbol) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MatrixException(cbit.vcell.matrix.MatrixException) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) Vector(java.util.Vector) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ModelException(cbit.vcell.model.ModelException) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) MathException(cbit.vcell.math.MathException) Model(cbit.vcell.model.Model)

Aggregations

ReferenceData (cbit.vcell.opt.ReferenceData)17 SimpleReferenceData (cbit.vcell.opt.SimpleReferenceData)13 ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)8 DataSource (cbit.vcell.modelopt.DataSource)6 ExpressionException (cbit.vcell.parser.ExpressionException)5 ODESolverResultSetColumnDescription (cbit.vcell.math.ODESolverResultSetColumnDescription)4 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)4 Variable (cbit.vcell.math.Variable)3 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)3 ParseException (java.text.ParseException)3 Vector (java.util.Vector)3 Element (org.jdom.Element)3 UserCancelException (org.vcell.util.UserCancelException)3 MappingException (cbit.vcell.mapping.MappingException)2 CSV (cbit.vcell.math.CSV)2 Constant (cbit.vcell.math.Constant)2 FunctionColumnDescription (cbit.vcell.math.FunctionColumnDescription)2 MathException (cbit.vcell.math.MathException)2 ParameterVariable (cbit.vcell.math.ParameterVariable)2 MatrixException (cbit.vcell.matrix.MatrixException)2