Search in sources :

Example 26 with Parameter

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

the class MicroscopyXmlReader method getParameter.

private Parameter getParameter(Element paramElement) {
    Parameter parameter = null;
    if (paramElement != null) {
        String name = unMangle(paramElement.getAttributeValue(OptXmlTags.ParameterName_Attr));
        double lowerBound = new Double(unMangle(paramElement.getAttributeValue(OptXmlTags.ParameterLow_Attr)));
        double upperBound = new Double(unMangle(paramElement.getAttributeValue(OptXmlTags.ParameterHigh_Attr)));
        double iniGuess = new Double(unMangle(paramElement.getAttributeValue(OptXmlTags.ParameterInit_Attr)));
        double scale = new Double(unMangle(paramElement.getAttributeValue(OptXmlTags.ParameterScale_Attr)));
        parameter = new Parameter(name, lowerBound, upperBound, scale, iniGuess);
    }
    return parameter;
}
Also used : Parameter(cbit.vcell.opt.Parameter)

Example 27 with Parameter

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

the class OptModelParamPanel method init.

public void init(OptContext optContext, NormalizedSampleFunction[] fittedROIs, LocalWorkspace localWorkspace) {
    this.optContext = optContext;
    this.fittedROIs = fittedROIs;
    this.localWorkspace = localWorkspace;
    Parameter[] parameters = optContext.getParameters();
    final GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[] { 7, 7, 7, 0 };
    gridBagLayout.rowHeights = new int[] { 7, 7, 7, 7 };
    parameterPanel.setLayout(gridBagLayout);
    int gridLayout_Y = 0;
    for (int i = 0; i < parameters.length; i++) {
        final JLabel label = new JLabel();
        label.setText(parameters[i].getName());
        final GridBagConstraints gridBagConstraints0 = new GridBagConstraints();
        gridBagConstraints0.insets = new Insets(2, 2, 2, 2);
        gridBagConstraints0.anchor = GridBagConstraints.EAST;
        gridBagConstraints0.gridy = gridLayout_Y;
        gridBagConstraints0.gridx = 0;
        parameterPanel.add(label, gridBagConstraints0);
        JTextField textField = new JTextField();
        parameterValueTextFields.add(textField);
        textField.getDocument().addUndoableEditListener(EDIT_LISTENER);
        textField.setPreferredSize(new Dimension(125, 20));
        textField.addActionListener(OPTIMIZER_VALUE_ACTION_LISTENER);
        textField.setMinimumSize(new Dimension(125, 20));
        final GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(2, 2, 2, 0);
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
        gridBagConstraints.gridy = gridLayout_Y;
        gridBagConstraints.gridx = 1;
        parameterPanel.add(textField, gridBagConstraints);
        JButton setButton = new JButton();
        parameterValueSetButtons.add(setButton);
        setButton.setMargin(new Insets(2, 1, 2, 1));
        setButton.addActionListener(SET_ACTION_LISTENER);
        setButton.setText("Set");
        final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
        gridBagConstraints_1.insets = new Insets(2, 0, 2, 2);
        gridBagConstraints_1.gridy = gridLayout_Y;
        gridBagConstraints_1.gridx = 2;
        parameterPanel.add(setButton, gridBagConstraints_1);
        JSlider slider = new JSlider();
        parameterValueSliders.add(slider);
        slider.addChangeListener(OPTIMIZER_SLIDER_CHANGE_LISTENER);
        slider.setPaintLabels(true);
        final GridBagConstraints gridBagConstraints_4 = new GridBagConstraints();
        gridBagConstraints_4.weighty = 1;
        gridBagConstraints_4.insets = new Insets(2, 2, 2, 0);
        gridBagConstraints_4.fill = GridBagConstraints.HORIZONTAL;
        gridBagConstraints_4.weightx = 1;
        gridBagConstraints_4.gridy = gridLayout_Y;
        gridBagConstraints_4.gridx = 3;
        parameterPanel.add(slider, gridBagConstraints_4);
        gridLayout_Y++;
    }
    for (JSlider slider : parameterValueSliders) {
        slider.removeChangeListener(OPTIMIZER_SLIDER_CHANGE_LISTENER);
    }
    try {
        for (int parameterIndex = 0; parameterIndex < parameters.length; parameterIndex++) {
            Parameter parameter = parameters[parameterIndex];
            JSlider slider = parameterValueSliders.get(parameterIndex);
            Hashtable<Integer, JComponent> sliderLabelTable = new Hashtable<Integer, JComponent>();
            slider.setMinimum(0);
            slider.setMaximum(2000);
            slider.setValue(0);
            sliderLabelTable.put(0, new JLabel(parameter.getLowerBound() + ""));
            sliderLabelTable.put(2000, new JLabel(parameter.getUpperBound() + ""));
            // 
            // way of doing a log scale
            // 
            // bleachWhileMonitorSliderLabelTable.put(new Integer(0), new JLabel(FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getLowerBound()+""));
            // bleachWhileMonitorSliderLabelTable.put(new Integer(20), new JLabel("1e-4"));
            // bleachWhileMonitorSliderLabelTable.put(new Integer(40), new JLabel("1e-3"));
            // bleachWhileMonitorSliderLabelTable.put(new Integer(60), new JLabel("1e-2"));
            // bleachWhileMonitorSliderLabelTable.put(new Integer(80), new JLabel("1e-1"));
            // bleachWhileMonitorSliderLabelTable.put(new Integer(100),new JLabel(FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getUpperBound()+""));
            // Kludge for WindowBuilder otherwise not display correctly
            slider.setLabelTable(null);
            slider.setLabelTable(sliderLabelTable);
        }
    } finally {
        for (JSlider slider : parameterValueSliders) {
            slider.addChangeListener(OPTIMIZER_SLIDER_CHANGE_LISTENER);
        }
    }
    double[] parameterValues = new double[parameters.length];
    for (int i = 0; i < parameters.length; i++) {
        parameterValues[i] = parameters[i].getInitialGuess();
    }
    setParameterValues(parameterValues);
    plotDerivedSimulationResults();
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) Hashtable(java.util.Hashtable) JButton(javax.swing.JButton) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) Parameter(cbit.vcell.opt.Parameter) WorkflowParameter(org.vcell.workflow.WorkflowParameter) JSlider(javax.swing.JSlider)

Example 28 with Parameter

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

the class RunProfileLikelihoodGeneralOp method evaluateParameters.

private ProfileData[] evaluateParameters(OptContext optContext, Parameter[] currentParams, ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    // long startTime =System.currentTimeMillis();
    int totalParamLen = currentParams.length;
    ProfileData[] resultData = new ProfileData[totalParamLen];
    for (int j = 0; j < totalParamLen; j++) {
        ProfileData profileData = new ProfileData();
        // add the fixed parameter to profileData, output exp data and opt results
        Parameter[] newBestParameters = getBestParameters(optContext, currentParams, null);
        double iniError = leastError;
        // 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(), epsilon);
        }
        if (clientTaskStatusSupport != null) {
            clientTaskStatusSupport.setMessage("<html>Evaluating confidence intervals of \'" + fixedParam.getName() + "\' <br> of model '" + optContext.getModelName() + "'.</html>");
        }
        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 = CONFIDENCE_INTERVAL_STEP;
        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() - epsilon)) {
                paramVal = fixedParam.getUpperBound() - epsilon;
                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
            optContext.setFixedParameter(fixedParam, paramVal);
            Parameter[] newParameters = getBestParameters(optContext, unFixedParams, increasedParam);
            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 = leastError;
            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 = CONFIDENCE_INTERVAL_STEP * Math.pow(2, stepIncreaseCount);
            } else {
                if (stepIncreaseCount > 1) {
                    incrementStep = CONFIDENCE_INTERVAL_STEP / Math.pow(2, stepIncreaseCount);
                    stepIncreaseCount--;
                }
            }
            if (clientTaskStatusSupport != null && clientTaskStatusSupport.isInterrupted()) {
                throw UserCancelException.CANCEL_GENERIC;
            }
            lastError = error;
            iterationCount++;
            if (clientTaskStatusSupport != null) {
                clientTaskStatusSupport.setProgress((int) ((iterationCount * 1.0 / MAX_ITERATION) * 0.5 * 100));
            }
        }
        if (clientTaskStatusSupport != null) {
            // half way through evaluation of a parameter.
            clientTaskStatusSupport.setProgress(50);
        }
        // decrease
        iterationCount = 1;
        paramLogVal = Math.log10(fixedParam.getInitialGuess());
        ;
        ;
        lastError = iniError;
        isBoundReached = false;
        double decrementStep = incrementStep;
        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() + epsilon)) {
                paramVal = fixedParam.getLowerBound() + epsilon;
                paramLogVal = Math.log10(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
            optContext.setFixedParameter(fixedParam, paramVal);
            Parameter[] newParameters = getBestParameters(optContext, unFixedParams, decreasedParam);
            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 = leastError;
            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 = CONFIDENCE_INTERVAL_STEP * Math.pow(2, stepIncreaseCount);
            } else {
                if (stepIncreaseCount > 1) {
                    incrementStep = CONFIDENCE_INTERVAL_STEP / Math.pow(2, stepIncreaseCount);
                    stepIncreaseCount--;
                }
            }
            if (clientTaskStatusSupport != null && clientTaskStatusSupport.isInterrupted()) {
                throw UserCancelException.CANCEL_GENERIC;
            }
            lastError = error;
            iterationCount++;
            if (clientTaskStatusSupport != null) {
                clientTaskStatusSupport.setProgress((int) (((iterationCount + MAX_ITERATION) * 1.0 / MAX_ITERATION) * 0.5 * 100));
            }
        }
        resultData[j] = profileData;
        if (clientTaskStatusSupport != null) {
            // finish evaluation of a parameter
            clientTaskStatusSupport.setProgress(100);
        }
    }
    optContext.clearFixedParameter();
    // 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.
    if (clientTaskStatusSupport != null) {
        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 29 with Parameter

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

the class PhotoactivationExperimentTest method analyzePhotoactivation.

/**
 * Fits raw image time series data to uniform disk models (with Guassian or Uniform fluorescence).
 *
 * @param rawTimeSeriesImages
 * @param localWorkspace
 * @throws Exception
 */
private static void analyzePhotoactivation(ImageTimeSeries<UShortImage> rawTimeSeriesImages, LocalWorkspace localWorkspace) throws Exception {
    // 
    // correct the timestamps (1 per second).
    // 
    double[] timeStamps = rawTimeSeriesImages.getImageTimeStamps();
    for (int i = 0; i < timeStamps.length; i++) {
        timeStamps[i] = i;
    }
    new DisplayTimeSeriesOp().displayImageTimeSeries(rawTimeSeriesImages, "raw images", (WindowListener) null);
    ImageTimeSeries<UShortImage> blurredRaw = blurTimeSeries(rawTimeSeriesImages);
    new DisplayTimeSeriesOp().displayImageTimeSeries(blurredRaw, "blurred raw images", (WindowListener) null);
    double cellThreshold = 0.4;
    GeometryRoisAndActivationTiming cellROIresults = new GenerateCellROIsFromRawPhotoactivationTimeSeriesOp().generate(blurredRaw, cellThreshold);
    ROI backgroundROI = cellROIresults.backgroundROI_2D;
    ROI cellROI = cellROIresults.cellROI_2D;
    int indexOfFirstPostactivation = cellROIresults.indexOfFirstPostactivation;
    boolean backgroundSubtract = false;
    boolean normalizeByPreActivation = false;
    NormalizedPhotoactivationDataResults normResults = new GenerateNormalizedPhotoactivationDataOp().generate(rawTimeSeriesImages, backgroundROI, indexOfFirstPostactivation, backgroundSubtract, normalizeByPreActivation);
    ImageTimeSeries<FloatImage> normalizedTimeSeries = normResults.normalizedPhotoactivationData;
    FloatImage preactivationAvg = normResults.preactivationAverageImage;
    FloatImage normalizedPostactivation = normalizedTimeSeries.getAllImages()[0];
    new DisplayTimeSeriesOp().displayImageTimeSeries(normalizedTimeSeries, "normalized images", (WindowListener) null);
    // 
    // create a single bleach ROI by thresholding
    // 
    double activatedThreshold = 1000;
    ROI activatedROI = new GenerateActivationRoiOp().generateActivatedRoi(blurredRaw.getAllImages()[indexOfFirstPostactivation], cellROI, activatedThreshold);
    new DisplayImageOp().displayImage(activatedROI.getRoiImages()[0], "activated roi", null);
    new DisplayImageOp().displayImage(cellROI.getRoiImages()[0], "cell roi", null);
    new DisplayImageOp().displayImage(backgroundROI.getRoiImages()[0], "background roi", null);
    {
        // 
        // only use bleach ROI for fitting etc.
        // 
        NormalizedSampleFunction[] dataROIs = new NormalizedSampleFunction[] { NormalizedSampleFunction.fromROI(activatedROI) };
        // 
        // get reduced data and errors for each ROI
        // 
        RowColumnResultSet reducedData = new GenerateReducedDataOp().generateReducedData(normalizedTimeSeries, dataROIs);
        RowColumnResultSet measurementErrors = new ComputeMeasurementErrorOp().computeNormalizedMeasurementError(dataROIs, indexOfFirstPostactivation, rawTimeSeriesImages, preactivationAvg, null);
        DisplayPlotOp displayReducedData = new DisplayPlotOp();
        displayReducedData.displayPlot(reducedData, "reduced data", null);
        DisplayPlotOp displayMeasurementError = new DisplayPlotOp();
        displayMeasurementError.displayPlot(measurementErrors, "measurement error", null);
        // 
        // 2 parameter uniform disk model
        // 
        Parameter tau = new Parameter("tau", 0.001, 200.0, 1.0, 0.1);
        Parameter f_init = new Parameter("f_init", 0.5, 4000, 1.0, 1.0);
        Parameter f_final = new Parameter("f_final", 0.01, 4000, 1.0, 0.5);
        Parameter[] parameters = new Parameter[] { tau, f_init, f_final };
        OptModel optModel = new OptModel("photoactivation (activated roi)", parameters) {

            @Override
            public double[][] getSolution0(double[] newParams, double[] solutionTimePoints) {
                double tau = newParams[0];
                double max = newParams[1];
                double offset = newParams[2];
                double[][] solution = new double[1][solutionTimePoints.length];
                for (int i = 0; i < solution[0].length; i++) {
                    double t = solutionTimePoints[i];
                    solution[0][i] = offset + (max - offset) * Math.exp(-t / tau);
                }
                return solution;
            }

            @Override
            public double getPenalty(double[] parameters2) {
                return 0;
            }
        };
        ErrorFunction errorFunction = new ErrorFunctionNoiseWeightedL2();
        OptContext uniformDisk2Context = new Generate2DOptContextOp().generate2DOptContext(optModel, reducedData, measurementErrors, errorFunction);
        new DisplayInteractiveModelOp().displayOptModel(uniformDisk2Context, dataROIs, localWorkspace, "nonspatial photoactivation - activated ROI only", null);
    }
    {
        // 
        // only activation ROI for chemistry, cellROI for bleaching
        // 
        NormalizedSampleFunction[] dataROIs = new NormalizedSampleFunction[] { NormalizedSampleFunction.fromROI(activatedROI), NormalizedSampleFunction.fromROI(cellROI) };
        // 
        // get reduced data and errors for each ROI
        // 
        RowColumnResultSet reducedData = new GenerateReducedDataOp().generateReducedData(normalizedTimeSeries, dataROIs);
        RowColumnResultSet measurementErrors = new ComputeMeasurementErrorOp().computeNormalizedMeasurementError(dataROIs, indexOfFirstPostactivation, rawTimeSeriesImages, preactivationAvg, null);
        DisplayPlotOp displayReducedData = new DisplayPlotOp();
        displayReducedData.displayPlot(reducedData, "reduced data (2)", null);
        DisplayPlotOp displayMeasurementError = new DisplayPlotOp();
        displayMeasurementError.displayPlot(measurementErrors, "measurement error (2)", null);
        // 
        // 2 parameter uniform disk model
        // 
        Parameter tau_active = new Parameter("tau_active", 0.001, 200.0, 1.0, 0.1);
        Parameter f_active_init = new Parameter("f_active_init", 0.5, 4000, 1.0, 1.0);
        Parameter f_active_amplitude = new Parameter("f_active_amplitude", 0.01, 4000, 1.0, 0.5);
        Parameter f_cell_init = new Parameter("f_cell_init", 0.01, 4000, 1.0, 0.1);
        Parameter f_cell_amplitude = new Parameter("f_cell_amplitude", 0.01, 4000, 1.0, 0.1);
        Parameter tau_cell = new Parameter("tau_cell", 0.00001, 200, 1.0, 1);
        Parameter[] parameters = new Parameter[] { tau_active, f_active_init, f_active_amplitude, tau_cell, f_cell_init, f_cell_amplitude };
        OptModel optModel = new OptModel("photoactivation (activated and cell rois)", parameters) {

            @Override
            public double[][] getSolution0(double[] newParams, double[] solutionTimePoints) {
                double tau_active = newParams[0];
                double max_active = newParams[1];
                double amplitude_active = newParams[2];
                double tau_cell = newParams[3];
                double max_cell = newParams[4];
                double amplitude_cell = newParams[5];
                final int ACTIVE_ROI = 0;
                final int CELL_ROI = 1;
                final int NUM_ROIS = 2;
                double[][] solution = new double[NUM_ROIS][solutionTimePoints.length];
                for (int i = 0; i < solution[0].length; i++) {
                    double t = solutionTimePoints[i];
                    solution[ACTIVE_ROI][i] = (max_active - amplitude_active) + (amplitude_active) * Math.exp(-t / tau_active) * Math.exp(-t / tau_cell);
                    solution[CELL_ROI][i] = (max_cell - amplitude_cell) + (amplitude_cell) * Math.exp(-t / tau_cell);
                }
                return solution;
            }

            @Override
            public double getPenalty(double[] parameters2) {
                return 0;
            }
        };
        ErrorFunctionNoiseWeightedL2 errorFunction = new ErrorFunctionNoiseWeightedL2();
        OptContext uniformDisk2Context = new Generate2DOptContextOp().generate2DOptContext(optModel, reducedData, measurementErrors, errorFunction);
        new DisplayInteractiveModelOp().displayOptModel(uniformDisk2Context, dataROIs, localWorkspace, "nonspatial photoactivation - activated and cell ROIs", null);
    }
}
Also used : FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) GenerateCellROIsFromRawPhotoactivationTimeSeriesOp(org.vcell.vmicro.op.GenerateCellROIsFromRawPhotoactivationTimeSeriesOp) ErrorFunctionNoiseWeightedL2(org.vcell.vmicro.workflow.data.ErrorFunctionNoiseWeightedL2) OptContext(org.vcell.vmicro.workflow.data.OptContext) OptModel(org.vcell.vmicro.workflow.data.OptModel) DisplayPlotOp(org.vcell.vmicro.op.display.DisplayPlotOp) NormalizedPhotoactivationDataResults(org.vcell.vmicro.op.GenerateNormalizedPhotoactivationDataOp.NormalizedPhotoactivationDataResults) DisplayImageOp(org.vcell.vmicro.op.display.DisplayImageOp) DisplayTimeSeriesOp(org.vcell.vmicro.op.display.DisplayTimeSeriesOp) GeometryRoisAndActivationTiming(org.vcell.vmicro.op.GenerateCellROIsFromRawPhotoactivationTimeSeriesOp.GeometryRoisAndActivationTiming) DisplayInteractiveModelOp(org.vcell.vmicro.op.display.DisplayInteractiveModelOp) GenerateActivationRoiOp(org.vcell.vmicro.op.GenerateActivationRoiOp) GenerateReducedDataOp(org.vcell.vmicro.op.GenerateReducedDataOp) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ErrorFunction(org.vcell.vmicro.workflow.data.ErrorFunction) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Generate2DOptContextOp(org.vcell.vmicro.op.Generate2DOptContextOp) ROI(cbit.vcell.VirtualMicroscopy.ROI) ComputeMeasurementErrorOp(org.vcell.vmicro.op.ComputeMeasurementErrorOp) Parameter(cbit.vcell.opt.Parameter) GenerateNormalizedPhotoactivationDataOp(org.vcell.vmicro.op.GenerateNormalizedPhotoactivationDataOp)

Example 30 with Parameter

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

the class BatchRunXmlReader method getBatchRunWorkspace.

/**
 * This method returns a Biomodel object from a XML Element.
 * Creation date: (3/13/2001 12:35:00 PM)
 * @param param org.jdom.Element
 * @return cbit.vcell.biomodel.BioModel
 * @throws XmlParseException
 */
public FRAPBatchRunWorkspace getBatchRunWorkspace(Element param) throws XmlParseException {
    FRAPBatchRunWorkspace tempBatchRunWorkspace = new FRAPBatchRunWorkspace();
    // Element param = root.getChild(MicroscopyXMLTags.FrapBatchRunTag);
    // selected model index
    Element selectedModexIndexElement = param.getChild(MicroscopyXMLTags.BatchRunSelectedModelTypeTag);
    String selectedModexIndexStr = selectedModexIndexElement.getText();
    int selectedModelIndex = (new Integer(selectedModexIndexStr).intValue());
    if (selectedModexIndexStr != null && selectedModexIndexStr.length() > 0) {
        tempBatchRunWorkspace.setSelectedModel(selectedModelIndex);
    }
    // get average model parameters when there is selected model
    Element averageParametersElement = param.getChild(MicroscopyXMLTags.ModelParametersTag);
    Parameter[] params = null;
    if (averageParametersElement != null && averageParametersElement.getAttributes().size() > 0) {
        if (selectedModelIndex == FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT) {
            params = new Parameter[FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF];
            double primaryDiffRate = Double.parseDouble(averageParametersElement.getAttributeValue(MicroscopyXMLTags.PrimaryRateAttrTag));
            params[FRAPModel.INDEX_PRIMARY_DIFF_RATE] = 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(), primaryDiffRate);
            double primaryFraction = Double.parseDouble(averageParametersElement.getAttributeValue(MicroscopyXMLTags.PrimaryFractionAttTag));
            params[FRAPModel.INDEX_PRIMARY_FRACTION] = 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(), primaryFraction);
            double bwmRate = Double.parseDouble(averageParametersElement.getAttributeValue(MicroscopyXMLTags.BleachWhileMonitoringTauAttrTag));
            params[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(), bwmRate);
        } else if (selectedModelIndex == FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS) {
            params = new Parameter[FRAPModel.NUM_MODEL_PARAMETERS_TWO_DIFF];
            double primaryDiffRate = Double.parseDouble(averageParametersElement.getAttributeValue(MicroscopyXMLTags.PrimaryRateAttrTag));
            params[FRAPModel.INDEX_PRIMARY_DIFF_RATE] = 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(), primaryDiffRate);
            double primaryFraction = Double.parseDouble(averageParametersElement.getAttributeValue(MicroscopyXMLTags.PrimaryFractionAttTag));
            params[FRAPModel.INDEX_PRIMARY_FRACTION] = 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(), primaryFraction);
            double bwmRate = Double.parseDouble(averageParametersElement.getAttributeValue(MicroscopyXMLTags.BleachWhileMonitoringTauAttrTag));
            params[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(), bwmRate);
            double secDiffRate = Double.parseDouble(averageParametersElement.getAttributeValue(MicroscopyXMLTags.SecondRateAttrTag));
            params[FRAPModel.INDEX_SECONDARY_DIFF_RATE] = 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(), secDiffRate);
            double secFraction = Double.parseDouble(averageParametersElement.getAttributeValue(MicroscopyXMLTags.SecondFractionAttTag));
            params[FRAPModel.INDEX_SECONDARY_FRACTION] = 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(), secFraction);
        } else if (selectedModelIndex == FRAPModel.IDX_MODEL_REACTION_OFF_RATE) {
            params = new Parameter[FRAPModel.NUM_MODEL_PARAMETERS_REACTION_OFF_RATE];
            double bwmRate = Double.parseDouble(averageParametersElement.getAttributeValue(MicroscopyXMLTags.BleachWhileMonitoringTauAttrTag));
            params[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(), bwmRate);
            double fittingParam = Double.parseDouble(averageParametersElement.getAttributeValue(MicroscopyXMLTags.BindingSiteConcentrationAttTag));
            params[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(), fittingParam);
            double offRate = Double.parseDouble(averageParametersElement.getAttributeValue(MicroscopyXMLTags.ReactionOffRateAttTag));
            params[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(), offRate);
            params[FRAPModel.INDEX_PRIMARY_DIFF_RATE] = null;
            params[FRAPModel.INDEX_PRIMARY_FRACTION] = null;
            params[FRAPModel.INDEX_SECONDARY_DIFF_RATE] = null;
            params[FRAPModel.INDEX_SECONDARY_FRACTION] = null;
            params[FRAPModel.INDEX_ON_RATE] = null;
        }
        tempBatchRunWorkspace.setAverageParameters(params);
    }
    // get FrapStudy file list
    Element frapStudyListElement = param.getChild(MicroscopyXMLTags.FrapStudyListTag);
    String numFrapStudiesStr = frapStudyListElement.getAttributeValue(MicroscopyXMLTags.NumFrapStudyListAttrTag);
    Integer.parseInt(numFrapStudiesStr);
    // get each individual FRAPStudy
    @SuppressWarnings("unchecked") List<Element> fileNameList = frapStudyListElement.getChildren(MicroscopyXMLTags.FrapFileNameTag);
    for (int i = 0; i < fileNameList.size(); i++) {
        String fileName = fileNameList.get(i).getText();
        // create empty frap study to put in temporay batchrunworkspace
        FRAPStudy fStudy = new FRAPStudy();
        fStudy.setXmlFilename(fileName);
        tempBatchRunWorkspace.addFrapStudy(fStudy);
    }
    return tempBatchRunWorkspace;
}
Also used : Element(org.jdom.Element) Parameter(cbit.vcell.opt.Parameter) FRAPStudy(cbit.vcell.microscopy.FRAPStudy)

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