use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class Filter method filter.
/**
* Filter the results
*
* @param results
* @return the filtered results
*/
public MemoryPeakResults filter(MemoryPeakResults results) {
MemoryPeakResults newResults = new MemoryPeakResults();
newResults.copySettings(results);
setup(results);
for (PeakResult peak : results.getResults()) {
if (accept(peak))
newResults.add(peak);
}
end();
return newResults;
}
use of gdsc.smlm.results.MemoryPeakResults 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)} 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, int failures, int tn, int fn) {
int tp = 0, fp = 0;
for (MemoryPeakResults peakResults : resultsList) {
setup(peakResults);
int frame = -1;
int failCount = 0;
for (PeakResult peak : peakResults.getResults()) {
final boolean isTrue = peak.origValue != 0;
// Reset fail count for new frames
if (frame != peak.getFrame()) {
frame = peak.getFrame();
failCount = 0;
}
failCount += peak.origX;
// Reject all peaks if we have exceeded the fail count
final boolean isPositive;
if (failCount > failures) {
isPositive = false;
} else {
// Otherwise assess the peak
isPositive = accept(peak);
}
if (isPositive) {
failCount = 0;
} else {
failCount++;
}
if (isTrue) {
if (isPositive)
// true positive
tp++;
else
// false negative
fn++;
} else {
if (isPositive)
// false positive
fp++;
else
// true negative
tn++;
}
}
end();
}
return new ClassificationResult(tp, fp, tn, fn);
}
use of gdsc.smlm.results.MemoryPeakResults 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
* @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
*/
public ClassificationResult score(List<MemoryPeakResults> resultsList, int tn, int fn) {
int tp = 0, fp = 0;
for (MemoryPeakResults peakResults : resultsList) {
setup(peakResults);
for (PeakResult peak : peakResults.getResults()) {
final boolean isTrue = peak.origValue != 0;
boolean isPositive = accept(peak);
if (isTrue) {
if (isPositive)
// true positive
tp++;
else
// false negative
fn++;
} else {
if (isPositive)
// false positive
fp++;
else
// true negative
tn++;
}
}
end();
}
return new ClassificationResult(tp, fp, tn, fn);
}
use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class Filter method filterSubset.
/**
* Filter the results
* <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>
* The number of failures before each peak is stored in the origX property of the PeakResult.
*
* @param results
* @param failures
* the number of failures to allow per frame before all peaks are rejected
* @param score
* If not null will be populated with the fraction score [ tp, fp, tn, fn, p, n ]
* @return the filtered results
*/
public MemoryPeakResults filterSubset(MemoryPeakResults results, int failures, double[] score) {
MemoryPeakResults newResults = new MemoryPeakResults();
newResults.copySettings(results);
setup(results);
int frame = -1;
int failCount = 0;
double fp = 0, fn = 0;
double tp = 0, tn = 0;
for (PeakResult peak : results.getResults()) {
if (frame != peak.getFrame()) {
frame = peak.getFrame();
failCount = 0;
}
// Reject all peaks if we have exceeded the fail count
final boolean isPositive;
if (failCount > failures) {
isPositive = false;
} else {
// Otherwise assess the peak
isPositive = accept(peak);
}
if (isPositive) {
peak.origX = failCount;
failCount = 0;
newResults.add(peak);
} else {
failCount++;
}
if (isPositive) {
tp += peak.getTruePositiveScore();
fp += peak.getFalsePositiveScore();
} else {
fn += peak.getFalseNegativeScore();
tn += peak.getTrueNegativeScore();
}
}
end();
if (score != null && score.length > 5) {
score[0] = tp;
score[1] = fp;
score[2] = tn;
score[3] = fn;
score[4] = newResults.size();
score[5] = results.size() - newResults.size();
}
return newResults;
}
use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class Filter method filterSubset2.
/**
* Filter the results
* <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 set of results that may have been extracted from a larger set
* since the number of consecutive failures before each peak are expected to be stored in the origY property. Set
* this to zero and the results should be identical to {@link #filterSubset(MemoryPeakResults, int, double[])}.
* <p>
* The number of failures before each peak is stored in the origX property of the PeakResult.
*
* @param results
* @param failures
* the number of failures to allow per frame before all peaks are rejected
* @param score
* If not null will be populated with the fraction score [ tp, fp, tn, fn, p, n ]
* @return the filtered results
*/
public MemoryPeakResults filterSubset2(MemoryPeakResults results, int failures, double[] score) {
MemoryPeakResults newResults = new MemoryPeakResults();
newResults.copySettings(results);
setup(results);
int frame = -1;
int failCount = 0;
double fp = 0, fn = 0;
double tp = 0, tn = 0;
for (PeakResult peak : results.getResults()) {
if (frame != peak.getFrame()) {
frame = peak.getFrame();
failCount = 0;
}
failCount += peak.origY;
// Reject all peaks if we have exceeded the fail count
final boolean isPositive;
if (failCount > failures) {
isPositive = false;
} else {
// Otherwise assess the peak
isPositive = accept(peak);
}
if (isPositive) {
peak.origX = failCount;
failCount = 0;
newResults.add(peak);
} else {
failCount++;
}
if (isPositive) {
tp += peak.getTruePositiveScore();
fp += peak.getFalsePositiveScore();
} else {
fn += peak.getFalseNegativeScore();
tn += peak.getTrueNegativeScore();
}
}
end();
if (score != null && score.length > 5) {
score[0] = tp;
score[1] = fp;
score[2] = tn;
score[3] = fn;
score[4] = newResults.size();
score[5] = results.size() - newResults.size();
}
return newResults;
}
Aggregations