Search in sources :

Example 16 with ODESolverResultSet

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

the class FRAPEstimationPanel_NotUsed method displayFit.

private void displayFit(FrapDataAnalysisResults.DiffusionOnlyAnalysisRestults diffAnalysisResults, double[] frapDataTimeStamps, int startIndexForRecovery) {
    if (diffAnalysisResults == null) {
        FRAPParameterEstimateEnum.DIFFUSION_RATE.value = null;
        FRAPParameterEstimateEnum.MOBILE_FRACTION.value = null;
        FRAPParameterEstimateEnum.IMMOBILE_FRATION.value = null;
        FRAPParameterEstimateEnum.START_TIME_RECOVERY.value = null;
        FRAPParameterEstimateEnum.BLEACH_RATE_MONITOR.value = null;
        multisourcePlotPane.setDataSources(null);
    } else {
        FRAPParameterEstimateEnum.DIFFUSION_RATE.value = (diffAnalysisResults.getRecoveryDiffusionRate() == null ? null : diffAnalysisResults.getRecoveryDiffusionRate());
        FRAPParameterEstimateEnum.MOBILE_FRACTION.value = (diffAnalysisResults.getMobilefraction() == null ? null : diffAnalysisResults.getMobilefraction());
        FRAPParameterEstimateEnum.IMMOBILE_FRATION.value = (FRAPParameterEstimateEnum.MOBILE_FRACTION.value == null ? null : 1.0 - FRAPParameterEstimateEnum.MOBILE_FRACTION.value);
        FRAPParameterEstimateEnum.BLEACH_RATE_MONITOR.value = (diffAnalysisResults.getBleachWhileMonitoringTau() == null ? null : diffAnalysisResults.getBleachWhileMonitoringTau());
        // int startIndexForRecovery = FRAPDataAnalysis.getRecoveryIndex(initFRAPData);
        // 
        // Experiment - Cell ROI Average
        // 
        double[] temp_background = initFRAPData.getAvgBackGroundIntensity();
        double[] preBleachAvgXYZ = FrapDataUtils.calculatePreBleachAverageXYZ(initFRAPData, startIndexForRecovery);
        double[] cellRegionData = FRAPDataAnalysis.getAverageROIIntensity(initFRAPData, initFRAPData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()), preBleachAvgXYZ, temp_background);
        ReferenceData expCellAvgData = new SimpleReferenceData(new String[] { "t", "CellROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] { frapDataTimeStamps, cellRegionData });
        DataSource expCellAvgDataSource = new DataSource.DataSourceReferenceData("expCellAvg", expCellAvgData);
        // 
        // Analytic - Cell ROI Average with Bleach while monitor
        // 
        ODESolverResultSet bleachWhileMonitorOdeSolverResultSet = new ODESolverResultSet();
        bleachWhileMonitorOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
        try {
            bleachWhileMonitorOdeSolverResultSet.addFunctionColumn(new FunctionColumnDescription(diffAnalysisResults.getFitBleachWhileMonitorExpression(), "CellROI_BleachWhileMonitor", null, "bleachWhileMonitorFit", true));
        } catch (ExpressionException e) {
            e.printStackTrace();
        }
        for (int i = startIndexForRecovery; i < frapDataTimeStamps.length; i++) {
            bleachWhileMonitorOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
        }
        // 
        // extend if necessary to plot theoretical curve to 4*tau
        // 
        {
            double T = frapDataTimeStamps[frapDataTimeStamps.length - 1];
            double deltaT = frapDataTimeStamps[frapDataTimeStamps.length - 1] - frapDataTimeStamps[frapDataTimeStamps.length - 2];
            while (T + deltaT < 6 * diffAnalysisResults.getRecoveryTau()) {
                bleachWhileMonitorOdeSolverResultSet.addRow(new double[] { T });
                T += deltaT;
            }
        }
        DataSource bleachWhileMonitorDataSource = new DataSource.DataSourceRowColumnResultSet("bleachwm", bleachWhileMonitorOdeSolverResultSet);
        // Recovery curve
        double[] bleachRegionData = FRAPDataAnalysis.getAverageROIIntensity(initFRAPData, initFRAPData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()), preBleachAvgXYZ, temp_background);
        ;
        ReferenceData expRefData = new SimpleReferenceData(new String[] { "t", "BleachROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] { frapDataTimeStamps, bleachRegionData });
        DataSource expDataSource = new DataSource.DataSourceReferenceData("experiment", expRefData);
        ODESolverResultSet fitOdeSolverResultSet = new ODESolverResultSet();
        fitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
        try {
            fitOdeSolverResultSet.addFunctionColumn(new FunctionColumnDescription(diffAnalysisResults.getDiffFitExpression(), // "('"+FrapDataAnalysisResults.BLEACH_TYPE_NAMES[bleachEstimationComboBox.getSelectedIndex()]+"')",
            "BleachROI_Recovery", null, "recoveryFit", true));
        } catch (ExpressionException e) {
            e.printStackTrace();
        }
        for (int i = startIndexForRecovery; i < frapDataTimeStamps.length; i++) {
            fitOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
        }
        // 
        // extend if necessary to plot theoretical curve to 4*tau
        // 
        double T = frapDataTimeStamps[frapDataTimeStamps.length - 1];
        double deltaT = frapDataTimeStamps[frapDataTimeStamps.length - 1] - frapDataTimeStamps[frapDataTimeStamps.length - 2];
        while (T + deltaT < 6 * diffAnalysisResults.getRecoveryTau()) {
            fitOdeSolverResultSet.addRow(new double[] { T });
            T += deltaT;
        }
        DataSource fitDataSource = new DataSource.DataSourceRowColumnResultSet("fit", fitOdeSolverResultSet);
        multisourcePlotPane.setDataSources(new DataSource[] { expDataSource, fitDataSource, expCellAvgDataSource, bleachWhileMonitorDataSource });
        multisourcePlotPane.selectAll();
    }
    table.repaint();
}
Also used : SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ExpressionException(cbit.vcell.parser.ExpressionException) DataSource(cbit.vcell.modelopt.DataSource)

Example 17 with ODESolverResultSet

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

the class EstParams_ReactionOffRatePanel method displayResults.

private void displayResults(FRAPData frapData, int startIndexRecovery) throws ExpressionException, DivideByZeroException {
    Parameter[] currentParams = offRateParamPanel.getCurrentParameters();
    if (frapData == null || currentParams == null) {
        multisourcePlotPane.setDataSources(null);
    } else {
        double[] frapDataTimeStamps = frapData.getImageDataset().getImageTimeStamps();
        // Experiment - Cell ROI Average
        double[] temp_background = frapData.getAvgBackGroundIntensity();
        double[] preBleachAvgXYZ = FrapDataUtils.calculatePreBleachAverageXYZ(frapData, startIndexRecovery);
        /*double[] cellRegionData = FRAPDataAnalysis.getAverageROIIntensity(frapData, frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()),preBleachAvgXYZ,temp_background);
			ReferenceData expCellAvgData = new SimpleReferenceData(new String[] { ReservedSymbol.TIME.getName(), "CellROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] {frapDataTimeStamps, cellRegionData });
			DataSource expCellAvgDataSource = new DataSource.DataSourceReferenceData("exp", expCellAvgData);
			//Analytic - Cell ROI Average with Bleach while monitor
			ODESolverResultSet bleachWhileMonitorOdeSolverResultSet = new ODESolverResultSet();
			bleachWhileMonitorOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(ReservedSymbol.TIME.getName()));
			Expression cellAvgExp = new Expression(FRAPOptFunctions.FUNC_CELL_INTENSITY);
			// substitute parameter values 
			cellAvgExp.substituteInPlace(new Expression(FRAPOptFunctions.SYMBOL_I_inicell), new Expression(cellRegionData[startIndexRecovery]));
			cellAvgExp.substituteInPlace(new Expression(FRAPOptFunctions.SYMBOL_BWM_RATE), new Expression(currentParams[FRAPModel.INDEX_BLEACH_MONITOR_RATE].getInitialGuess()));
			// time shift
			cellAvgExp.substituteInPlace(new Expression(ReservedSymbol.TIME.getName()), new Expression(ReservedSymbol.TIME.getName()+"-"+frapDataTimeStamps[startIndexRecovery]));
			try {
				bleachWhileMonitorOdeSolverResultSet.addFunctionColumn(
					new FunctionColumnDescription(
						cellAvgExp,
						"CellROIAvg",
						null,"bleachWhileMonitorFit",true));
			} catch (ExpressionException e) {
				e.printStackTrace();
			}
			for (int i = startIndexRecovery; i < frapDataTimeStamps.length; i++) 
			{
				bleachWhileMonitorOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
			}
			DataSource bleachWhileMonitorDataSource = new DataSource.DataSourceOdeSolverResultSet("fit", bleachWhileMonitorOdeSolverResultSet);*/
        // experimental bleach region average intensity curve
        double[] bleachRegionData = FRAPDataAnalysis.getAverageROIIntensity(frapData, frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()), preBleachAvgXYZ, temp_background);
        ;
        ReferenceData expRefData = new SimpleReferenceData(new String[] { ReservedVariable.TIME.getName(), "BleachROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] { frapDataTimeStamps, bleachRegionData });
        DataSource expBleachDataSource = new DataSource.DataSourceReferenceData("exp", expRefData);
        // Analytic - bleach region average intensity with bleach while monitoring rate
        ODESolverResultSet koffFitOdeSolverResultSet = new ODESolverResultSet();
        koffFitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(ReservedVariable.TIME.getName()));
        Expression bleachedAvgExp = frapWorkspace.getWorkingFrapStudy().getFrapOptFunc().getRecoveryExpressionWithCurrentParameters(currentParams);
        try {
            koffFitOdeSolverResultSet.addFunctionColumn(new FunctionColumnDescription(bleachedAvgExp, "BleachROIAvg", null, "recoveryFit", true));
        } catch (ExpressionException e) {
            e.printStackTrace();
        }
        double[] truncatedTimes = new double[frapDataTimeStamps.length - startIndexRecovery];
        for (int i = startIndexRecovery; i < frapDataTimeStamps.length; i++) {
            koffFitOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
            truncatedTimes[i - startIndexRecovery] = frapDataTimeStamps[i];
        }
        setCurrentEstimationResults(frapWorkspace.getWorkingFrapStudy().getFrapOptFunc().createData(bleachedAvgExp.flatten(), truncatedTimes));
        DataSource koffFitDataSource = new DataSource.DataSourceRowColumnResultSet("fit", koffFitOdeSolverResultSet);
        multisourcePlotPane.setDataSources(new DataSource[] { expBleachDataSource, koffFitDataSource /*, expCellAvgDataSource , bleachWhileMonitorDataSource*/
        });
        multisourcePlotPane.selectAll();
    }
}
Also used : SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ExpressionException(cbit.vcell.parser.ExpressionException) DataSource(cbit.vcell.modelopt.DataSource) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) Expression(cbit.vcell.parser.Expression) Parameter(cbit.vcell.opt.Parameter) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription)

Example 18 with ODESolverResultSet

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

the class EstParams_TwoDiffComponentPanel 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 = diffTwoPanel.getCurrentFitData();
        // store results
        setCurrentEstimationResults(currentOptFitData);
        if (allDataHash != null && currentOptFitData != null) {
            // populate optimization data---convert it to odeSoverResultSet and further put into datasource
            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 + /*j*/
                    1, values[k]);
                }
                // }
                columncounter++;
            }
            // 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
                final DataSource expDataSource = /*new DataSource(referenceData,"exp")*/
                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());
    }
}
Also used : Color(java.awt.Color) DataSource(cbit.vcell.modelopt.DataSource) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription)

Example 19 with ODESolverResultSet

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

the class TestingFrameworkWindowManager method generateTestCriteriaReport.

/**
 * Insert the method's description here.
 * Creation date: (8/18/2003 5:36:47 PM)
 */
private String generateTestCriteriaReport(TestCaseNew testCase, TestCriteriaNew testCriteria, Simulation testSim, TFGenerateReport.VCDocumentAndSimInfo userSelectedRefSimInfo) /*,VCDocument refDoc,VCDocument testDocument*/
{
    if (testSim.getScanCount() != 1) {
        throw new RuntimeException("paramater scan is not supported in Math Testing Framework");
    }
    SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(testSim, 0);
    String simReportStatus = null;
    String simReportStatusMessage = null;
    StringBuffer reportTCBuffer = new StringBuffer();
    VariableComparisonSummary[] failVarSummaries = null;
    VariableComparisonSummary[] allVarSummaries = null;
    double absErr = 0;
    double relErr = 0;
    if (testCriteria != null) {
        absErr = testCriteria.getMaxAbsError().doubleValue();
        relErr = testCriteria.getMaxRelError().doubleValue();
    }
    try {
        VCDocument testDoc = null;
        if (testCase instanceof TestCaseNewMathModel) {
            MathModelInfo mmInfo = ((TestCaseNewMathModel) testCase).getMathModelInfo();
            MathModel mathModel = getRequestManager().getDocumentManager().getMathModel(mmInfo);
            testDoc = mathModel;
        } else if (testCase instanceof TestCaseNewBioModel) {
            TestCaseNewBioModel bioTestCase = (TestCaseNewBioModel) testCase;
            // bioTestCase.
            BioModelInfo bmInfo = bioTestCase.getBioModelInfo();
            BioModel bioModel = getRequestManager().getDocumentManager().getBioModel(bmInfo);
            testDoc = bioModel;
        }
        TFGenerateReport.VCDocumentAndSimInfo refVCDocumentAndSimInfo = null;
        if (userSelectedRefSimInfo == null) {
            SimulationInfo refSimInfo = testCriteria.getRegressionSimInfo();
            if (refSimInfo != null) {
                VCDocument refDoc = null;
                if (testCriteria instanceof TestCriteriaNewMathModel) {
                    MathModelInfo mmInfo = ((TestCriteriaNewMathModel) testCriteria).getRegressionMathModelInfo();
                    MathModel mathModel = getRequestManager().getDocumentManager().getMathModel(mmInfo);
                    refDoc = mathModel;
                } else if (testCriteria instanceof TestCriteriaNewBioModel) {
                    BioModelInfo bmInfo = ((TestCriteriaNewBioModel) testCriteria).getRegressionBioModelInfo();
                    BioModel bioModel = getRequestManager().getDocumentManager().getBioModel(bmInfo);
                    refDoc = bioModel;
                }
                refVCDocumentAndSimInfo = new TFGenerateReport.VCDocumentAndSimInfo(refSimInfo, refDoc);
            }
            reportTCBuffer.append("\t\t" + testSim.getName() + (refVCDocumentAndSimInfo != null ? " (Using TestCrit RegrRefSim)" : "") + " : " + "\n");
        } else {
            refVCDocumentAndSimInfo = userSelectedRefSimInfo;
            reportTCBuffer.append("\t\t" + testSim.getName() + " (Using UserDefined RegrRefSim '" + userSelectedRefSimInfo.getSimInfo().getAuthoritativeVCSimulationIdentifier() + "') : " + "\n");
        }
        if (testCase.getType().equals(TestCaseNew.REGRESSION) && refVCDocumentAndSimInfo == null) {
            reportTCBuffer.append("\t\t\tNo reference SimInfo, SimInfoKey=" + testCriteria.getSimInfo().getVersion().getName() + ". Cannot perform Regression Test!\n");
            simReportStatus = TestCriteriaNew.TCRIT_STATUS_NOREFREGR;
        } else {
            VCDataIdentifier vcdID = new VCSimulationDataIdentifier(testSim.getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), 0);
            DataManager simDataManager = getRequestManager().getDataManager(null, vcdID, testSim.isSpatial());
            double[] timeArray = null;
            // can be histogram, so there won't be time array
            try {
                timeArray = simDataManager.getDataSetTimes();
            } catch (Exception ex) {
                ex.printStackTrace(System.out);
            }
            NonspatialStochSimOptions stochOpt = testSim.getSolverTaskDescription().getStochOpt();
            if ((stochOpt == null || stochOpt.getNumOfTrials() == 1) && (timeArray == null || timeArray.length == 0)) {
                reportTCBuffer.append("\t\t\tNO DATA : Simulation not run yet.\n");
                simReportStatus = TestCriteriaNew.TCRIT_STATUS_NODATA;
            } else {
                // SPATIAL simulation
                if (testSim.getMathDescription().isSpatial()) {
                    PDEDataManager pdeDataManager = (PDEDataManager) simDataManager;
                    // Get EXACT solution if test case type is EXACT, Compare with numerical
                    if (testCase.getType().equals(TestCaseNew.EXACT) || testCase.getType().equals(TestCaseNew.EXACT_STEADY)) {
                        SimulationComparisonSummary simCompSummary = MathTestingUtilities.comparePDEResultsWithExact(simSymbolTable, pdeDataManager, testCase.getType(), testCriteria.getMaxAbsError(), testCriteria.getMaxRelError());
                        // Failed var summaries
                        failVarSummaries = simCompSummary.getFailingVariableComparisonSummaries(absErr, relErr);
                        allVarSummaries = simCompSummary.getVariableComparisonSummaries();
                        if (failVarSummaries.length > 0) {
                            simReportStatus = TestCriteriaNew.TCRIT_STATUS_FAILEDVARS;
                            // Failed simulation
                            reportTCBuffer.append("\t\tTolerance test FAILED \n");
                            reportTCBuffer.append("\t\tFailed Variables : \n");
                            for (int m = 0; m < failVarSummaries.length; m++) {
                                reportTCBuffer.append("\t\t\t" + failVarSummaries[m].toShortString() + "\n");
                            }
                        } else {
                            simReportStatus = TestCriteriaNew.TCRIT_STATUS_PASSED;
                            reportTCBuffer.append("\t\tTolerance test PASSED \n");
                        }
                        reportTCBuffer.append("\t\tPassed Variables : \n");
                        // Check if varSummary exists in failed summaries list. If not, simulation passed.
                        for (int m = 0; m < allVarSummaries.length; m++) {
                            if (!BeanUtils.arrayContains(failVarSummaries, allVarSummaries[m])) {
                                reportTCBuffer.append("\t\t\t" + allVarSummaries[m].toShortString() + "\n");
                            }
                        }
                    // Get CONSTRUCTED solution if test case type is CONSTRUCTED, Compare with numerical
                    } else if (testCase.getType().equals(TestCaseNew.CONSTRUCTED)) {
                        SimulationComparisonSummary simCompSummary = MathTestingUtilities.comparePDEResultsWithExact(simSymbolTable, pdeDataManager, testCase.getType(), testCriteria.getMaxAbsError(), testCriteria.getMaxRelError());
                        // Failed var summaries
                        failVarSummaries = simCompSummary.getFailingVariableComparisonSummaries(absErr, relErr);
                        allVarSummaries = simCompSummary.getVariableComparisonSummaries();
                        if (failVarSummaries.length > 0) {
                            simReportStatus = TestCriteriaNew.TCRIT_STATUS_FAILEDVARS;
                            // Failed simulation
                            reportTCBuffer.append("\t\tTolerance test FAILED \n");
                            reportTCBuffer.append("\t\tFailed Variables : \n");
                            for (int m = 0; m < failVarSummaries.length; m++) {
                                reportTCBuffer.append("\t\t\t" + failVarSummaries[m].toShortString() + "\n");
                            }
                        } else {
                            simReportStatus = TestCriteriaNew.TCRIT_STATUS_PASSED;
                            reportTCBuffer.append("\t\tTolerance test PASSED \n");
                        }
                        reportTCBuffer.append("\t\tPassed Variables : \n");
                        // Check if varSummary exists in failed summaries list. If not, simulation passed.
                        for (int m = 0; m < allVarSummaries.length; m++) {
                            if (!BeanUtils.arrayContains(failVarSummaries, allVarSummaries[m])) {
                                reportTCBuffer.append("\t\t\t" + allVarSummaries[m].toShortString() + "\n");
                            }
                        }
                    } else if (testCase.getType().equals(TestCaseNew.REGRESSION)) {
                        Simulation refSim = ((ClientDocumentManager) getRequestManager().getDocumentManager()).getSimulation(refVCDocumentAndSimInfo.getSimInfo());
                        VCDataIdentifier refVcdID = new VCSimulationDataIdentifier(refVCDocumentAndSimInfo.getSimInfo().getAuthoritativeVCSimulationIdentifier(), 0);
                        PDEDataManager refDataManager = (PDEDataManager) getRequestManager().getDataManager(null, refVcdID, refSim.isSpatial());
                        if (refSim.getScanCount() != 1) {
                            throw new RuntimeException("paramater scan is not supported in Math Testing Framework");
                        }
                        SimulationSymbolTable refSimSymbolTable = new SimulationSymbolTable(refSim, 0);
                        String[] varsToCompare = getVariableNamesToCompare(simSymbolTable, refSimSymbolTable);
                        SimulationComparisonSummary simCompSummary = MathTestingUtilities.comparePDEResults(simSymbolTable, pdeDataManager, refSimSymbolTable, refDataManager, varsToCompare, testCriteria.getMaxAbsError(), testCriteria.getMaxRelError(), refVCDocumentAndSimInfo.getVCDocument(), getDataInfoProvider(refVCDocumentAndSimInfo.getVCDocument(), refDataManager.getPDEDataContext(), refSim.getName()), testDoc, getDataInfoProvider(testDoc, pdeDataManager.getPDEDataContext(), testSim.getName()));
                        // Failed var summaries
                        failVarSummaries = simCompSummary.getFailingVariableComparisonSummaries(absErr, relErr);
                        allVarSummaries = simCompSummary.getVariableComparisonSummaries();
                        if (failVarSummaries.length > 0) {
                            simReportStatus = TestCriteriaNew.TCRIT_STATUS_FAILEDVARS;
                            // Failed simulation
                            reportTCBuffer.append("\t\tTolerance test FAILED \n");
                            reportTCBuffer.append("\t\tFailed Variables : \n");
                            for (int m = 0; m < failVarSummaries.length; m++) {
                                reportTCBuffer.append("\t\t\t" + failVarSummaries[m].toShortString() + "\n");
                            }
                        } else {
                            simReportStatus = TestCriteriaNew.TCRIT_STATUS_PASSED;
                            reportTCBuffer.append("\t\tTolerance test PASSED \n");
                        }
                        reportTCBuffer.append("\t\tPassed Variables : \n");
                        // Check if varSummary exists in failed summaries list. If not, simulation passed.
                        for (int m = 0; m < allVarSummaries.length; m++) {
                            if (!BeanUtils.arrayContains(failVarSummaries, allVarSummaries[m])) {
                                reportTCBuffer.append("\t\t\t" + allVarSummaries[m].toShortString() + "\n");
                            }
                        }
                    }
                } else {
                    // NON-SPATIAL CASE
                    ODEDataManager odeDataManager = (ODEDataManager) simDataManager;
                    ODESolverResultSet numericalResultSet = odeDataManager.getODESolverResultSet();
                    // Get EXACT result set if test case type is EXACT, Compare with numerical
                    if (testCase.getType().equals(TestCaseNew.EXACT) || testCase.getType().equals(TestCaseNew.EXACT_STEADY)) {
                        ODESolverResultSet exactResultSet = MathTestingUtilities.getExactResultSet(testSim.getMathDescription(), timeArray, testSim.getSolverTaskDescription().getSensitivityParameter());
                        String[] varsToCompare = getVariableNamesToCompare(simSymbolTable, simSymbolTable);
                        SimulationComparisonSummary simCompSummary_exact = MathTestingUtilities.compareResultSets(numericalResultSet, exactResultSet, varsToCompare, testCase.getType(), testCriteria.getMaxAbsError(), testCriteria.getMaxRelError());
                        // Get all the variable comparison summaries and the failed ones to print out report for EXACT solution comparison.
                        failVarSummaries = simCompSummary_exact.getFailingVariableComparisonSummaries(absErr, relErr);
                        allVarSummaries = simCompSummary_exact.getVariableComparisonSummaries();
                        if (failVarSummaries.length > 0) {
                            simReportStatus = TestCriteriaNew.TCRIT_STATUS_FAILEDVARS;
                            // Failed simulation
                            reportTCBuffer.append("\t\tTolerance test FAILED \n");
                            reportTCBuffer.append("\t\tFailed Variables : \n");
                            for (int m = 0; m < failVarSummaries.length; m++) {
                                reportTCBuffer.append("\t\t\t" + failVarSummaries[m].toShortString() + "\n");
                            }
                        } else {
                            simReportStatus = TestCriteriaNew.TCRIT_STATUS_PASSED;
                            reportTCBuffer.append("\t\tTolerance test PASSED \n");
                        }
                        reportTCBuffer.append("\t\tPassed Variables : \n");
                        // Check if varSummary exists in failed summaries list. If not, simulation passed.
                        for (int m = 0; m < allVarSummaries.length; m++) {
                            if (!BeanUtils.arrayContains(failVarSummaries, allVarSummaries[m])) {
                                reportTCBuffer.append("\t\t\t" + allVarSummaries[m].toShortString() + "\n");
                            }
                        }
                    // Get CONSTRUCTED result set if test case type is CONSTRUCTED , compare with numerical
                    } else if (testCase.getType().equals(TestCaseNew.CONSTRUCTED)) {
                        ODESolverResultSet constructedResultSet = MathTestingUtilities.getConstructedResultSet(testSim.getMathDescription(), timeArray);
                        String[] varsToCompare = getVariableNamesToCompare(simSymbolTable, simSymbolTable);
                        SimulationComparisonSummary simCompSummary_constr = MathTestingUtilities.compareResultSets(numericalResultSet, constructedResultSet, varsToCompare, testCase.getType(), testCriteria.getMaxAbsError(), testCriteria.getMaxRelError());
                        // Get all the variable comparison summaries and the failed ones to print out report for CONSTRUCTED solution comparison.
                        failVarSummaries = simCompSummary_constr.getFailingVariableComparisonSummaries(absErr, relErr);
                        allVarSummaries = simCompSummary_constr.getVariableComparisonSummaries();
                        if (failVarSummaries.length > 0) {
                            simReportStatus = TestCriteriaNew.TCRIT_STATUS_FAILEDVARS;
                            // Failed simulation
                            reportTCBuffer.append("\t\tTolerance test FAILED \n");
                            reportTCBuffer.append("\t\tFailed Variables : \n");
                            for (int m = 0; m < failVarSummaries.length; m++) {
                                reportTCBuffer.append("\t\t\t" + failVarSummaries[m].toShortString() + "\n");
                            }
                        } else {
                            simReportStatus = TestCriteriaNew.TCRIT_STATUS_PASSED;
                            reportTCBuffer.append("\t\tTolerance test PASSED \n");
                        }
                        reportTCBuffer.append("\t\tPassed Variables : \n");
                        // Check if varSummary exists in failed summaries list. If not, simulation passed.
                        for (int m = 0; m < allVarSummaries.length; m++) {
                            if (!BeanUtils.arrayContains(failVarSummaries, allVarSummaries[m])) {
                                reportTCBuffer.append("\t\t\t" + allVarSummaries[m].toShortString() + "\n");
                            }
                        }
                    } else if (testCase.getType().equals(TestCaseNew.REGRESSION)) {
                        Simulation refSim = ((ClientDocumentManager) getRequestManager().getDocumentManager()).getSimulation(testCriteria.getRegressionSimInfo());
                        if (refSim.getScanCount() != 1) {
                            throw new RuntimeException("paramater scan is not supported in Math Testing Framework");
                        }
                        SimulationSymbolTable refSimSymbolTable = new SimulationSymbolTable(refSim, 0);
                        String[] varsToTest = getVariableNamesToCompare(simSymbolTable, refSimSymbolTable);
                        VCDataIdentifier refVcdID = new VCSimulationDataIdentifier(refVCDocumentAndSimInfo.getSimInfo().getAuthoritativeVCSimulationIdentifier(), 0);
                        ODEDataManager refDataManager = (ODEDataManager) getRequestManager().getDataManager(null, refVcdID, refSim.isSpatial());
                        ODESolverResultSet referenceResultSet = refDataManager.getODESolverResultSet();
                        SimulationComparisonSummary simCompSummary_regr = null;
                        int interpolationOrder = 1;
                        SolverTaskDescription solverTaskDescription = refSim.getSolverTaskDescription();
                        if (solverTaskDescription.getOutputTimeSpec().isDefault() && ((DefaultOutputTimeSpec) solverTaskDescription.getOutputTimeSpec()).getKeepEvery() == 1) {
                            SolverDescription solverDescription = solverTaskDescription.getSolverDescription();
                            if ((!solverDescription.supportsAll(SolverDescription.DiscontinutiesFeatures)) || !refSim.getMathDescription().hasDiscontinuities()) {
                                interpolationOrder = solverDescription.getTimeOrder();
                            }
                        }
                        simCompSummary_regr = MathTestingUtilities.compareUnEqualResultSets(numericalResultSet, referenceResultSet, varsToTest, testCriteria.getMaxAbsError(), testCriteria.getMaxRelError(), interpolationOrder);
                        // Get all the variable comparison summaries and the failed ones to print out report for CONSTRUCTED solution comparison.
                        failVarSummaries = simCompSummary_regr.getFailingVariableComparisonSummaries(absErr, relErr);
                        allVarSummaries = simCompSummary_regr.getVariableComparisonSummaries();
                        if (failVarSummaries.length > 0) {
                            simReportStatus = TestCriteriaNew.TCRIT_STATUS_FAILEDVARS;
                            // Failed simulation
                            reportTCBuffer.append("\t\tTolerance test FAILED \n");
                            reportTCBuffer.append("\t\tFailed Variables : \n");
                            for (int m = 0; m < failVarSummaries.length; m++) {
                                reportTCBuffer.append("\t\t\t" + failVarSummaries[m].toShortString() + "\n");
                            }
                        } else {
                            simReportStatus = TestCriteriaNew.TCRIT_STATUS_PASSED;
                            reportTCBuffer.append("\t\tTolerance test PASSED \n");
                        }
                        reportTCBuffer.append("\t\tPassed Variables : \n");
                        // Check if varSummary exists in failed summaries list. If not, simulation passed.
                        for (int m = 0; m < allVarSummaries.length; m++) {
                            if (!BeanUtils.arrayContains(failVarSummaries, allVarSummaries[m])) {
                                reportTCBuffer.append("\t\t\t" + allVarSummaries[m].toShortString() + "\n");
                            }
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        simReportStatus = TestCriteriaNew.TCRIT_STATUS_RPERROR;
        simReportStatusMessage = e.getClass().getName() + " " + e.getMessage();
        reportTCBuffer.append("\t\t" + simReportStatusMessage + "\n");
        e.printStackTrace(System.out);
    }
    if (userSelectedRefSimInfo == null) {
        try {
            // Remove any test results already present for testCriteria
            RemoveTestResultsOP removeResultsOP = new RemoveTestResultsOP(new BigDecimal[] { testCriteria.getTCritKey() });
            // testResultsOPsVector.add(removeResultsOP);
            getRequestManager().getDocumentManager().doTestSuiteOP(removeResultsOP);
            // Create new AddTestREsultsOP object for the current simulation./testCriteria.
            if (allVarSummaries != null) {
                AddTestResultsOP testResultsOP = new AddTestResultsOP(testCriteria.getTCritKey(), allVarSummaries);
                // testResultsOPsVector.add(testResultsOP);
                // Write the testResults for simulation/TestCriteria into the database ...
                getRequestManager().getDocumentManager().doTestSuiteOP(testResultsOP);
            }
            // Update report status
            updateTCritStatus(testCriteria, simReportStatus, simReportStatusMessage);
        } catch (Throwable e) {
            reportTCBuffer.append("\t\tUpdate DB Results failed. " + e.getClass().getName() + " " + e.getMessage() + "\n");
            try {
                getRequestManager().getDocumentManager().doTestSuiteOP(new EditTestCriteriaOPReportStatus(testCriteria.getTCritKey(), TestCriteriaNew.TCRIT_STATUS_RPERROR, e.getClass().getName() + " " + e.getMessage()));
            } catch (Throwable e2) {
            // Nothing more can be done
            }
        }
    }
    return reportTCBuffer.toString();
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) AddTestCasesOPMathModel(cbit.vcell.numericstest.AddTestCasesOPMathModel) TestCaseNewMathModel(cbit.vcell.numericstest.TestCaseNewMathModel) TestCriteriaNewMathModel(cbit.vcell.numericstest.TestCriteriaNewMathModel) EditTestCriteriaOPMathModel(cbit.vcell.numericstest.EditTestCriteriaOPMathModel) AddTestCriteriaOPMathModel(cbit.vcell.numericstest.AddTestCriteriaOPMathModel) SolverDescription(cbit.vcell.solver.SolverDescription) TestCriteriaNewBioModel(cbit.vcell.numericstest.TestCriteriaNewBioModel) NonspatialStochSimOptions(cbit.vcell.solver.NonspatialStochSimOptions) ClientDocumentManager(cbit.vcell.clientdb.ClientDocumentManager) TFGenerateReport(cbit.vcell.client.task.TFGenerateReport) TestCaseNewBioModel(cbit.vcell.numericstest.TestCaseNewBioModel) RemoveTestResultsOP(cbit.vcell.numericstest.RemoveTestResultsOP) TestCriteriaNewMathModel(cbit.vcell.numericstest.TestCriteriaNewMathModel) AddTestResultsOP(cbit.vcell.numericstest.AddTestResultsOP) SimulationComparisonSummary(cbit.vcell.solver.test.SimulationComparisonSummary) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) VariableComparisonSummary(cbit.vcell.solver.test.VariableComparisonSummary) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription) EditTestCriteriaOPReportStatus(cbit.vcell.numericstest.EditTestCriteriaOPReportStatus) VCDocument(org.vcell.util.document.VCDocument) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) BioModelInfo(org.vcell.util.document.BioModelInfo) PDEDataManager(cbit.vcell.simdata.PDEDataManager) ODEDataManager(cbit.vcell.simdata.ODEDataManager) DataManager(cbit.vcell.simdata.DataManager) MathModelInfo(org.vcell.util.document.MathModelInfo) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) DataAccessException(org.vcell.util.DataAccessException) UserCancelException(org.vcell.util.UserCancelException) Simulation(cbit.vcell.solver.Simulation) PDEDataManager(cbit.vcell.simdata.PDEDataManager) TestCaseNewBioModel(cbit.vcell.numericstest.TestCaseNewBioModel) TestCriteriaNewBioModel(cbit.vcell.numericstest.TestCriteriaNewBioModel) AddTestCasesOPBioModel(cbit.vcell.numericstest.AddTestCasesOPBioModel) BioModel(cbit.vcell.biomodel.BioModel) EditTestCriteriaOPBioModel(cbit.vcell.numericstest.EditTestCriteriaOPBioModel) AddTestCriteriaOPBioModel(cbit.vcell.numericstest.AddTestCriteriaOPBioModel) TestCaseNewMathModel(cbit.vcell.numericstest.TestCaseNewMathModel) ODEDataManager(cbit.vcell.simdata.ODEDataManager) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec) SimulationInfo(cbit.vcell.solver.SimulationInfo)

Example 20 with ODESolverResultSet

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

the class MergedDatasetViewer method refreshData.

/**
 * Insert the method's description here.
 * Creation date: (6/11/2004 2:43:49 PM)
 * @exception org.vcell.util.DataAccessException The exception description.
 */
public void refreshData() throws org.vcell.util.DataAccessException {
    if (isODEData) {
        ODESolverResultSet osr = null;
        osr = odeDataViewer.getOdeSolverResultSet();
        if (osr != null) {
            odeDataViewer.setOdeSolverResultSet(osr);
        }
    } else {
        pdeDataViewer.getPdeDataContext().refreshTimes();
    }
}
Also used : ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet)

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