Search in sources :

Example 1 with ConfidenceInterval

use of org.vcell.optimization.ConfidenceInterval 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 2 with ConfidenceInterval

use of org.vcell.optimization.ConfidenceInterval in project vcell by virtualcell.

the class FRAPOptimizationUtils method getSummaryFromProfileData.

// getting a profileSummary for each parameter that has acquired a profile likelihood distribution
public static ProfileSummaryData getSummaryFromProfileData(ProfileData profileData) {
    ArrayList<ProfileDataElement> profileElements = profileData.getProfileDataElements();
    int dataSize = profileElements.size();
    double[] paramValArray = new double[dataSize];
    double[] errorArray = new double[dataSize];
    if (dataSize > 0) {
        // profile likelihood curve
        String paramName = profileElements.get(0).getParamName();
        // find the parameter to locate the upper and lower bounds
        Parameter parameter = null;
        Parameter[] bestParameters = profileElements.get(0).getBestParameters();
        for (int i = 0; i < bestParameters.length; i++) {
            if (bestParameters[i] != null && bestParameters[i].getName().equals(paramName)) {
                parameter = bestParameters[i];
            }
        }
        // double logLowerBound = (lowerBound == 0)? 0: Math.log10(lowerBound);
        for (int i = 0; i < dataSize; i++) {
            paramValArray[i] = profileElements.get(i).getParameterValue();
            errorArray[i] = profileElements.get(i).getLikelihood();
        }
        PlotData dataPlot = new PlotData(paramValArray, errorArray);
        // get confidence interval line
        // make array copy in order to not change the data orders afte the sorting
        double[] paramValArrayCopy = new double[paramValArray.length];
        System.arraycopy(paramValArray, 0, paramValArrayCopy, 0, paramValArray.length);
        double[] errorArrayCopy = new double[errorArray.length];
        System.arraycopy(errorArray, 0, errorArrayCopy, 0, errorArray.length);
        DescriptiveStatistics paramValStat = DescriptiveStatistics.CreateBasicStatistics(paramValArrayCopy);
        DescriptiveStatistics errorStat = DescriptiveStatistics.CreateBasicStatistics(errorArrayCopy);
        double[] xArray = new double[2];
        double[][] yArray = new double[ConfidenceInterval.NUM_CONFIDENCE_LEVELS][2];
        // get confidence level plot lines
        xArray[0] = paramValStat.getMin() - (Math.abs(paramValStat.getMin()) * 0.2);
        xArray[1] = paramValStat.getMax() + (Math.abs(paramValStat.getMax()) * 0.2);
        for (int i = 0; i < ConfidenceInterval.NUM_CONFIDENCE_LEVELS; i++) {
            yArray[i][0] = errorStat.getMin() + ConfidenceInterval.DELTA_ALPHA_VALUE[i];
            yArray[i][1] = yArray[i][0];
        }
        PlotData confidence80Plot = new PlotData(xArray, yArray[ConfidenceInterval.IDX_DELTA_ALPHA_80]);
        PlotData confidence90Plot = new PlotData(xArray, yArray[ConfidenceInterval.IDX_DELTA_ALPHA_90]);
        PlotData confidence95Plot = new PlotData(xArray, yArray[ConfidenceInterval.IDX_DELTA_ALPHA_95]);
        PlotData confidence99Plot = new PlotData(xArray, yArray[ConfidenceInterval.IDX_DELTA_ALPHA_99]);
        // generate plot2D data
        Plot2D plots = new Plot2D(null, null, new String[] { "profile Likelihood Data", "80% confidence", "90% confidence", "95% confidence", "99% confidence" }, new PlotData[] { dataPlot, confidence80Plot, confidence90Plot, confidence95Plot, confidence99Plot }, new String[] { "Profile likelihood of " + paramName, "Log base 10 of " + paramName, "Profile Likelihood" }, new boolean[] { true, true, true, true, true });
        // get the best parameter for the minimal error
        int minErrIndex = -1;
        for (int i = 0; i < errorArray.length; i++) {
            if (errorArray[i] == errorStat.getMin()) {
                minErrIndex = i;
                break;
            }
        }
        double bestParamVal = Math.pow(10, paramValArray[minErrIndex]);
        // find confidence interval points
        ConfidenceInterval[] intervals = new ConfidenceInterval[ConfidenceInterval.NUM_CONFIDENCE_LEVELS];
        // half loop through the errors(left side curve)
        int[] smallLeftIdx = new int[ConfidenceInterval.NUM_CONFIDENCE_LEVELS];
        int[] bigLeftIdx = new int[ConfidenceInterval.NUM_CONFIDENCE_LEVELS];
        for (int i = 0; i < ConfidenceInterval.NUM_CONFIDENCE_LEVELS; i++) {
            smallLeftIdx[i] = -1;
            bigLeftIdx[i] = -1;
            for (// loop from bigger error to smaller error
            int j = 1; // loop from bigger error to smaller error
            j < minErrIndex + 1; // loop from bigger error to smaller error
            j++) {
                if ((errorArray[j] < (errorStat.getMin() + ConfidenceInterval.DELTA_ALPHA_VALUE[i])) && (errorArray[j - 1] > (errorStat.getMin() + ConfidenceInterval.DELTA_ALPHA_VALUE[i]))) {
                    smallLeftIdx[i] = j - 1;
                    bigLeftIdx[i] = j;
                    break;
                }
            }
        }
        // another half loop through the errors(right side curve)
        int[] smallRightIdx = new int[ConfidenceInterval.NUM_CONFIDENCE_LEVELS];
        int[] bigRightIdx = new int[ConfidenceInterval.NUM_CONFIDENCE_LEVELS];
        for (int i = 0; i < ConfidenceInterval.NUM_CONFIDENCE_LEVELS; i++) {
            smallRightIdx[i] = -1;
            bigRightIdx[i] = -1;
            for (// loop from bigger error to smaller error
            int j = (minErrIndex + 1); // loop from bigger error to smaller error
            j < errorArray.length; // loop from bigger error to smaller error
            j++) {
                if ((errorStat.getMin() + ConfidenceInterval.DELTA_ALPHA_VALUE[i]) < errorArray[j] && (errorStat.getMin() + ConfidenceInterval.DELTA_ALPHA_VALUE[i]) > errorArray[j - 1]) {
                    smallRightIdx[i] = j - 1;
                    bigRightIdx[i] = j;
                    break;
                }
            }
        }
        // calculate intervals
        for (int i = 0; i < ConfidenceInterval.NUM_CONFIDENCE_LEVELS; i++) {
            double lowerBound = Double.NEGATIVE_INFINITY;
            boolean bLowerBoundOpen = true;
            double upperBound = Double.POSITIVE_INFINITY;
            boolean bUpperBoundOpen = true;
            if (// no lower bound
            smallLeftIdx[i] == -1 && bigLeftIdx[i] == -1) {
                lowerBound = parameter.getLowerBound();
                bLowerBoundOpen = false;
            } else if (// there is a lower bound
            smallLeftIdx[i] != -1 && bigLeftIdx[i] != -1) {
                // x=x1+(x2-x1)*(y-y1)/(y2-y1);
                double x1 = paramValArray[smallLeftIdx[i]];
                double x2 = paramValArray[bigLeftIdx[i]];
                double y = errorStat.getMin() + ConfidenceInterval.DELTA_ALPHA_VALUE[i];
                double y1 = errorArray[smallLeftIdx[i]];
                double y2 = errorArray[bigLeftIdx[i]];
                lowerBound = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
                lowerBound = Math.pow(10, lowerBound);
                bLowerBoundOpen = false;
            }
            if (// no upper bound
            smallRightIdx[i] == -1 && bigRightIdx[i] == -1) {
                upperBound = parameter.getUpperBound();
                bUpperBoundOpen = false;
            } else if (// there is a upper bound
            smallRightIdx[i] != -1 && bigRightIdx[i] != -1) {
                // x=x1+(x2-x1)*(y-y1)/(y2-y1);
                double x1 = paramValArray[smallRightIdx[i]];
                double x2 = paramValArray[bigRightIdx[i]];
                double y = errorStat.getMin() + ConfidenceInterval.DELTA_ALPHA_VALUE[i];
                double y1 = errorArray[smallRightIdx[i]];
                double y2 = errorArray[bigRightIdx[i]];
                upperBound = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
                upperBound = Math.pow(10, upperBound);
                bUpperBoundOpen = false;
            }
            intervals[i] = new ConfidenceInterval(lowerBound, bLowerBoundOpen, upperBound, bUpperBoundOpen);
        }
        return new ProfileSummaryData(plots, bestParamVal, intervals, paramName);
    }
    return null;
}
Also used : PlotData(cbit.plot.PlotData) DescriptiveStatistics(org.vcell.util.DescriptiveStatistics) ProfileSummaryData(org.vcell.optimization.ProfileSummaryData) ProfileDataElement(org.vcell.optimization.ProfileDataElement) Parameter(cbit.vcell.opt.Parameter) Plot2D(cbit.plot.Plot2D) ConfidenceInterval(org.vcell.optimization.ConfidenceInterval)

Example 3 with ConfidenceInterval

use of org.vcell.optimization.ConfidenceInterval in project vcell by virtualcell.

the class DisplayProfileLikelihoodPlotsOp method getSummaryFromProfileData.

// getting a profileSummary for each parameter that has acquired a profile likelihood distribution
ProfileSummaryData getSummaryFromProfileData(ProfileData profileData) {
    ArrayList<ProfileDataElement> profileElements = profileData.getProfileDataElements();
    int dataSize = profileElements.size();
    double[] paramValArray = new double[dataSize];
    double[] errorArray = new double[dataSize];
    if (dataSize > 0) {
        // profile likelihood curve
        String paramName = profileElements.get(0).getParamName();
        // find the parameter to locate the upper and lower bounds
        Parameter parameter = null;
        Parameter[] bestParameters = profileElements.get(0).getBestParameters();
        for (int i = 0; i < bestParameters.length; i++) {
            if (bestParameters[i] != null && bestParameters[i].getName().equals(paramName)) {
                parameter = bestParameters[i];
            }
        }
        // double logLowerBound = (lowerBound == 0)? 0: Math.log10(lowerBound);
        for (int i = 0; i < dataSize; i++) {
            paramValArray[i] = profileElements.get(i).getParameterValue();
            errorArray[i] = profileElements.get(i).getLikelihood();
        }
        PlotData dataPlot = new PlotData(paramValArray, errorArray);
        // get confidence interval line
        // make array copy in order to not change the data orders afte the sorting
        double[] paramValArrayCopy = new double[paramValArray.length];
        System.arraycopy(paramValArray, 0, paramValArrayCopy, 0, paramValArray.length);
        double[] errorArrayCopy = new double[errorArray.length];
        System.arraycopy(errorArray, 0, errorArrayCopy, 0, errorArray.length);
        DescriptiveStatistics paramValStat = DescriptiveStatistics.CreateBasicStatistics(paramValArrayCopy);
        DescriptiveStatistics errorStat = DescriptiveStatistics.CreateBasicStatistics(errorArrayCopy);
        double[] xArray = new double[2];
        double[][] yArray = new double[ConfidenceInterval.NUM_CONFIDENCE_LEVELS][2];
        // get confidence level plot lines
        xArray[0] = paramValStat.getMin() - (Math.abs(paramValStat.getMin()) * 0.2);
        xArray[1] = paramValStat.getMax() + (Math.abs(paramValStat.getMax()) * 0.2);
        for (int i = 0; i < ConfidenceInterval.NUM_CONFIDENCE_LEVELS; i++) {
            yArray[i][0] = errorStat.getMin() + ConfidenceInterval.DELTA_ALPHA_VALUE[i];
            yArray[i][1] = yArray[i][0];
        }
        PlotData confidence80Plot = new PlotData(xArray, yArray[ConfidenceInterval.IDX_DELTA_ALPHA_80]);
        PlotData confidence90Plot = new PlotData(xArray, yArray[ConfidenceInterval.IDX_DELTA_ALPHA_90]);
        PlotData confidence95Plot = new PlotData(xArray, yArray[ConfidenceInterval.IDX_DELTA_ALPHA_95]);
        PlotData confidence99Plot = new PlotData(xArray, yArray[ConfidenceInterval.IDX_DELTA_ALPHA_99]);
        // generate plot2D data
        Plot2D plots = new Plot2D(null, null, new String[] { "profile Likelihood Data", "80% confidence", "90% confidence", "95% confidence", "99% confidence" }, new PlotData[] { dataPlot, confidence80Plot, confidence90Plot, confidence95Plot, confidence99Plot }, new String[] { "Profile likelihood of " + paramName, "Log base 10 of " + paramName, "Profile Likelihood" }, new boolean[] { true, true, true, true, true });
        // get the best parameter for the minimal error
        int minErrIndex = -1;
        for (int i = 0; i < errorArray.length; i++) {
            if (errorArray[i] == errorStat.getMin()) {
                minErrIndex = i;
                break;
            }
        }
        double bestParamVal = Math.pow(10, paramValArray[minErrIndex]);
        // find confidence interval points
        ConfidenceInterval[] intervals = new ConfidenceInterval[ConfidenceInterval.NUM_CONFIDENCE_LEVELS];
        // half loop through the errors(left side curve)
        int[] smallLeftIdx = new int[ConfidenceInterval.NUM_CONFIDENCE_LEVELS];
        int[] bigLeftIdx = new int[ConfidenceInterval.NUM_CONFIDENCE_LEVELS];
        for (int i = 0; i < ConfidenceInterval.NUM_CONFIDENCE_LEVELS; i++) {
            smallLeftIdx[i] = -1;
            bigLeftIdx[i] = -1;
            for (// loop from bigger error to smaller error
            int j = 1; // loop from bigger error to smaller error
            j < minErrIndex + 1; // loop from bigger error to smaller error
            j++) {
                if ((errorArray[j] < (errorStat.getMin() + ConfidenceInterval.DELTA_ALPHA_VALUE[i])) && (errorArray[j - 1] > (errorStat.getMin() + ConfidenceInterval.DELTA_ALPHA_VALUE[i]))) {
                    smallLeftIdx[i] = j - 1;
                    bigLeftIdx[i] = j;
                    break;
                }
            }
        }
        // another half loop through the errors(right side curve)
        int[] smallRightIdx = new int[ConfidenceInterval.NUM_CONFIDENCE_LEVELS];
        int[] bigRightIdx = new int[ConfidenceInterval.NUM_CONFIDENCE_LEVELS];
        for (int i = 0; i < ConfidenceInterval.NUM_CONFIDENCE_LEVELS; i++) {
            smallRightIdx[i] = -1;
            bigRightIdx[i] = -1;
            for (// loop from bigger error to smaller error
            int j = (minErrIndex + 1); // loop from bigger error to smaller error
            j < errorArray.length; // loop from bigger error to smaller error
            j++) {
                if ((errorStat.getMin() + ConfidenceInterval.DELTA_ALPHA_VALUE[i]) < errorArray[j] && (errorStat.getMin() + ConfidenceInterval.DELTA_ALPHA_VALUE[i]) > errorArray[j - 1]) {
                    smallRightIdx[i] = j - 1;
                    bigRightIdx[i] = j;
                    break;
                }
            }
        }
        // calculate intervals
        for (int i = 0; i < ConfidenceInterval.NUM_CONFIDENCE_LEVELS; i++) {
            double lowerBound = Double.NEGATIVE_INFINITY;
            boolean bLowerBoundOpen = true;
            double upperBound = Double.POSITIVE_INFINITY;
            boolean bUpperBoundOpen = true;
            if (// no lower bound
            smallLeftIdx[i] == -1 && bigLeftIdx[i] == -1) {
                lowerBound = parameter.getLowerBound();
                bLowerBoundOpen = false;
            } else if (// there is a lower bound
            smallLeftIdx[i] != -1 && bigLeftIdx[i] != -1) {
                // x=x1+(x2-x1)*(y-y1)/(y2-y1);
                double x1 = paramValArray[smallLeftIdx[i]];
                double x2 = paramValArray[bigLeftIdx[i]];
                double y = errorStat.getMin() + ConfidenceInterval.DELTA_ALPHA_VALUE[i];
                double y1 = errorArray[smallLeftIdx[i]];
                double y2 = errorArray[bigLeftIdx[i]];
                lowerBound = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
                lowerBound = Math.pow(10, lowerBound);
                bLowerBoundOpen = false;
            }
            if (// no upper bound
            smallRightIdx[i] == -1 && bigRightIdx[i] == -1) {
                upperBound = parameter.getUpperBound();
                bUpperBoundOpen = false;
            } else if (// there is a upper bound
            smallRightIdx[i] != -1 && bigRightIdx[i] != -1) {
                // x=x1+(x2-x1)*(y-y1)/(y2-y1);
                double x1 = paramValArray[smallRightIdx[i]];
                double x2 = paramValArray[bigRightIdx[i]];
                double y = errorStat.getMin() + ConfidenceInterval.DELTA_ALPHA_VALUE[i];
                double y1 = errorArray[smallRightIdx[i]];
                double y2 = errorArray[bigRightIdx[i]];
                upperBound = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
                upperBound = Math.pow(10, upperBound);
                bUpperBoundOpen = false;
            }
            intervals[i] = new ConfidenceInterval(lowerBound, bLowerBoundOpen, upperBound, bUpperBoundOpen);
        }
        return new ProfileSummaryData(plots, bestParamVal, intervals, paramName);
    }
    return null;
}
Also used : PlotData(cbit.plot.PlotData) DescriptiveStatistics(org.vcell.util.DescriptiveStatistics) ProfileSummaryData(org.vcell.optimization.ProfileSummaryData) ProfileDataElement(org.vcell.optimization.ProfileDataElement) Parameter(cbit.vcell.opt.Parameter) Plot2D(cbit.plot.Plot2D) ConfidenceInterval(org.vcell.optimization.ConfidenceInterval)

Aggregations

ConfidenceInterval (org.vcell.optimization.ConfidenceInterval)3 Plot2D (cbit.plot.Plot2D)2 PlotData (cbit.plot.PlotData)2 Parameter (cbit.vcell.opt.Parameter)2 ProfileDataElement (org.vcell.optimization.ProfileDataElement)2 ProfileSummaryData (org.vcell.optimization.ProfileSummaryData)2 DescriptiveStatistics (org.vcell.util.DescriptiveStatistics)2 FRAPModel (cbit.vcell.microscopy.FRAPModel)1 FRAPStudy (cbit.vcell.microscopy.FRAPStudy)1 DataSource (cbit.vcell.modelopt.DataSource)1 ReferenceData (cbit.vcell.opt.ReferenceData)1 ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)1 ArrayList (java.util.ArrayList)1