Search in sources :

Example 1 with FractionClassificationResult

use of gdsc.core.match.FractionClassificationResult in project GDSC-SMLM by aherbert.

the class BenchmarkFilterAnalysis method calculateSensitivity.

private void calculateSensitivity() {
    if (!calculateSensitivity)
        return;
    if (!bestFilter.isEmpty()) {
        IJ.showStatus("Calculating sensitivity ...");
        createSensitivityWindow();
        int currentIndex = 0;
        for (String type : bestFilterOrder) {
            IJ.showProgress(currentIndex++, bestFilter.size());
            DirectFilter filter = bestFilter.get(type).getFilter();
            FractionClassificationResult s = scoreFilter(filter, minimalFilter, resultsList, coordinateStore);
            s = getOriginalScore(s);
            String message = type + "\t\t\t" + Utils.rounded(s.getJaccard(), 4) + "\t\t" + Utils.rounded(s.getPrecision(), 4) + "\t\t" + Utils.rounded(s.getRecall(), 4);
            if (isHeadless) {
                IJ.log(message);
            } else {
                sensitivityWindow.append(message);
            }
            // List all the parameters that can be adjusted.
            final int parameters = filter.getNumberOfParameters();
            for (int index = 0; index < parameters; index++) {
                // For each parameter compute as upward + downward delta and get the average gradient
                DirectFilter higher = (DirectFilter) filter.adjustParameter(index, delta);
                DirectFilter lower = (DirectFilter) filter.adjustParameter(index, -delta);
                FractionClassificationResult sHigher = scoreFilter(higher, minimalFilter, resultsList, coordinateStore);
                sHigher = getOriginalScore(sHigher);
                FractionClassificationResult sLower = scoreFilter(lower, minimalFilter, resultsList, coordinateStore);
                sLower = getOriginalScore(sLower);
                StringBuilder sb = new StringBuilder();
                sb.append("\t").append(filter.getParameterName(index)).append("\t");
                sb.append(Utils.rounded(filter.getParameterValue(index), 4)).append("\t");
                double dx1 = higher.getParameterValue(index) - filter.getParameterValue(index);
                double dx2 = filter.getParameterValue(index) - lower.getParameterValue(index);
                addSensitivityScore(sb, s.getJaccard(), sHigher.getJaccard(), sLower.getJaccard(), dx1, dx2);
                addSensitivityScore(sb, s.getPrecision(), sHigher.getPrecision(), sLower.getPrecision(), dx1, dx2);
                addSensitivityScore(sb, s.getRecall(), sHigher.getRecall(), sLower.getRecall(), dx1, dx2);
                if (isHeadless) {
                    IJ.log(sb.toString());
                } else {
                    sensitivityWindow.append(sb.toString());
                }
            }
        }
        String message = "-=-=-=-";
        if (isHeadless) {
            IJ.log(message);
        } else {
            sensitivityWindow.append(message);
        }
        IJ.showProgress(1);
        IJ.showStatus("");
    }
}
Also used : IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter) FractionClassificationResult(gdsc.core.match.FractionClassificationResult)

Example 2 with FractionClassificationResult

use of gdsc.core.match.FractionClassificationResult in project GDSC-SMLM by aherbert.

the class BenchmarkFilterAnalysis method shutdown.

/*
	 * (non-Javadoc)
	 * 
	 * @see gdsc.smlm.ga.FitnessFunction#shutdown()
	 */
public void shutdown() {
    // Report the score for the best filter
    List<? extends Chromosome<FilterScore>> individuals = ga_population.getIndividuals();
    FilterScore max = null;
    for (Chromosome<FilterScore> c : individuals) {
        final FilterScore f = c.getFitness();
        if (f != null && f.compareTo(max) < 0) {
            max = f;
        }
    }
    if (max == null)
        return;
    DirectFilter filter = (DirectFilter) ((SimpleFilterScore) max).filter;
    // This filter may not have been part of the scored subset so use the entire results set for reporting
    FractionClassificationResult r = scoreFilter(filter, minimalFilter, ga_resultsList, coordinateStore);
    final StringBuilder text = createResult(filter, r);
    add(text, ga_iteration);
    gaWindow.append(text.toString());
}
Also used : FilterScore(gdsc.smlm.results.filter.FilterScore) IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter) FractionClassificationResult(gdsc.core.match.FractionClassificationResult)

Example 3 with FractionClassificationResult

use of gdsc.core.match.FractionClassificationResult in project GDSC-SMLM by aherbert.

the class Filter method fractionScore.

/**
	 * 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.
	 * 
	 * @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 fractionScore(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;
            }
            // 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)

Example 4 with FractionClassificationResult

use of gdsc.core.match.FractionClassificationResult in project GDSC-SMLM by aherbert.

the class BenchmarkFilterAnalysis method score.

public SearchResult<FilterScore>[] score(double[][] points) {
    ga_iteration++;
    SimpleFilterScore max = es_optimum;
    final FilterScoreResult[] scoreResults = scoreFilters(setStrength(new FilterSet(searchSpaceToFilters(points))), false);
    if (scoreResults == null)
        return null;
    @SuppressWarnings("unchecked") SearchResult<FilterScore>[] scores = new SearchResult[scoreResults.length];
    for (int index = 0; index < scoreResults.length; index++) {
        final FilterScoreResult scoreResult = scoreResults[index];
        final SimpleFilterScore result = new SimpleFilterScore(scoreResult, true, scoreResult.criteria >= minCriteria);
        if (result.compareTo(max) < 0) {
            max = result;
        }
        scores[index] = new SearchResult<FilterScore>(result.r.filter.getParameters(), result);
    }
    es_optimum = max;
    // Add the best filter to the table
    // This filter may not have been part of the scored subset so use the entire results set for reporting
    DirectFilter filter = max.r.filter;
    FractionClassificationResult r = scoreFilter(filter, minimalFilter, ga_resultsList, coordinateStore);
    final StringBuilder text = createResult(filter, r);
    add(text, ga_iteration);
    gaWindow.append(text.toString());
    return scores;
}
Also used : FilterSet(gdsc.smlm.results.filter.FilterSet) IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter) SearchResult(gdsc.smlm.search.SearchResult) FilterScore(gdsc.smlm.results.filter.FilterScore) FractionClassificationResult(gdsc.core.match.FractionClassificationResult)

Example 5 with FractionClassificationResult

use of gdsc.core.match.FractionClassificationResult in project GDSC-SMLM by aherbert.

the class BenchmarkFilterAnalysis method scoreFilter.

private FilterScoreResult scoreFilter(DirectFilter filter) {
    final FractionClassificationResult r = scoreFilter(filter, minimalFilter, resultsList, coordinateStore);
    final double score = getScore(r);
    final double criteria = getCriteria(r);
    // Create the score output
    final String text = createResult(filter, r).toString();
    return new FilterScoreResult(score, criteria, filter, text);
}
Also used : FractionClassificationResult(gdsc.core.match.FractionClassificationResult)

Aggregations

FractionClassificationResult (gdsc.core.match.FractionClassificationResult)15 DirectFilter (gdsc.smlm.results.filter.DirectFilter)6 IDirectFilter (gdsc.smlm.results.filter.IDirectFilter)5 ArrayList (java.util.ArrayList)4 PeakResultPoint (gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint)3 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)3 PeakResult (gdsc.smlm.results.PeakResult)3 SimpleRegression (org.apache.commons.math3.stat.regression.SimpleRegression)3 BasePoint (gdsc.core.match.BasePoint)2 FractionalAssignment (gdsc.core.match.FractionalAssignment)2 FastCorrelator (gdsc.core.utils.FastCorrelator)2 BasePreprocessedPeakResult (gdsc.smlm.results.filter.BasePreprocessedPeakResult)2 FilterScore (gdsc.smlm.results.filter.FilterScore)2 FilterSet (gdsc.smlm.results.filter.FilterSet)2 MultiPathFilter (gdsc.smlm.results.filter.MultiPathFilter)2 PeakFractionalAssignment (gdsc.smlm.results.filter.PeakFractionalAssignment)2 PreprocessedPeakResult (gdsc.smlm.results.filter.PreprocessedPeakResult)2 SearchResult (gdsc.smlm.search.SearchResult)2 BufferedTextWindow (gdsc.core.ij.BufferedTextWindow)1 ClassificationResult (gdsc.core.match.ClassificationResult)1