use of org.vcell.util.DescriptiveStatistics in project vcell by virtualcell.
the class FRAPBatchRunWorkspace method refreshStatisticsData.
public void refreshStatisticsData() {
int studySize = getFrapStudies().size();
// get parameters array (column-name and column-details should be excluded)
// parameterVals[0] primaryDiffRates, parameterVals[1] primaryMobiles,parameterVals[2]bwmRates
// parameterVals[3] secDiffRates,parameterVals[4] secMobiles,parameterVals[5] bs_concentration
// parameterVals[6] reaction on rate, parameterVals[7] reacton off rate, parameterVals[8] immobile
double[][] parameterVals = new double[BatchRunResultsParamTableModel.NUM_COLUMNS - 2][studySize];
for (int i = 0; i < (BatchRunResultsParamTableModel.NUM_COLUMNS - 2); i++) {
// fill all elements with 1e8 first
Arrays.fill(parameterVals[i], FRAPOptimizationUtils.largeNumber);
}
for (int i = 0; i < studySize; i++) {
FRAPStudy fStudy = getFrapStudies().get(i);
if (selectedModel == FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT) {
FRAPModel fModel = fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT];
parameterVals[0][i] = fModel.getModelParameters()[FRAPModel.INDEX_PRIMARY_DIFF_RATE].getInitialGuess();
parameterVals[1][i] = fModel.getModelParameters()[FRAPModel.INDEX_PRIMARY_FRACTION].getInitialGuess();
parameterVals[2][i] = fModel.getModelParameters()[FRAPModel.INDEX_BLEACH_MONITOR_RATE].getInitialGuess();
// immobile fraction
parameterVals[8][i] = Math.max(0, (1 - parameterVals[1][i]));
} else if (selectedModel == FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS) {
FRAPModel fModel = fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS];
parameterVals[0][i] = fModel.getModelParameters()[FRAPModel.INDEX_PRIMARY_DIFF_RATE].getInitialGuess();
parameterVals[1][i] = fModel.getModelParameters()[FRAPModel.INDEX_PRIMARY_FRACTION].getInitialGuess();
parameterVals[2][i] = fModel.getModelParameters()[FRAPModel.INDEX_BLEACH_MONITOR_RATE].getInitialGuess();
parameterVals[3][i] = fModel.getModelParameters()[FRAPModel.INDEX_SECONDARY_DIFF_RATE].getInitialGuess();
parameterVals[4][i] = fModel.getModelParameters()[FRAPModel.INDEX_SECONDARY_FRACTION].getInitialGuess();
// immobile fraction
parameterVals[8][i] = Math.max(0, (1 - parameterVals[1][i] - parameterVals[4][i]));
} else if (selectedModel == FRAPModel.IDX_MODEL_REACTION_OFF_RATE) {
FRAPModel fModel = fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE];
parameterVals[2][i] = fModel.getModelParameters()[FRAPModel.INDEX_BLEACH_MONITOR_RATE].getInitialGuess();
parameterVals[5][i] = fModel.getModelParameters()[FRAPModel.INDEX_BINDING_SITE_CONCENTRATION].getInitialGuess();
parameterVals[7][i] = fModel.getModelParameters()[FRAPModel.INDEX_OFF_RATE].getInitialGuess();
}
}
double[][] oldStatData = statisticsData;
// stores statistics for each parameters . (column-name and column-details should be excluded)
statisticsData = new double[BatchRunResultsStatTableModel.NUM_STATISTICS][BatchRunResultsParamTableModel.NUM_COLUMNS - 2];
for (int i = 0; i < BatchRunResultsStatTableModel.NUM_STATISTICS; i++) {
// fill all elements with 1e8 first
Arrays.fill(statisticsData[i], FRAPOptimizationUtils.largeNumber);
}
for (int i = 0; i < BatchRunResultsParamTableModel.NUM_COLUMNS - 2; i++) {
// statistics for parameters exist(which is not saved as 1e8)
if (parameterVals[i][0] != FRAPOptimizationUtils.largeNumber) {
DescriptiveStatistics stat = DescriptiveStatistics.CreateBasicStatistics(parameterVals[i]);
statisticsData[BatchRunResultsStatTableModel.ROW_IDX_AVERAGE][i] = stat.getMean();
statisticsData[BatchRunResultsStatTableModel.ROW_IDX_STD][i] = stat.getStandardDeviation();
statisticsData[BatchRunResultsStatTableModel.ROW_IDX_MEDIAN][i] = stat.getMedian();
statisticsData[BatchRunResultsStatTableModel.ROW_IDX_MIN][i] = stat.getMin();
statisticsData[BatchRunResultsStatTableModel.ROW_IDX_MAX][i] = stat.getMax();
}
}
updateAverageParameters();
firePropertyChange(PROPERTY_CHANGE_BATCHRUN_UPDATE_STATISTICS, oldStatData, statisticsData);
}
use of org.vcell.util.DescriptiveStatistics 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;
}
use of org.vcell.util.DescriptiveStatistics 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;
}
Aggregations