Search in sources :

Example 6 with FractionalAssignment

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

the class BenchmarkFilterAnalysis method reportResults.

private ComplexFilterScore reportResults(boolean newResults, List<ComplexFilterScore> filters) {
    if (filters.isEmpty()) {
        IJ.log("Warning: No filters pass the criteria");
        return null;
    }
    getCoordinateStore();
    Collections.sort(filters);
    FractionClassificationResult topFilterClassificationResult = null;
    ArrayList<FractionalAssignment[]> topFilterResults = null;
    String topFilterSummary = null;
    if (showSummaryTable || saveTemplate) {
        createSummaryWindow();
        int n = 0;
        final double range = (summaryDepth / simulationParameters.a) * 0.5;
        int np = 0;
        for (double depth : depthStats) {
            if (Math.abs(depth) < range)
                np++;
        }
        for (ComplexFilterScore fs : filters) {
            final ArrayList<FractionalAssignment[]> list = new ArrayList<FractionalAssignment[]>(resultsList.length);
            final FractionClassificationResult r = scoreFilter(fs.getFilter(), minimalFilter, resultsList, list, coordinateStore);
            final StringBuilder sb = createResult(fs.getFilter(), r);
            if (topFilterResults == null) {
                topFilterResults = list;
                topFilterClassificationResult = r;
            }
            // Show the recall at the specified depth. Sum the distance and signal factor of all scored spots.
            int scored = 0;
            double tp = 0, d = 0, sf = 0, rmsd = 0;
            SimpleRegression regression = new SimpleRegression(false);
            for (FractionalAssignment[] assignments : list) {
                if (assignments == null)
                    continue;
                for (int i = 0; i < assignments.length; i++) {
                    final CustomFractionalAssignment c = (CustomFractionalAssignment) assignments[i];
                    if (Math.abs(c.peak.error) <= range)
                        tp += c.getScore();
                    d += c.d;
                    sf += c.getSignalFactor();
                    rmsd += c.d * c.d;
                    regression.addData(c.peakResult.getSignal(), c.peak.getSignal());
                }
                scored += assignments.length;
            }
            final double slope = regression.getSlope();
            sb.append('\t');
            sb.append(Utils.rounded((double) tp / np)).append('\t');
            sb.append(Utils.rounded(d / scored)).append('\t');
            sb.append(Utils.rounded(sf / scored)).append('\t');
            sb.append(Utils.rounded(Math.sqrt(rmsd / scored))).append('\t');
            sb.append(Utils.rounded(slope)).append('\t');
            if (fs.atLimit() != null)
                sb.append(fs.atLimit());
            String text = sb.toString();
            if (topFilterSummary == null) {
                topFilterSummary = text;
                if (!showSummaryTable)
                    break;
            }
            if (fs.time != 0) {
                sb.append('\t');
                sb.append(fs.algorithm);
                sb.append('\t');
                sb.append(org.apache.commons.lang3.time.DurationFormatUtils.formatDurationHMS(fs.time));
            } else
                sb.append("\t\t");
            if (fs.paramTime != 0) {
                sb.append('\t');
                sb.append(fs.getParamAlgorithm());
                sb.append('\t');
                sb.append(org.apache.commons.lang3.time.DurationFormatUtils.formatDurationHMS(fs.paramTime));
            } else
                sb.append("\t\t");
            text = sb.toString();
            if (isHeadless)
                IJ.log(text);
            else
                summaryWindow.append(text);
            n++;
            if (summaryTopN > 0 && n >= summaryTopN)
                break;
        }
        // Add a spacer to the summary table if we have multiple results
        if (n > 1 && showSummaryTable) {
            if (isHeadless)
                IJ.log("");
            else
                summaryWindow.append("");
        }
    }
    DirectFilter bestFilter = filters.get(0).getFilter();
    if (saveBestFilter)
        saveFilter(bestFilter);
    if (topFilterClassificationResult == null) {
        topFilterResults = new ArrayList<FractionalAssignment[]>(resultsList.length);
        topFilterClassificationResult = scoreFilter(bestFilter, minimalFilter, resultsList, topFilterResults, coordinateStore);
    }
    if (newResults || scores.isEmpty()) {
        scores.add(new FilterResult(failCount, residualsThreshold, duplicateDistance, filters.get(0)));
    }
    if (saveTemplate)
        saveTemplate(topFilterSummary);
    showPlots();
    calculateSensitivity();
    topFilterResults = depthAnalysis(topFilterResults, bestFilter);
    topFilterResults = scoreAnalysis(topFilterResults, bestFilter);
    componentAnalysis(topFilterClassificationResult, filters.get(0));
    PreprocessedPeakResult[] filterResults = null;
    if (isShowOverlay())
        filterResults = showOverlay(topFilterResults, bestFilter);
    saveResults(filterResults, bestFilter);
    wo.tile();
    return filters.get(0);
}
Also used : IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter) ArrayList(java.util.ArrayList) SimpleRegression(org.apache.commons.math3.stat.regression.SimpleRegression) FractionalAssignment(gdsc.core.match.FractionalAssignment) PeakFractionalAssignment(gdsc.smlm.results.filter.PeakFractionalAssignment) FractionClassificationResult(gdsc.core.match.FractionClassificationResult) BasePreprocessedPeakResult(gdsc.smlm.results.filter.BasePreprocessedPeakResult) PreprocessedPeakResult(gdsc.smlm.results.filter.PreprocessedPeakResult)

Example 7 with FractionalAssignment

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

the class MultiPathFilter method score.

/**
	 * Score the assignments (TP/FP) and then clear the list.
	 *
	 * @param assignments
	 *            The assignments
	 * @param score
	 *            Scores array to accumulate TP/FP scores
	 * @param nPredicted
	 *            The number of predictions
	 * @param save
	 *            Set to true to save the scored assignments
	 * @param nActual
	 *            The number of actual results in the frame
	 * @return the fractional assignments
	 */
private FractionalAssignment[] score(final ArrayList<FractionalAssignment> assignments, final double[] score, final int nPredicted, boolean save, int nActual) {
    if (assignments.isEmpty())
        return null;
    final FractionalAssignment[] tmp = assignments.toArray(new FractionalAssignment[assignments.size()]);
    final RankedScoreCalculator calc = new RankedScoreCalculator(tmp, nActual, nPredicted);
    final double[] result = calc.score(nPredicted, false, save);
    score[0] += result[0];
    score[1] += result[1];
    score[2] += result[2];
    score[3] += result[3];
    assignments.clear();
    return calc.getScoredAssignments();
}
Also used : FractionalAssignment(gdsc.core.match.FractionalAssignment) RankedScoreCalculator(gdsc.core.match.RankedScoreCalculator)

Aggregations

FractionalAssignment (gdsc.core.match.FractionalAssignment)7 PeakFractionalAssignment (gdsc.smlm.results.filter.PeakFractionalAssignment)6 BasePreprocessedPeakResult (gdsc.smlm.results.filter.BasePreprocessedPeakResult)3 MultiPathFilter (gdsc.smlm.results.filter.MultiPathFilter)3 PreprocessedPeakResult (gdsc.smlm.results.filter.PreprocessedPeakResult)3 PlotWindow (ij.gui.PlotWindow)3 ArrayList (java.util.ArrayList)3 FractionClassificationResult (gdsc.core.match.FractionClassificationResult)2 DirectFilter (gdsc.smlm.results.filter.DirectFilter)2 TIntHashSet (gnu.trove.set.hash.TIntHashSet)2 Plot2 (ij.gui.Plot2)2 SimpleRegression (org.apache.commons.math3.stat.regression.SimpleRegression)2 BasePoint (gdsc.core.match.BasePoint)1 ImmutableFractionalAssignment (gdsc.core.match.ImmutableFractionalAssignment)1 RankedScoreCalculator (gdsc.core.match.RankedScoreCalculator)1 FastCorrelator (gdsc.core.utils.FastCorrelator)1 StoredDataStatistics (gdsc.core.utils.StoredDataStatistics)1 MaximaSpotFilter (gdsc.smlm.filters.MaximaSpotFilter)1 ScoredSpot (gdsc.smlm.ij.plugins.BenchmarkSpotFilter.ScoredSpot)1 PeakResultPoint (gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint)1