use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class ClassificationMatchCalculator method run.
@Override
public void run(String arg) {
SmlmUsageTracker.recordPlugin(this.getClass(), arg);
if (MemoryPeakResults.isMemoryEmpty()) {
IJ.error(TITLE, "No localisations in memory");
return;
}
if (!showDialog()) {
return;
}
// Load the results
final MemoryPeakResults results1 = ResultsManager.loadInputResults(settings.inputOption1, false, null, null);
final MemoryPeakResults results2 = ResultsManager.loadInputResults(settings.inputOption2, false, null, null);
IJ.showStatus("");
if (results1 == null || results1.size() == 0) {
IJ.error(TITLE, "No results 1 could be loaded");
return;
}
if (results2 == null || results2.size() == 0) {
IJ.error(TITLE, "No results 2 could be loaded");
return;
}
// Check the results can be loaded in the pixels
try {
results1.getDistanceConverter(DistanceUnit.PIXEL);
results2.getDistanceConverter(DistanceUnit.PIXEL);
} catch (ConversionException | ConfigurationException ex) {
IJ.error(TITLE, "Distances cannot be loaded in pixels");
return;
}
final long start = System.nanoTime();
runCompareClassifications(results1, results2);
final long nanoseconds = System.nanoTime() - start;
IJ.showStatus(String.format("%s = %s", TITLE, TextUtils.nanosToString(nanoseconds)));
}
use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class ClassificationMatchCalculator method getCoordinates.
/**
* Build a map between the peak id (time point) and a list of coordinates that pass the filter.
*
* @param results the results
* @param test the test
* @return the coordinates
*/
public static TIntObjectHashMap<List<PeakResultPoint>> getCoordinates(MemoryPeakResults results, Predicate<PeakResult> test) {
final TIntObjectHashMap<List<PeakResultPoint>> coords = new TIntObjectHashMap<>();
if (results.size() > 0) {
// Do not use HashMap directly to build the coords object since there
// will be many calls to getEntry(). Instead sort the results and use
// a new list for each time point
results.sort();
// Create list
final LocalList<PeakResultPoint> tmpCoords = new LocalList<>();
// Add the results for each frame
final FrameCounter counter = results.newFrameCounter();
results.forEach(DistanceUnit.PIXEL, (XyzrResultProcedure) (x, y, z, r) -> {
if (counter.advance(r.getFrame()) && !tmpCoords.isEmpty()) {
coords.put(counter.previousFrame(), tmpCoords.copy());
tmpCoords.clear();
}
if (test.test(r)) {
tmpCoords.add(new PeakResultPoint(r.getFrame(), x, y, z, r));
}
});
if (!tmpCoords.isEmpty()) {
coords.put(counter.currentFrame(), tmpCoords.copy());
}
}
return coords;
}
use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class ConvertResults method run.
@Override
public void run(String arg) {
SmlmUsageTracker.recordPlugin(this.getClass(), arg);
if (!showInputDialog()) {
return;
}
final MemoryPeakResults results = ResultsManager.loadInputResults(inputOption, false, null, null);
if (MemoryPeakResults.isEmpty(results)) {
IJ.error(TITLE, "No results could be loaded");
return;
}
if (!showDialog(results)) {
return;
}
IJ.showStatus("Converted " + results.getName());
}
use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class Filter method filter.
/**
* Filter the results.
*
* <p>The number of consecutive rejections are counted per frame. When the configured number of
* failures is reached all remaining results for the frame are rejected. This assumes the results
* are ordered by the frame.
*
* @param results the results
* @param failures the number of failures to allow per frame before all peaks are rejected
* @return the filtered results
*/
public MemoryPeakResults filter(MemoryPeakResults results, final int failures) {
final MemoryPeakResults newResults = new MemoryPeakResults();
final FrameCounter counter = new FrameCounter();
newResults.copySettings(results);
setup(results);
results.forEach((PeakResultProcedure) peak -> {
counter.advanceAndReset(peak.getFrame());
final boolean isPositive;
if (counter.getCount() > failures) {
isPositive = false;
} else {
isPositive = accept(peak);
}
if (isPositive) {
counter.reset();
newResults.add(peak);
} else {
counter.increment();
}
});
end();
return newResults;
}
use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class Filter method fractionScoreSubset.
/**
* Filter the results and return the performance score. Allows benchmarking the filter by marking
* the results as true or false.
*
* <p>Input PeakResults must be allocated a score for true positive, false positive, true negative
* and false negative (accessed via the object property get methods). The filter is run and
* results that pass accumulate scores for true positive and false positive, otherwise the scores
* are accumulated for true negative and false negative. The simplest scoring scheme is to mark
* valid results as tp=fn=1 and fp=tn=0 and invalid results the opposite.
*
* <p>The number of consecutive rejections are counted per frame. When the configured number of
* failures is reached all remaining results for the frame are rejected. This assumes the results
* are ordered by the frame.
*
* <p>Note that this method is to be used to score a subset that was generated using
* {@link #filterSubset(MemoryPeakResults, int, double[])} since the number of consecutive
* failures before each peak are expected to be stored in the origX property.
*
* @param resultsList a list of results to analyse
* @param failures the number of failures to allow per frame before all peaks are rejected
* @param tn The initial true negatives (used when the results have been pre-filtered)
* @param fn The initial false negatives (used when the results have been pre-filtered)
* @param initialNegatives The initial negatives (used when the results have been pre-filtered)
* @return the score
*/
public FractionClassificationResult fractionScoreSubset(List<MemoryPeakResults> resultsList, final int failures, double tn, double fn, int initialNegatives) {
final double[] s = new double[4];
s[TN] = tn;
s[FN] = fn;
final Counter p = new Counter();
int negatives = initialNegatives;
for (final MemoryPeakResults peakResults : resultsList) {
setup(peakResults);
final FrameCounter counter = new FrameCounter();
peakResults.forEach((PeakResultProcedure) peak -> {
counter.advanceAndReset(peak.getFrame());
counter.increment(peak.getOrigX());
final boolean isPositive;
if (counter.getCount() > failures) {
isPositive = false;
} else {
isPositive = accept(peak);
}
if (isPositive) {
counter.reset();
} else {
counter.increment();
}
if (isPositive) {
p.increment();
s[TP] += peak.getTruePositiveScore();
s[FP] += peak.getFalsePositiveScore();
} else {
s[FN] += peak.getFalseNegativeScore();
s[TN] += peak.getTrueNegativeScore();
}
});
negatives += peakResults.size();
end();
}
negatives -= p.getCount();
return new FractionClassificationResult(s[TP], s[FP], s[TN], s[FN], p.getCount(), negatives);
}
Aggregations