Search in sources :

Example 6 with ClassificationResult

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]);
}
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) ClassificationResult(uk.ac.sussex.gdsc.core.match.ClassificationResult) FractionClassificationResult(uk.ac.sussex.gdsc.core.match.FractionClassificationResult)

Example 7 with ClassificationResult

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]);
}
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) ClassificationResult(uk.ac.sussex.gdsc.core.match.ClassificationResult) FractionClassificationResult(uk.ac.sussex.gdsc.core.match.FractionClassificationResult)

Example 8 with ClassificationResult

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);
}
Also used : FractionClassificationResult(uk.ac.sussex.gdsc.core.match.FractionClassificationResult) ClassificationResult(uk.ac.sussex.gdsc.core.match.ClassificationResult)

Example 9 with ClassificationResult

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]);
}
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)

Aggregations

ClassificationResult (uk.ac.sussex.gdsc.core.match.ClassificationResult)9 FractionClassificationResult (uk.ac.sussex.gdsc.core.match.FractionClassificationResult)5 XStreamOmitField (com.thoughtworks.xstream.annotations.XStreamOmitField)3 List (java.util.List)3 Nullable (uk.ac.sussex.gdsc.core.annotation.Nullable)3 SimpleArrayUtils (uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils)3 Chromosome (uk.ac.sussex.gdsc.smlm.ga.Chromosome)3 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)3 PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)3 Counter (uk.ac.sussex.gdsc.smlm.results.count.Counter)3 FrameCounter (uk.ac.sussex.gdsc.smlm.results.count.FrameCounter)3 PeakResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure)3 AndFilter (uk.ac.sussex.gdsc.smlm.results.filter.AndFilter)2 Filter (uk.ac.sussex.gdsc.smlm.results.filter.Filter)2 OrFilter (uk.ac.sussex.gdsc.smlm.results.filter.OrFilter)2 PrecisionFilter (uk.ac.sussex.gdsc.smlm.results.filter.PrecisionFilter)2 PrecisionHysteresisFilter (uk.ac.sussex.gdsc.smlm.results.filter.PrecisionHysteresisFilter)2 SnrFilter (uk.ac.sussex.gdsc.smlm.results.filter.SnrFilter)2 SnrHysteresisFilter (uk.ac.sussex.gdsc.smlm.results.filter.SnrHysteresisFilter)2 TraceFilter (uk.ac.sussex.gdsc.smlm.results.filter.TraceFilter)2