use of gdsc.smlm.results.filter.DirectFilter in project GDSC-SMLM by aherbert.
the class BenchmarkFilterAnalysis method findOptimum.
public SearchResult<FilterScore> findOptimum(double[][] points) {
ga_iteration++;
SimpleFilterScore max = es_optimum;
final FilterScoreResult[] scoreResults = scoreFilters(setStrength(new FilterSet(searchSpaceToFilters(points))), false);
if (scoreResults == null)
return null;
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;
}
}
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 new SearchResult<FilterScore>(filter.getParameters(), max);
}
use of gdsc.smlm.results.filter.DirectFilter 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);
}
Aggregations