Search in sources :

Example 31 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class FRAPOptimizationUtils method doubleArrayToSolverResultSet.

// used by opt or sim data, no truncation of time/data. @param startingIndex is used to shift opt/sim times to compare with exp times
public static ODESolverResultSet doubleArrayToSolverResultSet(double[][] origData, double[] timePoints, double timePointOffset, boolean[] selectedROIs) /*throws Exception*/
{
    if (origData != null && timePoints != null && selectedROIs != null) {
        int numSelectedROITypes = 0;
        for (int i = 0; i < selectedROIs.length; i++) {
            if (selectedROIs[i]) {
                numSelectedROITypes++;
            }
        }
        ODESolverResultSet newOdeSolverResultSet = new ODESolverResultSet();
        newOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
        for (int j = 0; j < selectedROIs.length; j++) {
            if (!selectedROIs[j]) {
                continue;
            }
            String currentROIName = FRAPData.VFRAP_ROI_ENUM.values()[j].name();
            String name = currentROIName;
            newOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(name));
        }
        // set time
        for (int j = 0; j < timePoints.length; j++) {
            double[] row = new double[numSelectedROITypes + 1];
            row[0] = timePoints[j] + timePointOffset;
            newOdeSolverResultSet.addRow(row);
        }
        // set data
        int columncounter = 0;
        for (int j = 0; j < selectedROIs.length; j++) {
            if (!selectedROIs[j]) {
                continue;
            }
            double[] values = origData[j];
            for (int k = 0; k < values.length; k++) {
                newOdeSolverResultSet.setValue(k, columncounter + 1, values[k]);
            }
            columncounter++;
        }
        return newOdeSolverResultSet;
    }
    return null;
}
Also used : ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription)

Example 32 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class SpatialAnalysisResults method createSummaryReportSourceData.

// This function put exp data and sim data in a hashtable, the key is analysisParameters(right now only 1)
public Hashtable<AnalysisParameters, DataSource[]> createSummaryReportSourceData(final double[] frapDataTimeStamps, int startIndexForRecovery, boolean[] selecredROIs, boolean isSimData) throws Exception {
    Hashtable<AnalysisParameters, DataSource[]> allDataHash = new Hashtable<AnalysisParameters, DataSource[]>();
    Hashtable<CurveInfo, double[]> ROIInfoHash = curveHash;
    Set<CurveInfo> roiInfoSet = ROIInfoHash.keySet();
    Iterator<CurveInfo> roiInfoIter = roiInfoSet.iterator();
    // exp data are stored by ROI type.
    Hashtable<String, double[]> expROIData = new Hashtable<String, double[]>();
    // sim data are stored by AnalysisParameters and then by ROI type.
    Hashtable<AnalysisParameters, Hashtable<String, double[]>> simROIData = new Hashtable<AnalysisParameters, Hashtable<String, double[]>>();
    int roiCount = 0;
    // how many set of parameters are used for sim. 1 for now.
    int analysisParametersCount = 0;
    while (roiInfoIter.hasNext()) {
        CurveInfo roiCurveInfo = roiInfoIter.next();
        if (roiCurveInfo.isExperimentInfo()) {
            expROIData.put(roiCurveInfo.getROIName(), ROIInfoHash.get(roiCurveInfo));
            roiCount++;
        } else {
            Hashtable<String, double[]> simROIDataHash = simROIData.get(roiCurveInfo.getAnalysisParameters());
            if (simROIDataHash == null) {
                simROIDataHash = new Hashtable<String, double[]>();
                simROIData.put(roiCurveInfo.getAnalysisParameters(), simROIDataHash);
                analysisParametersCount++;
            }
            simROIDataHash.put(roiCurveInfo.getROIName(), ROIInfoHash.get(roiCurveInfo));
        }
    }
    // this is for exp data. each row of reference data contains time + intensities under 9 ROIs(bleached + ring1..8). totally 10 cols for each row.
    ReferenceData referenceData = createReferenceData(frapDataTimeStamps, startIndexForRecovery, "", selecredROIs);
    // loop only 1 time, right now the analysisParameters[]'s length is 1.
    for (int analysisParametersRow = 0; analysisParametersRow < analysisParametersCount; analysisParametersRow++) {
        AnalysisParameters currentAnalysisParameters = analysisParameters[analysisParametersRow];
        DataSource[] newDataSourceArr = new DataSource[2];
        // rows for time points and cols for t + roibleached + ring1--8 (10 cols)
        final DataSource expDataSource = new DataSource.DataSourceReferenceData("exp", referenceData);
        newDataSourceArr[ARRAY_INDEX_EXPDATASOURCE] = expDataSource;
        DataSource simDataSource = null;
        if (isSimData) {
            ODESolverResultSet odeSolverResultSet = createODESolverResultSet(currentAnalysisParameters, null, "");
            // rows for time points and cols for t + roibleached + ring1--8 (10 cols)
            simDataSource = new DataSource.DataSourceRowColumnResultSet("sim", odeSolverResultSet);
        }
        newDataSourceArr[ARRAY_INDEX_SIMDATASOURCE] = simDataSource;
        allDataHash.put(currentAnalysisParameters, newDataSourceArr);
    }
    return allDataHash;
}
Also used : Hashtable(java.util.Hashtable) DataSource(cbit.vcell.modelopt.DataSource) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet)

Example 33 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class SpatialAnalysisResults method createSummaryReportTableData.

public Object[][] createSummaryReportTableData(double[] frapDataTimeStamps, int startTimeIndex) {
    String[] summaryReportColumnNames = SpatialAnalysisResults.getSummaryReportColumnNames();
    final Object[][] tableData = new Object[analysisParameters.length][summaryReportColumnNames.length];
    for (int analysisParametersRow = 0; analysisParametersRow < analysisParameters.length; analysisParametersRow++) {
        AnalysisParameters currentAnalysisParameters = analysisParameters[analysisParametersRow];
        for (int roiColumn = 0; roiColumn < SpatialAnalysisResults.ORDERED_ROINAMES.length; roiColumn++) {
            ODESolverResultSet simDataSource = createODESolverResultSet(currentAnalysisParameters, SpatialAnalysisResults.ORDERED_ROINAMES[roiColumn], "");
            ReferenceData expDataSource = // TODO to remove null to put SpatialAnalysisResults.ORDERED_ROINAMES[roiColumn]
            createReferenceData(frapDataTimeStamps, startTimeIndex, "", null);
            int numSamples = expDataSource.getNumDataRows();
            double sumSquaredError = MathTestingUtilities.calcWeightedSquaredError(simDataSource, expDataSource);
            tableData[analysisParametersRow][roiColumn + ANALYSISPARAMETERS_COLUMNS_COUNT] = // unbiased estimator is numsamples-1
            Math.sqrt(sumSquaredError) / (numSamples - 1);
        }
    }
    return tableData;
}
Also used : SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet)

Example 34 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class MergedData method getODEDataBlock.

/**
 * Insert the method's description here.
 * Creation date: (1/14/00 2:28:47 PM)
 * @return cbit.vcell.simdata.ODEDataBlock
 */
public ODEDataBlock getODEDataBlock() throws DataAccessException {
    ODESolverResultSet combinedODESolverRSet = new ODESolverResultSet();
    ODEDataBlock refDataBlock = dataSetControllerImpl.getODEDataBlock(datasetsIDList[0]);
    ODESimData refSimData = refDataBlock.getODESimData();
    // Can use dataTimes field later (for genuine SimulationData), but for now, obtain it on the fly
    double[] times = null;
    try {
        int independentVarIndex = refSimData.findColumn("t");
        if (independentVarIndex < 0) {
            independentVarIndex = refSimData.findColumn(HISTOGRAM_INDEX_NAME);
        }
        times = refSimData.extractColumn(independentVarIndex);
    } catch (ExpressionException e) {
        e.printStackTrace(System.out);
    }
    // Adding data/function columns to new resultSet
    ODESolverResultSet[] resultSetList = new ODESolverResultSet[datasetsIDList.length];
    for (int i = 0; i < datasetsIDList.length; i++) {
        ODEDataBlock dataBlock = dataSetControllerImpl.getODEDataBlock(datasetsIDList[i]);
        ODESimData simData = dataBlock.getODESimData();
        ODESolverResultSet newODErset = new ODESolverResultSet();
        // First resultSet is reference resultSet. From the second onwards, resample the resultSet wrt the reference.
        if (i > 0) {
            try {
                newODErset = resampleODEData(refSimData, simData);
            } catch (ExpressionException e) {
                e.printStackTrace(System.out);
                throw new RuntimeException("\n >>>> Could not resample data! <<<<\n");
            }
        } else {
            newODErset = simData;
        }
        resultSetList[i] = newODErset;
        // Add data columns
        String[] newVarNames = new String[newODErset.getDataColumnCount()];
        for (int j = 0; j < newODErset.getDataColumnCount(); j++) {
            // If 'time' column is present in combinedResultSet, continue with next data column
            if ((combinedODESolverRSet.findColumn("t") > -1) && (newODErset.getDataColumnDescriptions()[j].getName().equals("t"))) {
                newVarNames[j] = newODErset.getDataColumnDescriptions()[j].getName();
                continue;
            }
            // Retain 'time' column as 't', without using datasetID as prefix to avoid multiple time columns in combinedODEResultSet.
            // Adding the time column from the first dataset to combinedResultSet, since it is treated as the reference dataset.
            String newColName = null;
            if (j == 0 && newODErset.getDataColumnDescriptions()[j].getName().equals("t")) {
                newColName = newODErset.getDataColumnDescriptions()[j].getName();
            } else {
                newColName = dataSetPrefix[i] + "." + newODErset.getDataColumnDescriptions()[j].getName();
            }
            newVarNames[j] = newColName;
            ColumnDescription cd = newODErset.getDataColumnDescriptions()[j];
            if (cd instanceof ODESolverResultSetColumnDescription) {
                ODESolverResultSetColumnDescription newCD = new ODESolverResultSetColumnDescription(newColName, cd.getParameterName(), newColName);
                combinedODESolverRSet.addDataColumn(newCD);
            }
        }
        // Add function columns
        for (int j = 0; j < newODErset.getFunctionColumnCount(); j++) {
            try {
                String newColName = dataSetPrefix[i] + "." + newODErset.getFunctionColumnDescriptions()[j].getName();
                FunctionColumnDescription fcd = newODErset.getFunctionColumnDescriptions()[j];
                Expression newExp = new Expression(fcd.getExpression());
                String[] symbols = newExp.getSymbols();
                if (symbols != null && (symbols.length > 0)) {
                    for (int jj = 0; jj < symbols.length; jj++) {
                        for (int kk = 0; kk < newVarNames.length; kk++) {
                            if (newVarNames[kk].equals(dataSetPrefix[i] + "." + symbols[jj])) {
                                newExp.substituteInPlace(new Expression(symbols[jj]), new Expression(newVarNames[kk]));
                                break;
                            }
                        }
                    }
                }
                FunctionColumnDescription newFcd = new FunctionColumnDescription(newExp, newColName, fcd.getParameterName(), newColName, fcd.getIsUserDefined());
                combinedODESolverRSet.addFunctionColumn(newFcd);
            } catch (ExpressionException e) {
                e.printStackTrace(System.out);
            }
        }
    }
    // Populating new dataset
    for (int i = 0; i < times.length; i++) {
        double[] newRow = new double[combinedODESolverRSet.getDataColumnCount()];
        int indx = 0;
        for (int j = 0; j < resultSetList.length; j++) {
            ODESolverResultSet resultSet = resultSetList[j];
            double[] tempRow = resultSet.getRow(i);
            int startIndx = 0;
            int arrayLen = tempRow.length;
            if (j > 0) {
                // From the second dataset onwards, we do not want to copy the time column, hence skip to
                // the next element/col in dataset, that reduces the # of elements in the row by 1.
                startIndx = 1;
                arrayLen = tempRow.length - 1;
            }
            System.arraycopy(tempRow, startIndx, newRow, indx, arrayLen);
            indx += tempRow.length;
        }
        combinedODESolverRSet.addRow(newRow);
    }
    ODEDataInfo odeDataInfo = new ODEDataInfo(getResultsInfoObject().getOwner(), getResultsInfoObject().getID(), 0);
    ODESimData odeSimData = new ODESimData(getResultsInfoObject(), combinedODESolverRSet);
    return new ODEDataBlock(odeDataInfo, odeSimData);
}
Also used : ColumnDescription(cbit.vcell.util.ColumnDescription) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription) ODESimData(cbit.vcell.solver.ode.ODESimData) ExpressionException(cbit.vcell.parser.ExpressionException) Expression(cbit.vcell.parser.Expression) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription)

Example 35 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class MergedData method resampleODEData.

/**
 * Insert the method's description here.
 * Creation date: (10/11/00 1:28:51 PM)
 * @param function cbit.vcell.math.Function
 */
private ODESolverResultSet resampleODEData(ODESimData refSimdata, ODESimData simData) throws ExpressionException {
    // If simData and refSimdata times are equal, return simData without resampling.
    // Else resampling is necessary.
    double[] refTimeArray = refSimdata.extractColumn(Math.max(refSimdata.findColumn(HISTOGRAM_INDEX_NAME), refSimdata.findColumn("t")));
    double[] timeArray = simData.extractColumn(Math.max(simData.findColumn(HISTOGRAM_INDEX_NAME), simData.findColumn("t")));
    if (refTimeArray.length == timeArray.length) {
        boolean bEqual = true;
        for (int i = 0; i < refTimeArray.length; i++) {
            if (refTimeArray[i] == timeArray[i]) {
                bEqual = bEqual && true;
            } else {
                bEqual = bEqual && false;
            }
        }
        if (bEqual) {
            return simData;
        }
    }
    ODESolverResultSet newODEresultSet = new ODESolverResultSet();
    for (int i = 0; i < simData.getDataColumnCount(); i++) {
        if (simData.getDataColumnDescriptions()[i] instanceof ODESolverResultSetColumnDescription) {
            ODESolverResultSetColumnDescription colDesc = ((ODESolverResultSetColumnDescription) simData.getDataColumnDescriptions()[i]);
            newODEresultSet.addDataColumn(colDesc);
        }
    }
    for (int i = 0; i < simData.getFunctionColumnCount(); i++) {
        FunctionColumnDescription colDesc = simData.getFunctionColumnDescriptions()[i];
        newODEresultSet.addFunctionColumn(colDesc);
    }
    double[][] resampledData = new double[refTimeArray.length][simData.getDataColumnCount()];
    for (int i = 0; i < simData.getDataColumnCount(); i++) {
        ColumnDescription colDesc = simData.getDataColumnDescriptions()[i];
        // If it is the first column (time), set value in new SimData to the timeArray values in refSimData.
        if (i == 0 && colDesc.getName().equals("t")) {
            for (int j = 0; j < refTimeArray.length; j++) {
                resampledData[j][i] = refTimeArray[j];
            }
            continue;
        }
        double[] data = simData.extractColumn(i);
        int k = 0;
        for (int j = 0; j < refTimeArray.length; j++) {
            // CHECK IF refTimeArray or timeArry has to be used here,
            while ((k < timeArray.length - 2) && (refTimeArray[j] > timeArray[k + 1])) {
                k++;
            }
            // apply first order linear basis for reference data interpolation.
            resampledData[j][i] = data[k] + (data[k + 1] - data[k]) * (refTimeArray[j] - timeArray[k]) / (timeArray[k + 1] - timeArray[k]);
        }
    }
    for (int i = 0; i < refTimeArray.length; i++) {
        newODEresultSet.addRow(resampledData[i]);
    }
    return newODEresultSet;
}
Also used : ColumnDescription(cbit.vcell.util.ColumnDescription) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription)

Aggregations

ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)37 ODESolverResultSetColumnDescription (cbit.vcell.math.ODESolverResultSetColumnDescription)18 FunctionColumnDescription (cbit.vcell.math.FunctionColumnDescription)11 Expression (cbit.vcell.parser.Expression)10 DataSource (cbit.vcell.modelopt.DataSource)9 ReferenceData (cbit.vcell.opt.ReferenceData)8 ExpressionException (cbit.vcell.parser.ExpressionException)7 Simulation (cbit.vcell.solver.Simulation)7 SimulationSymbolTable (cbit.vcell.solver.SimulationSymbolTable)6 SolverException (cbit.vcell.solver.SolverException)6 IOException (java.io.IOException)6 Variable (cbit.vcell.math.Variable)4 SimulationTask (cbit.vcell.messaging.server.SimulationTask)4 SimpleReferenceData (cbit.vcell.opt.SimpleReferenceData)4 SbmlException (org.vcell.sbml.SbmlException)4 SBMLImportException (org.vcell.sbml.vcell.SBMLImportException)4 BioModel (cbit.vcell.biomodel.BioModel)3 Function (cbit.vcell.math.Function)3 MathDescription (cbit.vcell.math.MathDescription)3 MathException (cbit.vcell.math.MathException)3