Search in sources :

Example 31 with Parameter

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

the class FRAPBatchRunWorkspace method updateAverageParameters.

private void updateAverageParameters() {
    // used to save old parameters to check if save is needed
    Parameter[] oldParameters = null;
    if (selectedModel == FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT) {
        Parameter diff = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_PRIMARY_DIFF_RATE], FRAPModel.REF_DIFFUSION_RATE_PARAM.getLowerBound(), FRAPModel.REF_DIFFUSION_RATE_PARAM.getUpperBound(), FRAPModel.REF_DIFFUSION_RATE_PARAM.getScale(), statisticsData[BatchRunResultsStatTableModel.ROW_IDX_AVERAGE][BatchRunResultsParamTableModel.COLUMN_PRI_DIFF_RATE - 1]);
        Parameter mobileFrac = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_PRIMARY_FRACTION], FRAPModel.REF_MOBILE_FRACTION_PARAM.getLowerBound(), FRAPModel.REF_MOBILE_FRACTION_PARAM.getUpperBound(), FRAPModel.REF_MOBILE_FRACTION_PARAM.getScale(), statisticsData[BatchRunResultsStatTableModel.ROW_IDX_AVERAGE][BatchRunResultsParamTableModel.COLUMN_PRI_MOBILE_FRACTION - 1]);
        Parameter bleachWhileMonitoringRate = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_BLEACH_MONITOR_RATE], FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getLowerBound(), FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getUpperBound(), FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getScale(), statisticsData[BatchRunResultsStatTableModel.ROW_IDX_AVERAGE][BatchRunResultsParamTableModel.COLUMN_BMR - 1]);
        // get old parameters
        oldParameters = getAverageParameters();
        setAverageParameters(new Parameter[] { diff, mobileFrac, bleachWhileMonitoringRate });
    } else if (selectedModel == FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS) {
        Parameter diff = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_PRIMARY_DIFF_RATE], FRAPModel.REF_DIFFUSION_RATE_PARAM.getLowerBound(), FRAPModel.REF_DIFFUSION_RATE_PARAM.getUpperBound(), FRAPModel.REF_DIFFUSION_RATE_PARAM.getScale(), statisticsData[BatchRunResultsStatTableModel.ROW_IDX_AVERAGE][BatchRunResultsParamTableModel.COLUMN_PRI_DIFF_RATE - 1]);
        Parameter mobileFrac = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_PRIMARY_FRACTION], FRAPModel.REF_MOBILE_FRACTION_PARAM.getLowerBound(), FRAPModel.REF_MOBILE_FRACTION_PARAM.getUpperBound(), FRAPModel.REF_MOBILE_FRACTION_PARAM.getScale(), statisticsData[BatchRunResultsStatTableModel.ROW_IDX_AVERAGE][BatchRunResultsParamTableModel.COLUMN_PRI_MOBILE_FRACTION - 1]);
        Parameter bleachWhileMonitoringRate = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_BLEACH_MONITOR_RATE], FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getLowerBound(), FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getUpperBound(), FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getScale(), statisticsData[BatchRunResultsStatTableModel.ROW_IDX_AVERAGE][BatchRunResultsParamTableModel.COLUMN_BMR - 1]);
        Parameter secDiffRate = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_SECONDARY_DIFF_RATE], FRAPModel.REF_SECOND_DIFFUSION_RATE_PARAM.getLowerBound(), FRAPModel.REF_SECOND_DIFFUSION_RATE_PARAM.getUpperBound(), FRAPModel.REF_SECOND_DIFFUSION_RATE_PARAM.getScale(), statisticsData[BatchRunResultsStatTableModel.ROW_IDX_AVERAGE][BatchRunResultsParamTableModel.COLUMN_SEC_DIFF_RATE - 1]);
        Parameter secMobileFrac = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_SECONDARY_FRACTION], FRAPModel.REF_SECOND_MOBILE_FRACTION_PARAM.getLowerBound(), FRAPModel.REF_SECOND_MOBILE_FRACTION_PARAM.getUpperBound(), FRAPModel.REF_SECOND_MOBILE_FRACTION_PARAM.getScale(), statisticsData[BatchRunResultsStatTableModel.ROW_IDX_AVERAGE][BatchRunResultsParamTableModel.COLUMN_SEC_MOBILE_FRACTION - 1]);
        // get old parameters
        oldParameters = getAverageParameters();
        setAverageParameters(new Parameter[] { diff, mobileFrac, bleachWhileMonitoringRate, secDiffRate, secMobileFrac });
    } else if (selectedModel == FRAPModel.IDX_MODEL_REACTION_OFF_RATE) {
        Parameter bleachWhileMonitoringRate = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_BLEACH_MONITOR_RATE], FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getLowerBound(), FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getUpperBound(), FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getScale(), statisticsData[BatchRunResultsStatTableModel.ROW_IDX_AVERAGE][BatchRunResultsParamTableModel.COLUMN_BMR - 1]);
        Parameter fittingParam = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_BINDING_SITE_CONCENTRATION], FRAPModel.REF_BS_CONCENTRATION_OR_A.getLowerBound(), FRAPModel.REF_BS_CONCENTRATION_OR_A.getUpperBound(), FRAPModel.REF_BS_CONCENTRATION_OR_A.getScale(), statisticsData[BatchRunResultsStatTableModel.ROW_IDX_AVERAGE][BatchRunResultsParamTableModel.COLUMN_BS_CONCENTRATION - 1]);
        Parameter offRate = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_OFF_RATE], FRAPModel.REF_REACTION_OFF_RATE.getLowerBound(), FRAPModel.REF_REACTION_OFF_RATE.getUpperBound(), FRAPModel.REF_REACTION_OFF_RATE.getScale(), statisticsData[BatchRunResultsStatTableModel.ROW_IDX_AVERAGE][BatchRunResultsParamTableModel.COLUMN_OFF_RATE - 1]);
        // get old parameters
        oldParameters = getAverageParameters();
        setAverageParameters(new Parameter[] { null, null, bleachWhileMonitoringRate, null, null, fittingParam, null, offRate });
    }
    // check to see if we need to set save flag
    boolean bSaveNeeded = true;
    if (oldParameters != null && getAverageParameters() != null) {
        if (oldParameters.length != getAverageParameters().length) {
            bSaveNeeded = false;
        }
        for (int i = 0; i < oldParameters.length; i++) {
            if (!Compare.isEqualOrNull(oldParameters[i], getAverageParameters()[i])) {
                bSaveNeeded = false;
            }
        }
    } else if (oldParameters == null && getAverageParameters() == null) {
        bSaveNeeded = false;
    }
    setSaveNeeded(bSaveNeeded);
}
Also used : Parameter(cbit.vcell.opt.Parameter)

Example 32 with Parameter

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

the class ModelOptimizationMapping method computeOptimizationSpec.

/**
 * Insert the method's description here.
 * Creation date: (8/22/2005 9:26:52 AM)
 * @return cbit.vcell.opt.OptimizationSpec
 * @param modelOptimizationSpec cbit.vcell.modelopt.ModelOptimizationSpec
 */
MathSymbolMapping computeOptimizationSpec() throws MathException, MappingException {
    if (getModelOptimizationSpec().getReferenceData() == null) {
        System.out.println("no referenced data defined");
        return null;
    }
    OptimizationSpec optSpec = new OptimizationSpec();
    optSpec.setComputeProfileDistributions(modelOptimizationSpec.isComputeProfileDistributions());
    parameterMappings = null;
    // 
    // get original MathDescription (later to be substituted for local/global parameters).
    // 
    SimulationContext simContext = modelOptimizationSpec.getSimulationContext();
    MathMapping mathMapping = simContext.createNewMathMapping();
    MathDescription origMathDesc = null;
    mathSymbolMapping = null;
    try {
        origMathDesc = mathMapping.getMathDescription();
        mathSymbolMapping = mathMapping.getMathSymbolMapping();
    } catch (MatrixException e) {
        e.printStackTrace(System.out);
        throw new MappingException(e.getMessage());
    } catch (ModelException e) {
        e.printStackTrace(System.out);
        throw new MappingException(e.getMessage());
    } catch (ExpressionException e) {
        e.printStackTrace(System.out);
        throw new MathException(e.getMessage());
    }
    // 
    // create objective function (mathDesc and data)
    // 
    ReferenceData referenceData = getRemappedReferenceData(mathMapping);
    if (referenceData == null) {
        throw new RuntimeException("no referenced data defined");
    }
    // 
    // get parameter mappings
    // 
    ParameterMappingSpec[] parameterMappingSpecs = modelOptimizationSpec.getParameterMappingSpecs();
    Vector<ParameterMapping> parameterMappingList = new Vector<ParameterMapping>();
    Variable[] allVars = (Variable[]) BeanUtils.getArray(origMathDesc.getVariables(), Variable.class);
    for (int i = 0; i < parameterMappingSpecs.length; i++) {
        cbit.vcell.model.Parameter modelParameter = parameterMappingSpecs[i].getModelParameter();
        String mathSymbol = null;
        Variable mathVariable = null;
        if (mathSymbolMapping != null) {
            Variable variable = mathSymbolMapping.getVariable(modelParameter);
            if (variable != null) {
                mathSymbol = variable.getName();
            }
            if (mathSymbol != null) {
                mathVariable = origMathDesc.getVariable(mathSymbol);
            }
        }
        if (mathVariable != null) {
            if (parameterMappingSpecs[i].isSelected()) {
                if (parameterMappingSpecs[i].getHigh() < parameterMappingSpecs[i].getLow()) {
                    throw new MathException("The lower bound for Parameter '" + parameterMappingSpecs[i].getModelParameter().getName() + "' is greater than its upper bound.");
                }
                if (parameterMappingSpecs[i].getCurrent() < parameterMappingSpecs[i].getLow()) {
                    throw new MathException("The initial guess of '" + parameterMappingSpecs[i].getModelParameter().getName() + "' is smaller than its lower bound.");
                }
                if (parameterMappingSpecs[i].getCurrent() > parameterMappingSpecs[i].getHigh()) {
                    throw new MathException("The initial guess of '" + parameterMappingSpecs[i].getModelParameter().getName() + "' is greater than its upper bound.");
                }
                if (parameterMappingSpecs[i].getLow() < 0) {
                    throw new MathException("The lower bound for Parameter '" + parameterMappingSpecs[i].getModelParameter().getName() + "' is negative. All lower bounds must not be negative.");
                }
                if (Double.isInfinite(parameterMappingSpecs[i].getLow())) {
                    throw new MathException("The lower bound for Parameter '" + parameterMappingSpecs[i].getModelParameter().getName() + "' is infinity. Lower bounds must not be infinity.");
                }
                if (parameterMappingSpecs[i].getHigh() <= 0) {
                    throw new MathException("The upper bound for Parameter '" + parameterMappingSpecs[i].getModelParameter().getName() + "' is negative. All upper bounds must be positive.");
                }
                if (Double.isInfinite(parameterMappingSpecs[i].getHigh())) {
                    throw new MathException("The upper bound for Parameter '" + parameterMappingSpecs[i].getModelParameter().getName() + "' is infinity. Upper bounds must not be infinity.");
                }
            }
            double low = parameterMappingSpecs[i].isSelected() && parameterMappingSpecs[i].getLow() == 0 ? 1e-8 : parameterMappingSpecs[i].getLow();
            double high = parameterMappingSpecs[i].getHigh();
            double scale = Math.abs(parameterMappingSpecs[i].getCurrent()) < 1.0E-10 ? 1.0 : Math.abs(parameterMappingSpecs[i].getCurrent());
            double current = parameterMappingSpecs[i].getCurrent();
            low = Math.min(low, current);
            high = Math.max(high, current);
            Parameter optParameter = new Parameter(mathSymbol, low, high, scale, current);
            ParameterMapping parameterMapping = new ParameterMapping(modelParameter, optParameter, mathVariable);
            // 
            if (mathVariable instanceof Constant) {
                Constant origConstant = (Constant) mathVariable;
                for (int j = 0; j < allVars.length; j++) {
                    if (allVars[j].equals(origConstant)) {
                        if (parameterMappingSpecs[i].isSelected()) {
                            allVars[j] = new ParameterVariable(origConstant.getName());
                        } else {
                            allVars[j] = new Constant(origConstant.getName(), new Expression(optParameter.getInitialGuess()));
                        }
                        break;
                    }
                }
            }
            // 
            if (parameterMappingSpecs[i].isSelected()) {
                parameterMappingList.add(parameterMapping);
            }
        }
    }
    parameterMappings = (ParameterMapping[]) BeanUtils.getArray(parameterMappingList, ParameterMapping.class);
    try {
        origMathDesc.setAllVariables(allVars);
    } catch (ExpressionBindingException e) {
        e.printStackTrace(System.out);
        throw new MathException(e.getMessage());
    }
    // 
    for (int i = 0; i < parameterMappings.length; i++) {
        optSpec.addParameter(parameterMappings[i].getOptParameter());
    }
    Vector<Issue> issueList = new Vector<Issue>();
    IssueContext issueContext = new IssueContext();
    optSpec.gatherIssues(issueContext, issueList);
    for (int i = 0; i < issueList.size(); i++) {
        Issue issue = issueList.elementAt(i);
        if (issue.getSeverity() == Issue.SEVERITY_ERROR) {
            throw new RuntimeException(issue.getMessage());
        }
    }
    // 
    // 
    // 
    optimizationSpec = optSpec;
    return mathSymbolMapping;
}
Also used : ParameterVariable(cbit.vcell.math.ParameterVariable) Variable(cbit.vcell.math.Variable) Issue(org.vcell.util.Issue) MathDescription(cbit.vcell.math.MathDescription) Constant(cbit.vcell.math.Constant) ParameterVariable(cbit.vcell.math.ParameterVariable) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MatrixException(cbit.vcell.matrix.MatrixException) IssueContext(org.vcell.util.IssueContext) OptimizationSpec(cbit.vcell.opt.OptimizationSpec) Vector(java.util.Vector) ModelException(cbit.vcell.model.ModelException) SimulationContext(cbit.vcell.mapping.SimulationContext) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) Expression(cbit.vcell.parser.Expression) MathException(cbit.vcell.math.MathException) MathMapping(cbit.vcell.mapping.MathMapping) Parameter(cbit.vcell.opt.Parameter)

Example 33 with Parameter

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

the class VirtualFrapBatchRunFrame method getBatchRunTasks.

private ArrayList<AsynchClientTask> getBatchRunTasks() {
    // to run batch files
    ArrayList<AsynchClientTask> batchRunTaskList = new ArrayList<AsynchClientTask>();
    for (int i = 0; i < batchRunWorkspace.getFrapStudies().size(); i++) {
        final int finalIdx = i;
        AsynchClientTask message1Task = new AsynchClientTask("Preparing for parameter estimation ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                appendJobStatus("<html><br>Running " + (batchRunWorkspace.getFrapStudies().get(finalIdx)).getXmlFilename() + "</html>", false);
            }
        };
        AsynchClientTask saveTask = new AsynchClientTask("Preparing for parameter estimation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
                if (fStudy.hasDiffusionOnlyModel()) {
                    // check external data info. If not existing,  we have to run ref simulation.
                    if (!FRAPWorkspace.areExternalDataOK(localWorkspace, fStudy.getFrapDataExternalDataInfo(), fStudy.getRoiExternalDataInfo())) {
                        // if external files are missing/currupt or ROIs are changed, create keys and save them
                        fStudy.setFrapDataExternalDataInfo(FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.IMAGE_EXTDATA_NAME));
                        fStudy.setRoiExternalDataInfo(FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.ROI_EXTDATA_NAME));
                        fStudy.saveROIsAsExternalData(localWorkspace, fStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
                        fStudy.saveImageDatasetAsExternalData(localWorkspace, fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
                    }
                }
            }
        };
        AsynchClientTask message2Task = new AsynchClientTask("Running reference simulation ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
                if (fStudy.hasDiffusionOnlyModel()) {
                    MessagePanel msgPanel = appendJobStatus("Running reference simulation ...", true);
                    hashTable.put("runRefStatus", msgPanel);
                } else if (fStudy.hasReactionOnlyOffRateModel()) {
                // MessagePanel msgPanel = appendJobStatus("...", true);
                // hashTable.put("runRefStatus", msgPanel);
                }
            }
        };
        AsynchClientTask runRefSimTask = new AsynchClientTask("Running reference simulation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
                if (fStudy.hasDiffusionOnlyModel()) {
                    MessagePanel msgPanel = (MessagePanel) hashTable.get("runRefStatus");
                    // run ref sim
                    if (// if ref data is stored ,we don't have to re-run
                    fStudy.getStoredRefData() != null) {
                        fStudy.setFrapOptData(new FRAPOptData(fStudy, FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF, localWorkspace, fStudy.getStoredRefData()));
                    } else {
                        fStudy.setFrapOptData(new FRAPOptData(fStudy, FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF, localWorkspace, msgPanel));
                    }
                } else if (fStudy.hasReactionOnlyOffRateModel()) {
                    if (fStudy.getFrapOptFunc() == null) {
                        fStudy.setFrapOptFunc(new FRAPOptFunctions(fStudy));
                    }
                }
            }
        };
        AsynchClientTask message3Task = new AsynchClientTask("Running optimization ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
                if (fStudy.hasDiffusionOnlyModel()) {
                    MessagePanel msgPanel = (MessagePanel) hashTable.get("runRefStatus");
                    msgPanel.setProgressCompleted();
                }
                MessagePanel msgPanel1 = appendJobStatus("Running optimization ...", true);
                hashTable.put("optimizationStatus", msgPanel1);
            }
        };
        AsynchClientTask runOptTask = new AsynchClientTask("Running optimization ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
                ArrayList<Integer> models = fStudy.getSelectedModels();
                if (models.size() == 1) {
                    for (int i = 0; i < models.size(); i++) {
                        int model = (models.get(i)).intValue();
                        if (model == batchRunWorkspace.getSelectedModel()) {
                            if (model == FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT) {
                                // if(fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() == null)
                                // {//always run
                                fStudy.getFrapOptData().setNumEstimatedParams(FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF);
                                Parameter[] initialParams = FRAPModel.getInitialParameters(fStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT], fStudy.getStartingIndexForRecovery());
                                // set model parameters and data
                                Parameter[] bestParameters = fStudy.getFrapOptData().getBestParamters(initialParams, fStudy.getSelectedROIsForErrorCalculation());
                                double[][] fitData = fStudy.getFrapOptData().getFitData(bestParameters);
                                fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].setModelParameters(bestParameters);
                                fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].setData(fitData);
                            // }
                            } else if (model == FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS) {
                                // if(fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters() == null)
                                // {//always run
                                fStudy.getFrapOptData().setNumEstimatedParams(FRAPModel.NUM_MODEL_PARAMETERS_TWO_DIFF);
                                Parameter[] initialParams = FRAPModel.getInitialParameters(fStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS], fStudy.getStartingIndexForRecovery());
                                // set model parameters and data
                                Parameter[] bestParameters = fStudy.getFrapOptData().getBestParamters(initialParams, fStudy.getSelectedROIsForErrorCalculation());
                                double[][] fitData = fStudy.getFrapOptData().getFitData(bestParameters);
                                fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].setModelParameters(bestParameters);
                                fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].setData(fitData);
                            // }
                            } else if (model == FRAPModel.IDX_MODEL_REACTION_OFF_RATE) {
                                Parameter[] bestParameters = fStudy.getFrapOptFunc().getBestParamters(fStudy.getFrapData(), null, true);
                                double[][] fitData = fStudy.getFrapOptFunc().getFitData(bestParameters);
                                fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].setModelParameters(bestParameters);
                                fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].setData(fitData);
                            }
                        } else {
                            throw new Exception("Selected model for batch run is not the same as selected model in FRAP doc " + fStudy.getXmlFilename());
                        }
                    }
                } else {
                    throw new Exception("Selected model size exceed 1");
                }
            }
        };
        AsynchClientTask message4Task = new AsynchClientTask("Evaluating confidence intervals for parameters ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                MessagePanel msgPanel = (MessagePanel) hashTable.get("optimizationStatus");
                msgPanel.setProgressCompleted();
                MessagePanel msgPanel2 = appendJobStatus("Evaluating confidence intervals for parameters ...", true);
                hashTable.put("evaluateCI", msgPanel2);
            }
        };
        AsynchClientTask evaluateCITask = new AsynchClientTask("Evaluating confidence intervals for parameters ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
                MessagePanel msgPanel = (MessagePanel) hashTable.get("evaluateCI");
                // evaluate confidence intervals
                ArrayList<Integer> models = fStudy.getSelectedModels();
                if (models.size() == 1) {
                    for (int i = 0; i < models.size(); i++) {
                        int model = (models.get(i)).intValue();
                        if (model == batchRunWorkspace.getSelectedModel()) {
                            if (model == FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT) {
                                if (fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() != null) {
                                    ProfileData[] profileData = fStudy.getFrapOptData().evaluateParameters(fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters(), msgPanel);
                                    fStudy.setProfileData_oneDiffComponent(profileData);
                                }
                            } else if (model == FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS) {
                                if (fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters() != null) {
                                    ProfileData[] profileData = fStudy.getFrapOptData().evaluateParameters(fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters(), msgPanel);
                                    fStudy.setProfileData_twoDiffComponents(profileData);
                                }
                            } else if (model == FRAPModel.IDX_MODEL_REACTION_OFF_RATE) {
                                if (fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters() != null) {
                                    ProfileData[] profileData = fStudy.getFrapOptFunc().evaluateParameters(fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters(), msgPanel);
                                    fStudy.setProfileData_reactionOffRate(profileData);
                                }
                            }
                        } else {
                            throw new Exception("Selected model for batch run is not the same as selected model in FRAP doc " + fStudy.getXmlFilename());
                        }
                    }
                } else {
                    throw new Exception("Selected model size exceed 1");
                }
            }
        };
        AsynchClientTask message5Task = new AsynchClientTask("Evaluating confidence intervals for parameters ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                MessagePanel msgPanel = (MessagePanel) hashTable.get("evaluateCI");
                msgPanel.setProgressCompleted();
            }
        };
        batchRunTaskList.add(message1Task);
        batchRunTaskList.add(saveTask);
        batchRunTaskList.add(message2Task);
        batchRunTaskList.add(runRefSimTask);
        batchRunTaskList.add(message3Task);
        batchRunTaskList.add(runOptTask);
        batchRunTaskList.add(message4Task);
        batchRunTaskList.add(evaluateCITask);
        batchRunTaskList.add(message5Task);
    }
    return batchRunTaskList;
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) FRAPOptFunctions(cbit.vcell.microscopy.FRAPOptFunctions) ArrayList(java.util.ArrayList) ProfileData(org.vcell.optimization.ProfileData) UserCancelException(org.vcell.util.UserCancelException) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) FRAPOptData(cbit.vcell.microscopy.FRAPOptData) Parameter(cbit.vcell.opt.Parameter)

Example 34 with Parameter

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

the class FRAPModel method getInitialParameters.

public static Parameter[] getInitialParameters(FRAPData frapData, String modelIdentifier, int startIndexForRecovery) throws ExpressionException, OptimizationException, IOException {
    Parameter[] params = null;
    // get estimated bleach type
    double bleachFraction = FRAPDataAnalysis.getCellAreaBleachedFraction(frapData);
    int bleachType = (bleachFraction > FRAPDataAnalysis.THRESHOLD_BLEACH_TYPE) ? FrapDataAnalysisResults.DiffusionOnlyAnalysisRestults.BleachType_HalfCell : FrapDataAnalysisResults.DiffusionOnlyAnalysisRestults.BleachType_GaussianSpot;
    // get analytical results
    FrapDataAnalysisResults.DiffusionOnlyAnalysisRestults analysisResults = FRAPDataAnalysis.fitRecovery_diffusionOnly(frapData, bleachType, startIndexForRecovery);
    // constrain the parameters in upper and lower bounds, analytic solution may get weird results sometimes(e.g. once got diffRate = 2819000.674223344)
    double diffusionRate = analysisResults.getRecoveryDiffusionRate();
    diffusionRate = (diffusionRate > REF_DIFFUSION_RATE_PARAM.getUpperBound()) ? REF_DIFFUSION_RATE_PARAM.getUpperBound() : diffusionRate;
    diffusionRate = (diffusionRate < REF_DIFFUSION_RATE_PARAM.getLowerBound()) ? REF_DIFFUSION_RATE_PARAM.getLowerBound() : diffusionRate;
    double mobileFraction = analysisResults.getMobilefraction();
    mobileFraction = (mobileFraction > REF_MOBILE_FRACTION_PARAM.getUpperBound()) ? REF_MOBILE_FRACTION_PARAM.getUpperBound() : mobileFraction;
    mobileFraction = (mobileFraction < REF_MOBILE_FRACTION_PARAM.getLowerBound()) ? REF_MOBILE_FRACTION_PARAM.getLowerBound() : mobileFraction;
    double bwmRate = analysisResults.getBleachWhileMonitoringTau();
    bwmRate = (bwmRate > REF_BLEACH_WHILE_MONITOR_PARAM.getUpperBound()) ? REF_BLEACH_WHILE_MONITOR_PARAM.getUpperBound() : bwmRate;
    bwmRate = (bwmRate < REF_BLEACH_WHILE_MONITOR_PARAM.getLowerBound()) ? REF_BLEACH_WHILE_MONITOR_PARAM.getLowerBound() : bwmRate;
    // create parameter array
    if (modelIdentifier.equals(MODEL_TYPE_ARRAY[IDX_MODEL_DIFF_ONE_COMPONENT])) {
        Parameter diff = new Parameter(MODEL_PARAMETER_NAMES[INDEX_PRIMARY_DIFF_RATE], REF_DIFFUSION_RATE_PARAM.getLowerBound(), REF_DIFFUSION_RATE_PARAM.getUpperBound(), REF_DIFFUSION_RATE_PARAM.getScale(), diffusionRate);
        Parameter mobileFrac = new Parameter(MODEL_PARAMETER_NAMES[INDEX_PRIMARY_FRACTION], REF_MOBILE_FRACTION_PARAM.getLowerBound(), REF_MOBILE_FRACTION_PARAM.getUpperBound(), REF_MOBILE_FRACTION_PARAM.getScale(), mobileFraction);
        Parameter bleachWhileMonitoringRate = new Parameter(MODEL_PARAMETER_NAMES[INDEX_BLEACH_MONITOR_RATE], REF_BLEACH_WHILE_MONITOR_PARAM.getLowerBound(), REF_BLEACH_WHILE_MONITOR_PARAM.getUpperBound(), REF_BLEACH_WHILE_MONITOR_PARAM.getScale(), bwmRate);
        params = new Parameter[FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF];
        params[FRAPModel.INDEX_PRIMARY_DIFF_RATE] = diff;
        params[FRAPModel.INDEX_PRIMARY_FRACTION] = mobileFrac;
        params[FRAPModel.INDEX_BLEACH_MONITOR_RATE] = bleachWhileMonitoringRate;
    } else if (modelIdentifier.equals(MODEL_TYPE_ARRAY[IDX_MODEL_DIFF_TWO_COMPONENTS])) {
        Parameter diff = new Parameter(MODEL_PARAMETER_NAMES[INDEX_PRIMARY_DIFF_RATE], REF_DIFFUSION_RATE_PARAM.getLowerBound(), REF_DIFFUSION_RATE_PARAM.getUpperBound(), REF_DIFFUSION_RATE_PARAM.getScale(), diffusionRate);
        Parameter mobileFrac = new Parameter(MODEL_PARAMETER_NAMES[INDEX_PRIMARY_FRACTION], REF_MOBILE_FRACTION_PARAM.getLowerBound(), REF_MOBILE_FRACTION_PARAM.getUpperBound(), REF_MOBILE_FRACTION_PARAM.getScale(), mobileFraction);
        Parameter monitorRate = new Parameter(MODEL_PARAMETER_NAMES[INDEX_BLEACH_MONITOR_RATE], REF_BLEACH_WHILE_MONITOR_PARAM.getLowerBound(), REF_BLEACH_WHILE_MONITOR_PARAM.getUpperBound(), REF_BLEACH_WHILE_MONITOR_PARAM.getScale(), bwmRate);
        Parameter secDiffRate = new Parameter(MODEL_PARAMETER_NAMES[INDEX_SECONDARY_DIFF_RATE], REF_SECOND_DIFFUSION_RATE_PARAM.getLowerBound(), REF_SECOND_DIFFUSION_RATE_PARAM.getUpperBound(), REF_SECOND_DIFFUSION_RATE_PARAM.getScale(), 0);
        Parameter secMobileFrac = new Parameter(MODEL_PARAMETER_NAMES[INDEX_SECONDARY_FRACTION], REF_SECOND_MOBILE_FRACTION_PARAM.getLowerBound(), REF_SECOND_MOBILE_FRACTION_PARAM.getUpperBound(), REF_SECOND_MOBILE_FRACTION_PARAM.getScale(), 0);
        params = new Parameter[FRAPModel.NUM_MODEL_PARAMETERS_TWO_DIFF];
        params[FRAPModel.INDEX_PRIMARY_DIFF_RATE] = diff;
        params[FRAPModel.INDEX_PRIMARY_FRACTION] = mobileFrac;
        params[FRAPModel.INDEX_BLEACH_MONITOR_RATE] = monitorRate;
        params[FRAPModel.INDEX_SECONDARY_DIFF_RATE] = secDiffRate;
        params[FRAPModel.INDEX_SECONDARY_FRACTION] = secMobileFrac;
    }
    return params;
}
Also used : Parameter(cbit.vcell.opt.Parameter)

Example 35 with Parameter

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

the class FRAPOptFunctions method getBestParamters.

// The best parameters will return a whole set of reaction off rate parameters (totally 8 parameters)
public Parameter[] getBestParamters(FRAPData frapData, Parameter fixedParam, boolean bApplyMeasurementError) throws Exception {
    if (measurementErrors == null) {
        measurementErrors = FRAPOptimizationUtils.refreshNormalizedMeasurementError(getExpFrapStudy());
    }
    setIsApplyMeasurementError(bApplyMeasurementError);
    Parameter[] outputParams = new Parameter[FRAPModel.NUM_MODEL_PARAMETERS_REACTION_OFF_RATE];
    FrapDataAnalysisResults.ReactionOnlyAnalysisRestults offRateResults = FRAPDataAnalysis.fitRecovery_reacOffRateOnly(frapData, fixedParam, measurementErrors, getExpFrapStudy().getStartingIndexForRecovery());
    setOffRateResults(offRateResults);
    outputParams[FRAPModel.INDEX_BLEACH_MONITOR_RATE] = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_BLEACH_MONITOR_RATE], FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getLowerBound(), FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getUpperBound(), FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getScale(), offRateResults.getBleachWhileMonitoringTau());
    outputParams[FRAPModel.INDEX_BINDING_SITE_CONCENTRATION] = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_BINDING_SITE_CONCENTRATION], FRAPModel.REF_BS_CONCENTRATION_OR_A.getLowerBound(), FRAPModel.REF_BS_CONCENTRATION_OR_A.getUpperBound(), FRAPModel.REF_BS_CONCENTRATION_OR_A.getScale(), offRateResults.getFittingParamA());
    outputParams[FRAPModel.INDEX_OFF_RATE] = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_OFF_RATE], FRAPModel.REF_REACTION_OFF_RATE.getLowerBound(), FRAPModel.REF_REACTION_OFF_RATE.getUpperBound(), FRAPModel.REF_REACTION_OFF_RATE.getScale(), offRateResults.getOffRate());
    // System.out.println("error" + getWeightedError(offRateResults.getOffRateFitExpression()));
    return outputParams;
}
Also used : Parameter(cbit.vcell.opt.Parameter)

Aggregations

Parameter (cbit.vcell.opt.Parameter)59 FRAPStudy (cbit.vcell.microscopy.FRAPStudy)11 Hashtable (java.util.Hashtable)10 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)9 ProfileDataElement (org.vcell.optimization.ProfileDataElement)8 Expression (cbit.vcell.parser.Expression)7 File (java.io.File)7 FRAPModel (cbit.vcell.microscopy.FRAPModel)6 ProfileData (org.vcell.optimization.ProfileData)6 OptimizationResultSet (cbit.vcell.opt.OptimizationResultSet)5 Element (org.jdom.Element)5 OptSolverResultSet (cbit.vcell.opt.OptSolverResultSet)4 OptimizationSpec (cbit.vcell.opt.OptimizationSpec)4 SimpleReferenceData (cbit.vcell.opt.SimpleReferenceData)4 ArrayList (java.util.ArrayList)4 ROI (cbit.vcell.VirtualMicroscopy.ROI)3 Dimension (java.awt.Dimension)3 Plot2D (cbit.plot.Plot2D)2 PlotData (cbit.plot.PlotData)2 BioModel (cbit.vcell.biomodel.BioModel)2