use of org.apache.commons.math3.random.HaltonSequenceGenerator in project GDSC-SMLM by aherbert.
the class DensityImage method computeRipleysPlot.
/**
* Compute the Ripley's L-function for user selected radii and show it on a plot.
*
* @param results
*/
private void computeRipleysPlot(MemoryPeakResults results) {
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addMessage("Compute Ripley's L(r) - r plot");
gd.addNumericField("Min_radius", minR, 2);
gd.addNumericField("Max_radius", maxR, 2);
gd.addNumericField("Increment", incrementR, 2);
gd.addCheckbox("Confidence_intervals", confidenceIntervals);
gd.showDialog();
if (gd.wasCanceled())
return;
minR = gd.getNextNumber();
maxR = gd.getNextNumber();
incrementR = gd.getNextNumber();
confidenceIntervals = gd.getNextBoolean();
if (minR > maxR || incrementR < 0 || gd.invalidNumber()) {
IJ.error(TITLE, "Invalid radius parameters");
return;
}
DensityManager dm = createDensityManager(results);
double[][] values = calculateLScores(dm);
// 99% confidence intervals
final int iterations = (confidenceIntervals) ? 99 : 0;
double[] upper = null;
double[] lower = null;
Rectangle bounds = results.getBounds();
// Use a uniform distribution for the coordinates
HaltonSequenceGenerator dist = new HaltonSequenceGenerator(2);
dist.skipTo(new Well19937c(System.currentTimeMillis() + System.identityHashCode(this)).nextInt());
for (int i = 0; i < iterations; i++) {
IJ.showProgress(i, iterations);
IJ.showStatus(String.format("L-score confidence interval %d / %d", i + 1, iterations));
// Randomise coordinates
float[] x = new float[results.size()];
float[] y = new float[x.length];
for (int j = x.length; j-- > 0; ) {
final double[] d = dist.nextVector();
x[j] = (float) (d[0] * bounds.width);
y[j] = (float) (d[1] * bounds.height);
}
double[][] values2 = calculateLScores(new DensityManager(x, y, bounds));
if (upper == null) {
upper = values2[1];
lower = new double[upper.length];
System.arraycopy(upper, 0, lower, 0, upper.length);
} else {
for (int m = upper.length; m-- > 0; ) {
if (upper[m] < values2[1][m])
upper[m] = values2[1][m];
if (lower[m] > values2[1][m])
lower[m] = values2[1][m];
}
}
}
String title = results.getName() + " Ripley's (L(r) - r) / r";
Plot2 plot = new Plot2(title, "Radius", "(L(r) - r) / r", values[0], values[1]);
// Get the limits
double yMin = min(0, values[1]);
double yMax = max(0, values[1]);
if (iterations > 0) {
yMin = min(yMin, lower);
yMax = max(yMax, upper);
}
plot.setLimits(0, values[0][values[0].length - 1], yMin, yMax);
if (iterations > 0) {
plot.setColor(Color.BLUE);
plot.addPoints(values[0], upper, 1);
plot.setColor(Color.RED);
plot.addPoints(values[0], lower, 1);
plot.setColor(Color.BLACK);
}
Utils.display(title, plot);
}
Aggregations