use of org.vcell.optimization.ProfileData in project vcell by virtualcell.
the class FRAPDiffTwoParamPanel method showParameterEvaluation.
public void showParameterEvaluation() {
AsynchClientTask evaluateTask = new AsynchClientTask("Prepare to evaluate parameters ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
String errorStr = checkParameters();
if (!errorStr.equals("")) {
throw new IllegalArgumentException(errorStr);
}
}
};
AsynchClientTask showResultTask = new AsynchClientTask("Showing profile likelihood and confidence intervals ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
ProfileData[] profileData = frapOptData.getExpFrapStudy().getProfileData_twoDiffComponents();
if (profileData != null && profileData.length > 0) {
JPanel basePanel = new JPanel();
// put plotpanes of different parameters' profile likelihoods into a base panel
basePanel.setLayout(new BoxLayout(basePanel, BoxLayout.Y_AXIS));
for (int i = 0; i < profileData.length; i++) {
ConfidenceIntervalPlotPanel plotPanel = new ConfidenceIntervalPlotPanel();
plotPanel.setProfileSummaryData(FRAPOptimizationUtils.getSummaryFromProfileData(profileData[i]));
plotPanel.setBorder(new EtchedBorder());
String paramName = "";
if (profileData[i].getProfileDataElements().size() > 0) {
paramName = profileData[i].getProfileDataElements().get(0).getParamName();
}
ProfileDataPanel profileDataPanel = new ProfileDataPanel(plotPanel, paramName);
basePanel.add(profileDataPanel);
}
JScrollPane scrollPane = new JScrollPane(basePanel);
scrollPane.setAutoscrolls(true);
scrollPane.setPreferredSize(new Dimension(620, 600));
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
// show plots in a dialog
DialogUtils.showComponentCloseDialog(FRAPDiffTwoParamPanel.this, scrollPane, "Profile Likelihood of Parameters");
}
}
};
// dispatch
ClientTaskDispatcher.dispatch(FRAPDiffTwoParamPanel.this, new Hashtable<String, Object>(), new AsynchClientTask[] { evaluateTask, showResultTask }, false, true, null, true);
}
use of org.vcell.optimization.ProfileData in project vcell by virtualcell.
the class FRAPReacOffRateParametersPanel method showParameterEvaluation.
public void showParameterEvaluation() {
AsynchClientTask evaluateTask = new AsynchClientTask("Prepare to evaluate parameters ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
String errorStr = checkParameters();
if (!errorStr.equals("")) {
throw new IllegalArgumentException(errorStr);
}
}
};
AsynchClientTask showResultTask = new AsynchClientTask("Showing profile likelihood and confidence intervals ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
ProfileData[] profileData = frapWorkspace.getWorkingFrapStudy().getProfileData_reactionOffRate();
if (profileData != null && profileData.length > 0) {
// put plotpanes of different parameters' profile likelihoods into a base panel
JPanel basePanel = new JPanel();
basePanel.setLayout(new BoxLayout(basePanel, BoxLayout.Y_AXIS));
for (int i = 0; i < profileData.length; i++) {
ConfidenceIntervalPlotPanel plotPanel = new ConfidenceIntervalPlotPanel();
plotPanel.setProfileSummaryData(FRAPOptimizationUtils.getSummaryFromProfileData(profileData[i]));
plotPanel.setBorder(new EtchedBorder());
String paramName = "";
if (profileData[i].getProfileDataElements().size() > 0) {
paramName = profileData[i].getProfileDataElements().get(0).getParamName();
}
ProfileDataPanel profileDataPanel = new ProfileDataPanel(plotPanel, paramName);
basePanel.add(profileDataPanel);
}
JScrollPane scrollPane = new JScrollPane(basePanel);
scrollPane.setAutoscrolls(true);
scrollPane.setPreferredSize(new Dimension(620, 600));
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
// show plots in a dialog
DialogUtils.showComponentCloseDialog(FRAPReacOffRateParametersPanel.this, scrollPane, "Profile Likelihood of Parameters");
}
}
};
// dispatch
ClientTaskDispatcher.dispatch(FRAPReacOffRateParametersPanel.this, new Hashtable<String, Object>(), new AsynchClientTask[] { evaluateTask, showResultTask }, false, true, null, true);
}
use of org.vcell.optimization.ProfileData 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;
}
use of org.vcell.optimization.ProfileData in project vcell by virtualcell.
the class VFrapProcess method compute.
public static VFrapProcessResults compute(ImageTimeSeries rawTimeSeriesImages, double bleachThreshold, double cellThreshold, LocalWorkspace localWorkspace, ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
GenerateCellROIsFromRawFrapTimeSeriesOp generateCellROIs = new GenerateCellROIsFromRawFrapTimeSeriesOp();
GeometryRoisAndBleachTiming geometryAndTiming = generateCellROIs.generate(rawTimeSeriesImages, cellThreshold);
GenerateNormalizedFrapDataOp generateNormalizedFrapData = new GenerateNormalizedFrapDataOp();
NormalizedFrapDataResults normalizedFrapResults = generateNormalizedFrapData.generate(rawTimeSeriesImages, geometryAndTiming.backgroundROI_2D, geometryAndTiming.indexOfFirstPostbleach);
GenerateBleachRoiOp generateROIs = new GenerateBleachRoiOp();
ROI bleachROI = generateROIs.generateBleachRoi(normalizedFrapResults.normalizedFrapData.getAllImages()[0], geometryAndTiming.cellROI_2D, bleachThreshold);
GenerateDependentImageROIsOp generateDependentROIs = new GenerateDependentImageROIsOp();
ROI[] dataROIs = generateDependentROIs.generate(geometryAndTiming.cellROI_2D, bleachROI);
NormalizedSampleFunction[] roiSampleFunctions = new NormalizedSampleFunction[dataROIs.length];
for (int i = 0; i < dataROIs.length; i++) {
roiSampleFunctions[i] = NormalizedSampleFunction.fromROI(dataROIs[i]);
}
GenerateReducedDataOp generateReducedNormalizedData = new GenerateReducedDataOp();
RowColumnResultSet reducedData = generateReducedNormalizedData.generateReducedData(normalizedFrapResults.normalizedFrapData, roiSampleFunctions);
ComputeMeasurementErrorOp computeMeasurementError = new ComputeMeasurementErrorOp();
RowColumnResultSet measurementError = computeMeasurementError.computeNormalizedMeasurementError(roiSampleFunctions, geometryAndTiming.indexOfFirstPostbleach, rawTimeSeriesImages, normalizedFrapResults.prebleachAverage, clientTaskStatusSupport);
GenerateTrivial2DPsfOp psf_2D = new GenerateTrivial2DPsfOp();
UShortImage psf = psf_2D.generateTrivial2D_Psf();
// RunRefSimulationOp runRefSimulationFull = new RunRefSimulationOp();
// GenerateReducedROIDataOp generateReducedRefSimData = new GenerateReducedROIDataOp();
RunRefSimulationFastOp runRefSimulationFast = new RunRefSimulationFastOp();
RowColumnResultSet refData = runRefSimulationFast.runRefSimFast(geometryAndTiming.cellROI_2D, normalizedFrapResults.normalizedFrapData, dataROIs, psf, localWorkspace, clientTaskStatusSupport);
final double refDiffusionRate = 1.0;
double[] refSimTimePoints = refData.extractColumn(0);
int numRois = refData.getDataColumnCount() - 1;
int numRefSimTimes = refData.getRowCount();
double[][] refSimData = new double[numRois][numRefSimTimes];
for (int roi = 0; roi < numRois; roi++) {
double[] roiData = refData.extractColumn(roi + 1);
for (int t = 0; t < numRefSimTimes; t++) {
refSimData[roi][t] = roiData[t];
}
}
ErrorFunction errorFunction = new ErrorFunctionNoiseWeightedL2();
OptModelOneDiff optModelOneDiff = new OptModelOneDiff(refSimData, refSimTimePoints, refDiffusionRate);
Generate2DOptContextOp generate2DOptContextOne = new Generate2DOptContextOp();
OptContext optContextOneDiff = generate2DOptContextOne.generate2DOptContext(optModelOneDiff, reducedData, measurementError, errorFunction);
RunProfileLikelihoodGeneralOp runProfileLikelihoodOne = new RunProfileLikelihoodGeneralOp();
ProfileData[] profileDataOne = runProfileLikelihoodOne.runProfileLikihood(optContextOneDiff, clientTaskStatusSupport);
// OptModelTwoDiffWithoutPenalty optModelTwoDiffWithoutPenalty = new OptModelTwoDiffWithoutPenalty(refSimData, refSimTimePoints, refDiffusionRate);
// Generate2DOptContextOp generate2DOptContextTwoWithoutPenalty = new Generate2DOptContextOp();
// OptContext optContextTwoDiffWithoutPenalty = generate2DOptContextTwoWithoutPenalty.generate2DOptContext(optModelTwoDiffWithoutPenalty, reducedData, measurementError);
// RunProfileLikelihoodGeneralOp runProfileLikelihoodTwoWithoutPenalty = new RunProfileLikelihoodGeneralOp();
// ProfileData[] profileDataTwoWithoutPenalty = runProfileLikelihoodTwoWithoutPenalty.runProfileLikihood(optContextTwoDiffWithoutPenalty, clientTaskStatusSupport);
OptModelTwoDiffWithPenalty optModelTwoDiffWithPenalty = new OptModelTwoDiffWithPenalty(refSimData, refSimTimePoints, refDiffusionRate);
Generate2DOptContextOp generate2DOptContextTwoWithPenalty = new Generate2DOptContextOp();
OptContext optContextTwoDiffWithPenalty = generate2DOptContextTwoWithPenalty.generate2DOptContext(optModelTwoDiffWithPenalty, reducedData, measurementError, errorFunction);
RunProfileLikelihoodGeneralOp runProfileLikelihoodTwoWithPenalty = new RunProfileLikelihoodGeneralOp();
ProfileData[] profileDataTwoWithPenalty = runProfileLikelihoodTwoWithPenalty.runProfileLikihood(optContextTwoDiffWithPenalty, clientTaskStatusSupport);
//
// SLOW WAY
//
// runRefSimulationFull.cellROI_2D,generateCellROIs.cellROI_2D);
// runRefSimulationFull.normalizedTimeSeries,generateNormalizedFrapData.normalizedFrapData);
// workflow.addTask(runRefSimulationFull);
// generateReducedRefSimData.imageTimeSeries,runRefSimulationFull.refSimTimeSeries);
// generateReducedRefSimData.imageDataROIs,generateDependentROIs.imageDataROIs);
// workflow.addTask(generateReducedRefSimData);
// DataHolder<RowColumnResultSet> reducedROIData = generateReducedRefSimData.reducedROIData;
// DataHolder<Double> refSimDiffusionRate = runRefSimulationFull.refSimDiffusionRate;
VFrapProcessResults results = new VFrapProcessResults(dataROIs, geometryAndTiming.cellROI_2D, bleachROI, normalizedFrapResults.normalizedFrapData, reducedData, profileDataOne, profileDataTwoWithPenalty);
return results;
}
use of org.vcell.optimization.ProfileData in project vcell by virtualcell.
the class WorkflowObjectsPanel method displayData.
private void displayData(TaskContext taskContext, WorkflowObject workflowObject) {
if (workflowObject instanceof DataInput || workflowObject instanceof DataOutput) {
String title = parametersFunctionsTableModel.getName(workflowObject);
WindowListener listener = new WindowAdapter() {
};
Object data = null;
if (workflowObject instanceof WorkflowDataSource) {
WorkflowDataSource dataHolder = (WorkflowDataSource) workflowObject;
data = taskContext.getRepository().getData(dataHolder);
} else if (workflowObject instanceof DataInput) {
DataInput dataInput = (DataInput) workflowObject;
data = taskContext.getData(dataInput);
}
if (data instanceof RowColumnResultSet) {
RowColumnResultSet rc = (RowColumnResultSet) data;
try {
new DisplayPlotOp().displayPlot(rc, title, listener);
} catch (ExpressionException e) {
e.printStackTrace();
}
} else if (data instanceof ROI) {
ROI roi = (ROI) data;
Image image = roi.getRoiImages()[0];
new DisplayImageOp().displayImage(image, title, listener);
} else if (data instanceof ProfileData[]) {
ProfileData[] profileData = (ProfileData[]) data;
new DisplayProfileLikelihoodPlotsOp().displayProfileLikelihoodPlots(profileData, title, listener);
} else if (data instanceof Image) {
Image image = (Image) data;
new DisplayImageOp().displayImage(image, title, listener);
} else if (data instanceof ImageTimeSeries) {
ImageTimeSeries imageTimeSeries = (ImageTimeSeries) data;
try {
DisplayTimeSeries.displayImageTimeSeries(imageTimeSeries, title, listener);
} catch (ImageException | IOException e) {
e.printStackTrace();
}
}
}
}
Aggregations