Search in sources :

Example 11 with DirectFilter

use of gdsc.smlm.results.filter.DirectFilter 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 12 with DirectFilter

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

the class BenchmarkFilterAnalysis method setStrength.

/**
	 * Sets the strength on all the filters.
	 *
	 * @param filterSet
	 *            the filter set
	 * @return the filter set
	 */
private FilterSet setStrength(FilterSet filterSet) {
    if (ss_lower != null) {
        for (Filter f : filterSet.getFilters()) {
            final DirectFilter df = (DirectFilter) f;
            df.setStrength(df.computeStrength(ss_lower, ss_upper));
        }
    }
    return filterSet;
}
Also used : IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter) Filter(gdsc.smlm.results.filter.Filter) MultiPathFilter(gdsc.smlm.results.filter.MultiPathFilter) MaximaSpotFilter(gdsc.smlm.filters.MaximaSpotFilter) IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter)

Example 13 with DirectFilter

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

the class BenchmarkFilterAnalysis method runAnalysis.

private void runAnalysis(List<FilterSet> filterSets, ComplexFilterScore optimum, double rangeReduction) {
    plots.clear();
    plots.ensureCapacity(plotTopN);
    bestFilter.clear();
    bestFilterOrder.clear();
    getCoordinateStore();
    filterAnalysisStopWatch = StopWatch.createStarted();
    IJ.showStatus("Analysing filters ...");
    int setNumber = 0;
    DirectFilter currentOptimum = (optimum != null) ? optimum.r.filter : null;
    for (FilterSet filterSet : filterSets) {
        setNumber++;
        if (filterAnalysis(filterSet, setNumber, currentOptimum, rangeReduction) < 0)
            break;
    }
    filterAnalysisStopWatch.stop();
    IJ.showProgress(1);
    IJ.showStatus("");
    final String timeString = filterAnalysisStopWatch.toString();
    IJ.log("Filter analysis time : " + timeString);
}
Also used : FilterSet(gdsc.smlm.results.filter.FilterSet) IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter)

Example 14 with DirectFilter

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

the class BenchmarkFilterAnalysis method componentAnalysis.

private void componentAnalysis(FractionClassificationResult bestResult, ComplexFilterScore bestFilterScore) {
    if (componentAnalysis == 0)
        return;
    createComponentAnalysisWindow();
    final DirectFilter bestFilter = bestFilterScore.getFilter();
    final String[] names = getNames(bestFilter);
    // Skip disabled parameters
    int nParams = bestFilter.getNumberOfParameters();
    final boolean[] enable = new boolean[nParams];
    int[] map = new int[nParams];
    for (int n = 0, i = 0; n < map.length; n++) {
        if (bestFilter.getParameterValue(n) == bestFilter.getDisabledParameterValue(n)) {
            // Mark to ignore
            enable[n] = true;
            nParams--;
        } else {
            map[i++] = n;
        }
    }
    // Score the best filter just so we have the unique Ids of the results
    score(bestFilter, -1, nParams, null, null, null, 0);
    final int[] uniqueIds1 = uniqueIds;
    final int uniqueIdCount1 = uniqueIdCount;
    // Limit to 12 params == 4095 combinations (this is the max for two multi filters combined)
    if (componentAnalysis >= 3 && nParams <= 12) {
        // Enumeration of combinations
        long count = countCombinations(nParams);
        // Enumerate all combinations
        ComplexFilterScore[] scores = new ComplexFilterScore[(int) count];
        int j = 0;
        for (int k = 1; k <= nParams; k++) {
            Iterator<int[]> it = CombinatoricsUtils.combinationsIterator(nParams, k);
            while (it.hasNext()) {
                final int[] combinations = it.next();
                final boolean[] enable2 = enable.clone();
                for (int i = 0; i < k; i++) {
                    combinations[i] = map[combinations[i]];
                    enable2[combinations[i]] = true;
                }
                final DirectFilter f = (DirectFilter) bestFilter.create(enable2);
                scores[j++] = score(f, 0, k, combinations, enable2, uniqueIds1, uniqueIdCount1);
            }
        }
        // Report
        Arrays.sort(scores, new FilterScoreCompararor());
        int lastSize = 0;
        for (int i = 0; i < scores.length; i++) {
            if (componentAnalysis == 3) {
                if (lastSize == scores[i].size)
                    // Only add the best result for each size
                    continue;
                lastSize = scores[i].size;
            }
            // Find the last component that was added
            if (scores[i].size == 1) {
                scores[i].index = scores[i].combinations[0];
            } else {
                // For each size k, find the best result with k-1 components and set the add index appropriately
                int add = -1;
                int target = -1;
                for (int l = 0; l < enable.length; l++) if (scores[i].enable[l])
                    target++;
                final int size1 = scores[i].size - 1;
                for (int ii = 0; ii < i; ii++) {
                    if (scores[ii].size < size1)
                        continue;
                    if (scores[ii].size > size1)
                        // Broken
                        break;
                    // Count matches. It must be 1 less than the current result
                    int matches = 0;
                    for (int l = 0; l < enable.length; l++) {
                        if (scores[i].enable[l] && scores[ii].enable[l])
                            matches++;
                    }
                    if (matches == target) {
                        // Find the additional parameter added
                        for (int l = 0; l < enable.length; l++) {
                            if (scores[i].enable[l]) {
                                if (scores[ii].enable[l])
                                    continue;
                                add = l;
                                break;
                            }
                        }
                        break;
                    }
                }
                scores[i].index = add;
            }
            addToComponentAnalysisWindow(scores[i], bestFilterScore, names);
        }
        return;
    }
    // Preserve the option to output the best or all results if we fell through from above
    final int myComponentAnalysis = (componentAnalysis >= 3) ? componentAnalysis - 2 : componentAnalysis;
    // Progressively add components until all are the same as the input bestFilter
    int enabled = 0;
    int[] previousCombinations = new int[0];
    for (int ii = 0; ii < nParams; ii++) {
        // Create a set of filters by enabling each component that is not currently enabled.
        ComplexFilterScore[] scores = new ComplexFilterScore[nParams - enabled];
        int k = enabled + 1;
        for (int i = 0, j = 0; i < nParams; i++) {
            int n = map[i];
            if (enable[n])
                continue;
            enable[n] = true;
            final DirectFilter f = (DirectFilter) bestFilter.create(enable);
            enable[n] = false;
            final int[] combinations = new int[k];
            System.arraycopy(previousCombinations, 0, combinations, 0, previousCombinations.length);
            combinations[k - 1] = n;
            Arrays.sort(combinations);
            scores[j++] = score(f, n, k, combinations, null, uniqueIds1, uniqueIdCount1);
        }
        // Rank them
        Arrays.sort(scores);
        for (int i = 0; i < scores.length; i++) {
            addToComponentAnalysisWindow(scores[i], bestFilterScore, names);
            if (myComponentAnalysis == 1)
                // Only add the best result
                break;
        }
        // Flag the best component added
        enable[scores[0].index] = true;
        enabled++;
        previousCombinations = scores[0].combinations;
    }
}
Also used : IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter)

Example 15 with DirectFilter

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

the class BenchmarkFilterAnalysis method saveFilter.

private void saveFilter(DirectFilter filter) {
    // Save the filter to file
    String filename = getFilename("Best_Filter_File", filterFilename);
    if (filename != null) {
        filterFilename = filename;
        Prefs.set(KEY_FILTER_FILENAME, filename);
        List<Filter> filters = new ArrayList<Filter>(1);
        filters.add(filter);
        FilterSet filterSet = new FilterSet(filter.getName(), filters);
        List<FilterSet> list = new ArrayList<FilterSet>(1);
        list.add(filterSet);
        saveFilterSet(filterSet, filename);
    }
}
Also used : FilterSet(gdsc.smlm.results.filter.FilterSet) IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter) Filter(gdsc.smlm.results.filter.Filter) MultiPathFilter(gdsc.smlm.results.filter.MultiPathFilter) MaximaSpotFilter(gdsc.smlm.filters.MaximaSpotFilter) ArrayList(java.util.ArrayList)

Aggregations

DirectFilter (gdsc.smlm.results.filter.DirectFilter)17 IDirectFilter (gdsc.smlm.results.filter.IDirectFilter)14 MultiPathFilter (gdsc.smlm.results.filter.MultiPathFilter)8 Filter (gdsc.smlm.results.filter.Filter)7 MaximaSpotFilter (gdsc.smlm.filters.MaximaSpotFilter)6 FilterSet (gdsc.smlm.results.filter.FilterSet)6 FractionClassificationResult (gdsc.core.match.FractionClassificationResult)5 ArrayList (java.util.ArrayList)4 FitEngineConfiguration (gdsc.smlm.engine.FitEngineConfiguration)3 FitConfiguration (gdsc.smlm.fitting.FitConfiguration)3 FilterScore (gdsc.smlm.results.filter.FilterScore)3 GenericDialog (ij.gui.GenericDialog)3 BasePoint (gdsc.core.match.BasePoint)2 PeakResultPoint (gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint)2 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)2 SearchResult (gdsc.smlm.search.SearchResult)2 NonBlockingGenericDialog (ij.gui.NonBlockingGenericDialog)2 Checkbox (java.awt.Checkbox)2 LinkedList (java.util.LinkedList)2 BufferedTextWindow (gdsc.core.ij.BufferedTextWindow)1