Search in sources :

Example 61 with PeakResult

use of uk.ac.sussex.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 the 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, final int failures, double[] score) {
    final MemoryPeakResults newResults = new MemoryPeakResults();
    final FrameCounter counter = new FrameCounter();
    newResults.copySettings(results);
    setup(results);
    final double[] s = new double[4];
    results.forEach((PeakResultProcedure) peak -> {
        counter.advanceAndReset(peak.getFrame());
        final boolean isPositive;
        if (counter.getCount() > failures) {
            isPositive = false;
        } else {
            isPositive = accept(peak);
        }
        if (isPositive) {
            peak.setOrigX(counter.getCount());
            counter.reset();
            newResults.add(peak);
        } else {
            counter.increment();
        }
        if (isPositive) {
            s[TP] += peak.getTruePositiveScore();
            s[FP] += peak.getFalsePositiveScore();
        } else {
            s[FN] += peak.getFalseNegativeScore();
            s[TN] += peak.getTrueNegativeScore();
        }
    });
    end();
    if (score != null && score.length > 5) {
        score[0] = s[TP];
        score[1] = s[FP];
        score[2] = s[TN];
        score[3] = s[FN];
        score[4] = newResults.size();
        score[5] = (double) results.size() - newResults.size();
    }
    return newResults;
}
Also used : Chromosome(uk.ac.sussex.gdsc.smlm.ga.Chromosome) List(java.util.List) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) FrameCounter(uk.ac.sussex.gdsc.smlm.results.count.FrameCounter) Nullable(uk.ac.sussex.gdsc.core.annotation.Nullable) ClassificationResult(uk.ac.sussex.gdsc.core.match.ClassificationResult) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) XStreamOmitField(com.thoughtworks.xstream.annotations.XStreamOmitField) FractionClassificationResult(uk.ac.sussex.gdsc.core.match.FractionClassificationResult) FrameCounter(uk.ac.sussex.gdsc.smlm.results.count.FrameCounter) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)

Example 62 with PeakResult

use of uk.ac.sussex.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
 * @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]);
}
Also used : Chromosome(uk.ac.sussex.gdsc.smlm.ga.Chromosome) List(java.util.List) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) FrameCounter(uk.ac.sussex.gdsc.smlm.results.count.FrameCounter) Nullable(uk.ac.sussex.gdsc.core.annotation.Nullable) ClassificationResult(uk.ac.sussex.gdsc.core.match.ClassificationResult) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) XStreamOmitField(com.thoughtworks.xstream.annotations.XStreamOmitField) FractionClassificationResult(uk.ac.sussex.gdsc.core.match.FractionClassificationResult) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) ClassificationResult(uk.ac.sussex.gdsc.core.match.ClassificationResult) FractionClassificationResult(uk.ac.sussex.gdsc.core.match.FractionClassificationResult)

Example 63 with PeakResult

use of uk.ac.sussex.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 the 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, final int failures, double[] score) {
    final MemoryPeakResults newResults = new MemoryPeakResults();
    final FrameCounter counter = new FrameCounter();
    newResults.copySettings(results);
    setup(results);
    final double[] s = new double[4];
    results.forEach((PeakResultProcedure) peak -> {
        counter.advanceAndReset(peak.getFrame());
        counter.increment(peak.getOrigY());
        final boolean isPositive;
        if (counter.getCount() > failures) {
            isPositive = false;
        } else {
            isPositive = accept(peak);
        }
        if (isPositive) {
            peak.setOrigX(counter.getCount());
            counter.reset();
            newResults.add(peak);
        } else {
            counter.increment();
        }
        if (isPositive) {
            s[TP] += peak.getTruePositiveScore();
            s[FP] += peak.getFalsePositiveScore();
        } else {
            s[FN] += peak.getFalseNegativeScore();
            s[TN] += peak.getTrueNegativeScore();
        }
    });
    end();
    if (score != null && score.length > 5) {
        score[0] = s[TP];
        score[1] = s[FP];
        score[2] = s[TN];
        score[3] = s[FN];
        score[4] = newResults.size();
        score[5] = (double) results.size() - newResults.size();
    }
    return newResults;
}
Also used : Chromosome(uk.ac.sussex.gdsc.smlm.ga.Chromosome) List(java.util.List) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) FrameCounter(uk.ac.sussex.gdsc.smlm.results.count.FrameCounter) Nullable(uk.ac.sussex.gdsc.core.annotation.Nullable) ClassificationResult(uk.ac.sussex.gdsc.core.match.ClassificationResult) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) XStreamOmitField(com.thoughtworks.xstream.annotations.XStreamOmitField) FractionClassificationResult(uk.ac.sussex.gdsc.core.match.FractionClassificationResult) FrameCounter(uk.ac.sussex.gdsc.smlm.results.count.FrameCounter) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)

Example 64 with PeakResult

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

the class ImageJImagePeakResultsTest method addPeakResults.

private static void addPeakResults(ImageJImagePeakResults results, int[] time, float[] x, float[] y, float[] value) {
    final LocalList<PeakResult> list = new LocalList<>(x.length);
    for (int i = 0; i < x.length; i++) {
        list.add(new PeakResult(time[i], 0, 0, 0, 0, 0, 0, createParams(x[i], y[i], value[i]), null));
    }
    results.addAll(list);
}
Also used : LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult)

Aggregations

PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)64 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)37 List (java.util.List)18 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)18 Rectangle (java.awt.Rectangle)17 Counter (uk.ac.sussex.gdsc.smlm.results.count.Counter)17 FrameCounter (uk.ac.sussex.gdsc.smlm.results.count.FrameCounter)17 PeakResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure)17 ImagePlus (ij.ImagePlus)14 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)14 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)14 IJ (ij.IJ)13 ImageJUtils (uk.ac.sussex.gdsc.core.ij.ImageJUtils)12 PlugIn (ij.plugin.PlugIn)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 SimpleArrayUtils (uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils)10 SettingsManager (uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager)10 PointRoi (ij.gui.PointRoi)9 ArrayList (java.util.ArrayList)9 TypeConverter (uk.ac.sussex.gdsc.core.data.utils.TypeConverter)9