use of gdsc.smlm.results.filter.FilterSet in project GDSC-SMLM by aherbert.
the class FilterAnalysis method addTraceFilters.
private void addTraceFilters(List<FilterSet> filterSets) {
if (!traceFilter)
return;
for (double d = minDistance; d <= maxDistance; d += incDistance) {
SNRFilter snr = new SNRFilter(maxSnr);
List<Filter> filters = new LinkedList<Filter>();
for (int t = minTime; t <= maxTime; t += incTime) {
filters.add(new OrFilter(snr, new TraceFilter(d, t)));
}
filterSets.add(new FilterSet(filters));
}
}
use of gdsc.smlm.results.filter.FilterSet in project GDSC-SMLM by aherbert.
the class FilterAnalysis method addPrecisionHysteresisFilters.
private void addPrecisionHysteresisFilters(List<FilterSet> filterSets) {
if (!hysteresisPrecisionFilter)
return;
for (int precisionGap = minPrecisionGap; precisionGap <= maxPrecisionGap; precisionGap += incPrecisionGap) {
List<Filter> filters = new LinkedList<Filter>();
for (int precision = minPrecision; precision <= maxPrecision; precision++) {
filters.add(new PrecisionHysteresisFilter(2, 0, 1, 0, precision, precisionGap));
}
filterSets.add(new FilterSet(filters));
}
}
use of gdsc.smlm.results.filter.FilterSet in project GDSC-SMLM by aherbert.
the class FilterAnalysis method analyse.
/**
* Run different filtering methods on a set of labelled peak results outputting performance statistics on the
* success of
* the filter to an ImageJ table.
* <p>
* If the peak result original value is set to 1 it is considered a true peak, 0 for a false peak. Filtering is done
* using e.g. SNR threshold, Precision thresholds, etc. The statistics reported are shown in a table, e.g.
* precision, Jaccard, F-score.
* <p>
* For each filter set a plot is shown of the Jaccard score verses the filter value, thus filters should be provided
* in ascending numerical order otherwise they are sorted.
*
* @param resultsList
* @param filterSets
*/
public void analyse(List<MemoryPeakResults> resultsList, List<FilterSet> filterSets) {
createResultsWindow();
plots = new ArrayList<NamedPlot>(plotTopN);
bestFilter = new HashMap<String, FilterScore>();
bestFilterOrder = new LinkedList<String>();
IJ.showStatus("Analysing filters ...");
int total = countFilters(filterSets);
int count = 0;
for (FilterSet filterSet : filterSets) {
IJ.showStatus("Analysing " + filterSet.getName() + " ...");
count = run(filterSet, resultsList, count, total);
}
IJ.showProgress(1);
IJ.showStatus("");
showPlots();
calculateSensitivity(resultsList);
}
use of gdsc.smlm.results.filter.FilterSet in project GDSC-SMLM by aherbert.
the class BenchmarkFilterAnalysis method iterate.
private void iterate() {
// If this is run again immediately then provide options for reporting the results
if (iterBestFilter != null && iterBestFilter == bestFilter) {
GenericDialog gd = new GenericDialog(TITLE);
gd.enableYesNoCancel();
gd.addMessage("Iteration results are held in memory.\n \nReport these results?");
gd.showDialog();
if (gd.wasCanceled())
return;
if (gd.wasOKed()) {
reportIterationResults();
return;
}
}
// TODO - collect this in the iteration dialog
if (!showIterationDialog())
return;
// Total the time from the interactive plugins
long time = 0;
// Run the benchmark fit once interactively, keep the instance
BenchmarkSpotFit fit = new BenchmarkSpotFit();
// than has been optimised before)
if (fit.resetMultiPathFilter() || invalidBenchmarkSpotFitResults(true)) {
fit.run(null);
if (!fit.finished)
// The plugin did not complete
return;
resetParametersFromFitting();
}
if (invalidBenchmarkSpotFitResults(false))
return;
if (BenchmarkSpotFit.stopWatch != null)
time += BenchmarkSpotFit.stopWatch.getTime();
// Run filter analysis once interactively
if (!loadFitResults())
return;
// Collect parameters for optimising the parameters
if (!showDialog(FLAG_OPTIMISE_FILTER | FLAG_OPTIMISE_PARAMS))
return;
// Load filters from file
List<FilterSet> filterSets = readFilterSets();
if (filterSets == null || filterSets.isEmpty()) {
IJ.error(TITLE, "No filters specified");
return;
}
ComplexFilterScore current = analyse(filterSets);
if (current == null)
return;
time += filterAnalysisStopWatch.getTime();
current = analyseParameters(current);
if (current == null)
return;
time += parameterAnalysisStopWatch.getTime();
// Time the non-interactive plugins as a continuous section
iterationStopWatch = StopWatch.createStarted();
// Remove the previous iteration results
iterBestFilter = null;
Utils.log(TITLE + " Iterating ...");
IterationConvergenceChecker checker = new IterationConvergenceChecker(current);
// Iterate ...
boolean outerConverged = false;
int outerIteration = 1;
double outerRangeReduction = 1;
while (!outerConverged) {
if (iterationConvergeBeforeRefit) {
// Optional inner loop so that the non-filter and filter parameters converge
// before a refit
boolean innerConverged = false;
int innerIteration = 0;
double innerRangeReduction = 1;
if (iterationMinRangeReduction < 1) {
// Linear interpolate down to the min range reduction
innerRangeReduction = Maths.max(iterationMinRangeReduction, Maths.interpolateY(0, 1, iterationMinRangeReductionIteration, iterationMinRangeReduction, innerIteration++));
// This would make the range too small...
//innerRangeReduction *= outerRangeReduction;
}
while (!innerConverged) {
ComplexFilterScore previous = current;
// Re-use the filters as the user may be loading a custom set.
current = analyse(filterSets, current, innerRangeReduction);
if (current == null)
break;
double[] previousParameters = createParameters();
current = analyseParameters(current, innerRangeReduction);
if (current == null)
return;
double[] currentParameters = createParameters();
innerConverged = checker.converged("Filter", previous, current, previousParameters, currentParameters);
}
// Check if we can continue (e.g. not max iterations or escape pressed)
if (!checker.canContinue)
break;
}
// Do the fit (using the current optimum filter)
fit.run(current.r.filter, residualsThreshold, failCount, duplicateDistance);
if (invalidBenchmarkSpotFitResults(false))
return;
if (!loadFitResults())
return;
// is centred around the current optimum.
if (iterationMinRangeReduction < 1) {
// Linear interpolate down to the min range reduction
outerRangeReduction = Maths.max(iterationMinRangeReduction, Maths.interpolateY(0, 1, iterationMinRangeReductionIteration, iterationMinRangeReduction, outerIteration++));
}
// Optimise the filter again.
ComplexFilterScore previous = current;
// Re-use the filters as the user may be loading a custom set.
current = analyse(filterSets, current, outerRangeReduction);
if (current == null)
break;
double[] previousParameters = createParameters();
current = analyseParameters(current, outerRangeReduction);
if (current == null)
return;
double[] currentParameters = createParameters();
outerConverged = checker.converged("Fit+Filter", previous, current, previousParameters, currentParameters);
}
if (current != null) //if (converged)
{
// Set-up the plugin so that it can be run again (in iterative mode)
// and the results reported for the top filter.
// If the user runs the non-iterative mode then the results will be lost.
iterBestFilter = bestFilter;
}
time += iterationStopWatch.getTime();
IJ.log("Iteration analysis time : " + DurationFormatUtils.formatDurationHMS(time));
IJ.showStatus("Finished");
}
use of gdsc.smlm.results.filter.FilterSet 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);
}
}
Aggregations