Search in sources :

Example 6 with ProfileDataElement

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

the class MicroscopyXmlReader method getProfileDataElement.

private ProfileDataElement getProfileDataElement(Element profileDataElementElement) {
    ProfileDataElement profileDataElement = null;
    if (profileDataElementElement != null) {
        String paramName = unMangle(profileDataElementElement.getAttributeValue(MicroscopyXMLTags.profileDataElementParameterNameAttrTag));
        double paramVal = new Double(unMangle(profileDataElementElement.getAttributeValue(MicroscopyXMLTags.profileDataElementParameterValueAttrTag)));
        double likelihood = new Double(unMangle(profileDataElementElement.getAttributeValue(MicroscopyXMLTags.profileDataElementLikelihoodAttrTag)));
        @SuppressWarnings("unchecked") List<Element> parameterElementList = profileDataElementElement.getChildren(OptXmlTags.Parameter_Tag);
        Parameter[] parameters = new Parameter[parameterElementList.size()];
        int paramCounter = 0;
        for (Element paramElement : parameterElementList) {
            parameters[paramCounter] = getParameter(paramElement);
            paramCounter++;
        }
        profileDataElement = new ProfileDataElement(paramName, paramVal, likelihood, parameters);
    }
    return profileDataElement;
}
Also used : ProfileDataElement(org.vcell.optimization.ProfileDataElement) ProfileDataElement(org.vcell.optimization.ProfileDataElement) Element(org.jdom.Element) Parameter(cbit.vcell.opt.Parameter)

Example 7 with ProfileDataElement

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

the class FRAPOptData method evaluateParameters.

public ProfileData[] evaluateParameters(Parameter[] currentParams, ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    // long startTime =System.currentTimeMillis();
    int totalParamLen = currentParams.length;
    ProfileData[] resultData = new ProfileData[totalParamLen];
    FRAPStudy frapStudy = getExpFrapStudy();
    for (int j = 0; j < totalParamLen; j++) {
        ProfileData profileData = new ProfileData();
        // add the fixed parameter to profileData, output exp data and opt results
        setNumEstimatedParams(totalParamLen);
        Parameter[] newBestParameters = getBestParamters(currentParams, frapStudy.getSelectedROIsForErrorCalculation(), null, true);
        double iniError = getLeastError();
        // fixed parameter
        Parameter fixedParam = newBestParameters[j];
        if (// log function cannot take 0 as parameter
        fixedParam.getInitialGuess() == 0) {
            fixedParam = new Parameter(fixedParam.getName(), fixedParam.getLowerBound(), fixedParam.getUpperBound(), fixedParam.getScale(), FRAPOptimizationUtils.epsilon);
        }
        if (clientTaskStatusSupport != null) {
            if (totalParamLen == FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF) {
                clientTaskStatusSupport.setMessage("<html>Evaluating confidence intervals of \'" + fixedParam.getName() + "\' <br> of diffusion with one diffusing component model.</html>");
            } else if (totalParamLen == FRAPModel.NUM_MODEL_PARAMETERS_TWO_DIFF) {
                clientTaskStatusSupport.setMessage("<html>Evaluating confidence intervals of \'" + fixedParam.getName() + "\' <br> of diffusion with two diffusing components model.</html>");
            }
            // start evaluation of a parameter.
            clientTaskStatusSupport.setProgress(0);
        }
        ProfileDataElement pde = new ProfileDataElement(fixedParam.getName(), Math.log10(fixedParam.getInitialGuess()), iniError, newBestParameters);
        profileData.addElement(pde);
        Parameter[] unFixedParams = new Parameter[totalParamLen - 1];
        int indexCounter = 0;
        for (int i = 0; i < totalParamLen; i++) {
            if (!newBestParameters[i].getName().equals(fixedParam.getName())) {
                unFixedParams[indexCounter] = newBestParameters[i];
                indexCounter++;
            } else
                continue;
        }
        // increase
        int iterationCount = 1;
        double paramLogVal = Math.log10(fixedParam.getInitialGuess());
        double lastError = iniError;
        boolean isBoundReached = false;
        double incrementStep = DEFAULT_CI_STEPS[j];
        int stepIncreaseCount = 0;
        while (true) {
            if (// if exceeds the maximum iterations, break;
            iterationCount > MAX_ITERATION) {
                break;
            }
            if (isBoundReached) {
                break;
            }
            paramLogVal = paramLogVal + incrementStep;
            double paramVal = Math.pow(10, paramLogVal);
            if (paramVal > (fixedParam.getUpperBound() - FRAPOptimizationUtils.epsilon)) {
                paramVal = fixedParam.getUpperBound();
                paramLogVal = Math.log10(fixedParam.getUpperBound());
                isBoundReached = true;
            }
            Parameter increasedParam = new Parameter(fixedParam.getName(), fixedParam.getLowerBound(), fixedParam.getUpperBound(), fixedParam.getScale(), paramVal);
            // getBestParameters returns the whole set of parameters including the fixed parameters
            setNumEstimatedParams(totalParamLen - 1);
            Parameter[] newParameters = getBestParamters(unFixedParams, frapStudy.getSelectedROIsForErrorCalculation(), increasedParam, true);
            for (// use last step unfixed parameter values to optimize
            int i = 0; // use last step unfixed parameter values to optimize
            i < newParameters.length; // use last step unfixed parameter values to optimize
            i++) {
                for (int k = 0; k < unFixedParams.length; k++) {
                    if (newParameters[i].getName().equals(unFixedParams[k].getName())) {
                        Parameter tempParameter = new Parameter(unFixedParams[k].getName(), unFixedParams[k].getLowerBound(), unFixedParams[k].getUpperBound(), unFixedParams[k].getScale(), newParameters[i].getInitialGuess());
                        unFixedParams[k] = tempParameter;
                    }
                }
            }
            double error = getLeastError();
            pde = new ProfileDataElement(increasedParam.getName(), paramLogVal, error, newParameters);
            profileData.addElement(pde);
            // check if the we run enough to get confidence intervals(99% @6.635, we plus 10 over the min error)
            if (error > (iniError + 10)) {
                break;
            }
            if (Math.abs((error - lastError) / lastError) < MIN_LIKELIHOOD_CHANGE) {
                stepIncreaseCount++;
                incrementStep = DEFAULT_CI_STEPS[j] * Math.pow(2, stepIncreaseCount);
            } else {
                if (stepIncreaseCount > 1) {
                    incrementStep = DEFAULT_CI_STEPS[j] / Math.pow(2, stepIncreaseCount);
                    stepIncreaseCount--;
                }
            }
            if (clientTaskStatusSupport.isInterrupted()) {
                throw UserCancelException.CANCEL_GENERIC;
            }
            lastError = error;
            iterationCount++;
            clientTaskStatusSupport.setProgress((int) ((iterationCount * 1.0 / MAX_ITERATION) * 0.5 * 100));
        }
        // half way through evaluation of a parameter.
        clientTaskStatusSupport.setProgress(50);
        // decrease
        iterationCount = 1;
        paramLogVal = Math.log10(fixedParam.getInitialGuess());
        ;
        ;
        lastError = iniError;
        isBoundReached = false;
        double decrementStep = DEFAULT_CI_STEPS[j];
        stepIncreaseCount = 0;
        while (true) {
            if (// if exceeds the maximum iterations, break;
            iterationCount > MAX_ITERATION) {
                break;
            }
            if (isBoundReached) {
                break;
            }
            paramLogVal = paramLogVal - decrementStep;
            double paramVal = Math.pow(10, paramLogVal);
            if (paramVal < (fixedParam.getLowerBound() + FRAPOptimizationUtils.epsilon)) {
                paramVal = FRAPOptimizationUtils.epsilon;
                paramLogVal = Math.log10(FRAPOptimizationUtils.epsilon);
                isBoundReached = true;
            }
            Parameter decreasedParam = new Parameter(fixedParam.getName(), fixedParam.getLowerBound(), fixedParam.getUpperBound(), fixedParam.getScale(), paramVal);
            // getBestParameters returns the whole set of parameters including the fixed parameters
            setNumEstimatedParams(totalParamLen - 1);
            Parameter[] newParameters = getBestParamters(unFixedParams, frapStudy.getSelectedROIsForErrorCalculation(), decreasedParam, true);
            for (// use last step unfixed parameter values to optimize
            int i = 0; // use last step unfixed parameter values to optimize
            i < newParameters.length; // use last step unfixed parameter values to optimize
            i++) {
                for (int k = 0; k < unFixedParams.length; k++) {
                    if (newParameters[i].getName().equals(unFixedParams[k].getName())) {
                        Parameter tempParameter = new Parameter(unFixedParams[k].getName(), unFixedParams[k].getLowerBound(), unFixedParams[k].getUpperBound(), unFixedParams[k].getScale(), newParameters[i].getInitialGuess());
                        unFixedParams[k] = tempParameter;
                    }
                }
            }
            double error = getLeastError();
            pde = new ProfileDataElement(decreasedParam.getName(), paramLogVal, error, newParameters);
            profileData.addElement(0, pde);
            if (error > (iniError + 10)) {
                break;
            }
            if (Math.abs((error - lastError) / lastError) < MIN_LIKELIHOOD_CHANGE) {
                stepIncreaseCount++;
                decrementStep = DEFAULT_CI_STEPS[j] * Math.pow(2, stepIncreaseCount);
            } else {
                if (stepIncreaseCount > 1) {
                    incrementStep = DEFAULT_CI_STEPS[j] / Math.pow(2, stepIncreaseCount);
                    stepIncreaseCount--;
                }
            }
            if (clientTaskStatusSupport.isInterrupted()) {
                throw UserCancelException.CANCEL_GENERIC;
            }
            lastError = error;
            iterationCount++;
            clientTaskStatusSupport.setProgress((int) (((iterationCount + MAX_ITERATION) * 1.0 / MAX_ITERATION) * 0.5 * 100));
        }
        resultData[j] = profileData;
        // finish evaluation of a parameter
        clientTaskStatusSupport.setProgress(100);
    }
    // this message is specifically set for batchrun, the message will stay in the status panel. It doesn't affect single run,which disappears quickly that user won't notice.
    clientTaskStatusSupport.setMessage("Evaluating confidence intervals ...");
    // System.out.println("total time used:" + (endTime - startTime));
    return resultData;
}
Also used : ProfileDataElement(org.vcell.optimization.ProfileDataElement) Parameter(cbit.vcell.opt.Parameter) ProfileData(org.vcell.optimization.ProfileData)

Example 8 with ProfileDataElement

use of org.vcell.optimization.ProfileDataElement 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 9 with ProfileDataElement

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

the class MicroscopyXmlproducer method getXML.

private static Element getXML(ProfileDataElement profileDataElement) {
    Element profileDataElementNode = new Element(MicroscopyXMLTags.ProfieDataElementTag);
    profileDataElementNode.setAttribute(MicroscopyXMLTags.profileDataElementParameterNameAttrTag, profileDataElement.getParamName());
    profileDataElementNode.setAttribute(MicroscopyXMLTags.profileDataElementParameterValueAttrTag, profileDataElement.getParameterValue() + "");
    profileDataElementNode.setAttribute(MicroscopyXMLTags.profileDataElementLikelihoodAttrTag, profileDataElement.getLikelihood() + "");
    Parameter[] parameters = profileDataElement.getBestParameters();
    for (int i = 0; i < parameters.length; i++) {
        if (// some of parameters in reaction off rate model are null.
        parameters[i] != null) {
            profileDataElementNode.addContent(getXML(parameters[i]));
        }
    }
    return profileDataElementNode;
}
Also used : ProfileDataElement(org.vcell.optimization.ProfileDataElement) Element(org.jdom.Element) Parameter(cbit.vcell.opt.Parameter)

Example 10 with ProfileDataElement

use of org.vcell.optimization.ProfileDataElement 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

ProfileDataElement (org.vcell.optimization.ProfileDataElement)10 Parameter (cbit.vcell.opt.Parameter)8 ProfileData (org.vcell.optimization.ProfileData)5 Element (org.jdom.Element)4 Plot2D (cbit.plot.Plot2D)2 PlotData (cbit.plot.PlotData)2 ConfidenceInterval (org.vcell.optimization.ConfidenceInterval)2 ProfileSummaryData (org.vcell.optimization.ProfileSummaryData)2 DescriptiveStatistics (org.vcell.util.DescriptiveStatistics)2 Point (java.awt.Point)1 File (java.io.File)1 IOException (java.io.IOException)1 ClientTaskStatusSupport (org.vcell.util.ClientTaskStatusSupport)1 ProgressDialogListener (org.vcell.util.ProgressDialogListener)1