use of uk.ac.sussex.gdsc.core.match.ClassificationResult in project GDSC-SMLM by aherbert.
the class Filter method scoreSubset.
/**
* Filter the results and return the performance score. Allows benchmarking the filter by marking
* the results as true or false.
*
* <p>Any input PeakResult with an original value that is not zero will be treated as a true
* result, all other results are false. The filter is run and the results are marked as true
* positive, false negative and false positive.
*
* <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)
* @return the score
*/
public ClassificationResult scoreSubset(List<MemoryPeakResults> resultsList, final int failures, int tn, int fn) {
final int[] s = new int[4];
s[TN] = tn;
s[FN] = fn;
for (final MemoryPeakResults peakResults : resultsList) {
setup(peakResults);
final FrameCounter counter = new FrameCounter();
peakResults.forEach((PeakResultProcedure) peak -> {
counter.advanceAndReset(peak.getFrame());
final boolean isTrue = peak.getOrigValue() != 0;
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 (isTrue) {
if (isPositive) {
s[TP]++;
} else {
s[FN]++;
}
} else if (isPositive) {
s[FP]++;
} else {
s[TN]++;
}
});
end();
}
return new ClassificationResult(s[TP], s[FP], s[TN], s[FN]);
}
use of uk.ac.sussex.gdsc.core.match.ClassificationResult in project GDSC-SMLM by aherbert.
the class Filter method score.
/**
* Filter the results and return the performance score. Allows benchmarking the filter by marking
* the results as true or false.
*
* <p>Any input PeakResult with an original value that is not zero will be treated as a true
* result, all other results are false. The filter is run and the results are marked as true
* positive, false negative and false positive.
*
* <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 resultsList a list of results to analyse
* @param failures the number of failures to allow per frame before all peaks are rejected
* @return the score
*/
public ClassificationResult score(List<MemoryPeakResults> resultsList, final int failures) {
final int[] s = new int[4];
for (final MemoryPeakResults peakResults : resultsList) {
setup(peakResults);
final FrameCounter counter = new FrameCounter();
peakResults.forEach((PeakResultProcedure) peak -> {
counter.advanceAndReset(peak.getFrame());
final boolean isTrue = peak.getOrigValue() != 0;
final boolean isPositive;
if (counter.getCount() > failures) {
isPositive = false;
} else {
isPositive = accept(peak);
}
if (isPositive) {
counter.reset();
} else {
counter.increment();
}
if (isTrue) {
if (isPositive) {
s[TP]++;
} else {
s[FN]++;
}
} else if (isPositive) {
s[FP]++;
} else {
s[TN]++;
}
});
end();
}
return new ClassificationResult(s[TP], s[FP], s[TN], s[FN]);
}
use of uk.ac.sussex.gdsc.core.match.ClassificationResult in project GDSC-SMLM by aherbert.
the class BenchmarkFilterAnalysis method scoreComponents.
private ComplexFilterScore scoreComponents(DirectFilter filter, int index, int size, int[] combinations, boolean[] enable, int[] uniqueIds1, int uniqueIdCount1) {
setupFractionScoreStore();
// Score them
long time = System.nanoTime();
final FilterScoreResult r = scoreFilter(filter);
time = System.nanoTime() - time;
endFractionScoreStore();
ClassificationResult r2 = null;
if (uniqueIds1 != null) {
// Build an overlap between the results created by this filter and the best filter.
// Note that the overlap may be very low given the number of different ways we can generate
// fit results (i.e. it is not as simple as just single-fitting on each candidate)
// To do this we assign a unique ID to each possible result.
// The two sets can be compared to produce a Precision, Recall, Jaccard, etc.
// PreprocessedPeakResult will need an additional mutable Id field.
// Sort by Id then iterate through both arrays concurrently counting the matching Ids.
final int[] uniqueIds2 = uniqueIds;
final int uniqueIdCount2 = uniqueIdCount;
int tp = 0;
int fp = 0;
int fn = 0;
// Compare Ids (must be sorted in ascending order)
int i1 = 0;
int i2 = 0;
while (i1 < uniqueIdCount1 && i2 < uniqueIdCount2) {
final int result = uniqueIds1[i1] - uniqueIds2[i2];
if (result > 0) {
i2++;
fp++;
} else if (result < 0) {
i1++;
fn++;
}
i1++;
i2++;
tp++;
}
// Count the remaining ids
fn += (uniqueIdCount1 - i1);
fp += (uniqueIdCount2 - i2);
r2 = new ClassificationResult(tp, fp, 0, fn);
}
// These scores are used when the same filter type so set allSameType to true
return new ComplexFilterScore(r, true, index, time, r2, size, combinations, enable);
}
use of uk.ac.sussex.gdsc.core.match.ClassificationResult in project GDSC-SMLM by aherbert.
the class Filter method score.
/**
* Filter the results and return the performance score. Allows benchmarking the filter by marking
* the results as true or false.
*
* <p>Any input PeakResult with an original value that is not zero will be treated as a true
* result, all other results are false. The filter is run and the results are marked as true
* positive, false negative and false positive.
*
* @param resultsList a list of results to analyse
* @return the score
*/
public ClassificationResult score(List<MemoryPeakResults> resultsList) {
final int[] s = new int[4];
for (final MemoryPeakResults peakResults : resultsList) {
setup(peakResults);
peakResults.forEach((PeakResultProcedure) peak -> {
final boolean isTrue = peak.getOrigValue() != 0;
final boolean isPositive = accept(peak);
if (isTrue) {
if (isPositive) {
s[TP]++;
} else {
s[FN]++;
}
} else if (isPositive) {
s[FP]++;
} else {
s[TN]++;
}
});
end();
}
return new ClassificationResult(s[TP], s[FP], s[TN], s[FN]);
}
Aggregations