Search in sources :

Example 61 with PeakResult

use of gdsc.smlm.results.PeakResult 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);
}
Also used : MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) ClassificationResult(gdsc.core.match.ClassificationResult) FractionClassificationResult(gdsc.core.match.FractionClassificationResult) PeakResult(gdsc.smlm.results.PeakResult)

Example 62 with PeakResult

use of gdsc.smlm.results.PeakResult 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);
}
Also used : MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) ClassificationResult(gdsc.core.match.ClassificationResult) FractionClassificationResult(gdsc.core.match.FractionClassificationResult) PeakResult(gdsc.smlm.results.PeakResult)

Example 63 with PeakResult

use of gdsc.smlm.results.PeakResult 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;
}
Also used : MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) PeakResult(gdsc.smlm.results.PeakResult)

Example 64 with PeakResult

use of gdsc.smlm.results.PeakResult 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;
}
Also used : MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) PeakResult(gdsc.smlm.results.PeakResult)

Example 65 with PeakResult

use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.

the class Filter method fractionScore2.

/**
	 * 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 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 #fractionScore(List, int)}.
	 * 
	 * @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 FractionClassificationResult fractionScore2(List<MemoryPeakResults> resultsList, int failures) {
    int p = 0, n = 0;
    double fp = 0, fn = 0;
    double tp = 0, tn = 0;
    for (MemoryPeakResults peakResults : resultsList) {
        setup(peakResults);
        int frame = -1;
        int failCount = 0;
        for (PeakResult peak : peakResults.getResults()) {
            // Reset fail count for new frames
            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) {
                failCount = 0;
            } else {
                failCount++;
            }
            if (isPositive) {
                p++;
                tp += peak.getTruePositiveScore();
                fp += peak.getFalsePositiveScore();
            } else {
                fn += peak.getFalseNegativeScore();
                tn += peak.getTrueNegativeScore();
            }
        }
        n += peakResults.size();
        end();
    }
    n -= p;
    return new FractionClassificationResult(tp, fp, tn, fn, p, n);
}
Also used : FractionClassificationResult(gdsc.core.match.FractionClassificationResult) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) PeakResult(gdsc.smlm.results.PeakResult)

Aggregations

PeakResult (gdsc.smlm.results.PeakResult)89 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)40 ExtendedPeakResult (gdsc.smlm.results.ExtendedPeakResult)18 Rectangle (java.awt.Rectangle)18 ArrayList (java.util.ArrayList)17 IdPeakResult (gdsc.smlm.results.IdPeakResult)13 ImagePlus (ij.ImagePlus)9 Point (java.awt.Point)9 Trace (gdsc.smlm.results.Trace)8 ImageStack (ij.ImageStack)7 FractionClassificationResult (gdsc.core.match.FractionClassificationResult)6 Calibration (gdsc.smlm.results.Calibration)6 PreprocessedPeakResult (gdsc.smlm.results.filter.PreprocessedPeakResult)6 ExtendedGenericDialog (ij.gui.ExtendedGenericDialog)6 BasePoint (gdsc.core.match.BasePoint)5 Statistics (gdsc.core.utils.Statistics)5 StoredDataStatistics (gdsc.core.utils.StoredDataStatistics)5 IJImagePeakResults (gdsc.smlm.ij.results.IJImagePeakResults)5 GenericDialog (ij.gui.GenericDialog)5 ImageProcessor (ij.process.ImageProcessor)5