Collar-based event precision, recall and F1¶
Event-based F1, or collar F1, scores a sound event detector by matching each predicted event to at most one reference event of the same class. With the default settings a pair counts only when the onsets differ by at most 0.2 s and the offsets by at most 0.2 s or 20% of the reference duration, whichever is larger.
Specification identifier: event_f1/1.
Status: implemented (bootstrap). Established metric family; selected
fixtures are compared against sed_eval 0.2.1 as described below.
Source: Mesaros, Heittola and Virtanen, Metrics for Polyphonic Sound Event
Detection, Applied Sciences 6(6):162, 2016, https://doi.org/10.3390/app6060162,
together with the event-based evaluation in sed_eval 0.2.x. The collar rules
below follow that protocol; deviations are listed under Limitations.
What does event F1 penalise?¶
Event F1 asks one question per pair: do both boundaries land inside their collars? There is no partial credit. Pick a mistake and move the slider; the grey bands are the collars.
Numbers behind this figure
Late or early onset
| Onset shift (s) | Precision | Recall | F1 |
|---|---|---|---|
| -0.6 | 0.00 | 0.00 | 0.00 |
| -0.55 | 0.00 | 0.00 | 0.00 |
| -0.5 | 0.00 | 0.00 | 0.00 |
| -0.45 | 0.00 | 0.00 | 0.00 |
| -0.4 | 0.00 | 0.00 | 0.00 |
| -0.35 | 0.00 | 0.00 | 0.00 |
| -0.3 | 0.00 | 0.00 | 0.00 |
| -0.25 | 0.00 | 0.00 | 0.00 |
| -0.2 | 0.00 | 0.00 | 0.00 |
| -0.15 | 1.00 | 1.00 | 1.00 |
| -0.1 | 1.00 | 1.00 | 1.00 |
| -0.05 | 1.00 | 1.00 | 1.00 |
| 0 | 1.00 | 1.00 | 1.00 |
| 0.05 | 1.00 | 1.00 | 1.00 |
| 0.1 | 1.00 | 1.00 | 1.00 |
| 0.15 | 1.00 | 1.00 | 1.00 |
| 0.2 | 0.00 | 0.00 | 0.00 |
| 0.25 | 0.00 | 0.00 | 0.00 |
| 0.3 | 0.00 | 0.00 | 0.00 |
| 0.35 | 0.00 | 0.00 | 0.00 |
| 0.4 | 0.00 | 0.00 | 0.00 |
| 0.45 | 0.00 | 0.00 | 0.00 |
| 0.5 | 0.00 | 0.00 | 0.00 |
| 0.55 | 0.00 | 0.00 | 0.00 |
| 0.6 | 0.00 | 0.00 | 0.00 |
Late or early offset
| Offset shift (s) | Precision | Recall | F1 |
|---|---|---|---|
| -1.6 | 0.00 | 0.00 | 0.00 |
| -1.4 | 0.00 | 0.00 | 0.00 |
| -1.2 | 0.00 | 0.00 | 0.00 |
| -1 | 0.00 | 0.00 | 0.00 |
| -0.8 | 1.00 | 1.00 | 1.00 |
| -0.6 | 1.00 | 1.00 | 1.00 |
| -0.4 | 1.00 | 1.00 | 1.00 |
| -0.2 | 1.00 | 1.00 | 1.00 |
| 0 | 1.00 | 1.00 | 1.00 |
| 0.2 | 1.00 | 1.00 | 1.00 |
| 0.4 | 1.00 | 1.00 | 1.00 |
| 0.6 | 1.00 | 1.00 | 1.00 |
| 0.8 | 1.00 | 1.00 | 1.00 |
| 1 | 0.00 | 0.00 | 0.00 |
| 1.2 | 0.00 | 0.00 | 0.00 |
| 1.4 | 0.00 | 0.00 | 0.00 |
| 1.6 | 0.00 | 0.00 | 0.00 |
Event length
| Reference length (s) | Precision | Recall | F1 |
|---|---|---|---|
| 0.5 | 0.00 | 0.00 | 0.00 |
| 1 | 0.00 | 0.00 | 0.00 |
| 1.5 | 0.00 | 0.00 | 0.00 |
| 2 | 0.00 | 0.00 | 0.00 |
| 2.5 | 1.00 | 1.00 | 1.00 |
| 3 | 1.00 | 1.00 | 1.00 |
| 3.5 | 1.00 | 1.00 | 1.00 |
| 4 | 1.00 | 1.00 | 1.00 |
| 4.5 | 1.00 | 1.00 | 1.00 |
| 5 | 1.00 | 1.00 | 1.00 |
Split detection
| Gap between pieces (s) | Precision | Recall | F1 |
|---|---|---|---|
| 0 | 0.00 | 0.00 | 0.00 |
| 0.2 | 0.00 | 0.00 | 0.00 |
| 0.4 | 0.00 | 0.00 | 0.00 |
| 0.6 | 0.00 | 0.00 | 0.00 |
| 0.8 | 0.00 | 0.00 | 0.00 |
| 1 | 0.00 | 0.00 | 0.00 |
| 1.2 | 0.00 | 0.00 | 0.00 |
| 1.4 | 0.00 | 0.00 | 0.00 |
| 1.6 | 0.00 | 0.00 | 0.00 |
| 1.8 | 0.00 | 0.00 | 0.00 |
| 2 | 0.00 | 0.00 | 0.00 |
Merged events
| Gap between events (s) | Precision | Recall | F1 |
|---|---|---|---|
| 0.2 | 0.00 | 0.00 | 0.00 |
| 0.4 | 0.00 | 0.00 | 0.00 |
| 0.6 | 0.00 | 0.00 | 0.00 |
| 0.8 | 0.00 | 0.00 | 0.00 |
| 1 | 0.00 | 0.00 | 0.00 |
| 1.2 | 0.00 | 0.00 | 0.00 |
| 1.4 | 0.00 | 0.00 | 0.00 |
| 1.6 | 0.00 | 0.00 | 0.00 |
| 1.8 | 0.00 | 0.00 | 0.00 |
| 2 | 0.00 | 0.00 | 0.00 |
False alarms
| Extra detections | Precision | Recall | F1 |
|---|---|---|---|
| 0 | 1.00 | 1.00 | 1.00 |
| 1 | 0.67 | 1.00 | 0.80 |
| 2 | 0.50 | 1.00 | 0.67 |
| 3 | 0.40 | 1.00 | 0.57 |
| 4 | 0.33 | 1.00 | 0.50 |
Missed events
| Events missed | Precision | Recall | F1 |
|---|---|---|---|
| 0 | 1.00 | 1.00 | 1.00 |
| 1 | 1.00 | 0.75 | 0.86 |
| 2 | 1.00 | 0.50 | 0.67 |
| 3 | 1.00 | 0.25 | 0.40 |
| 4 | None | 0.00 | 0.00 |
Wrong class
| Second event labelled | Precision | Recall | F1 |
|---|---|---|---|
| speech (correct) | 1.00 | 1.00 | 1.00 |
| siren (wrong) | 0.50 | 0.50 | 0.50 |
| Mistake | Effect on the counts |
|---|---|
| Onset or offset just outside its collar | The pair is lost: one FP and one FN |
| Event reported in pieces | At most one piece can match; with no piece inside both collars, every piece is an FP and the reference an FN |
| Two events reported as one | At most one reference can match; with offsets evaluated, usually none does |
| Extra detection | One FP |
| Missed event | One FN |
| Right interval, wrong class | One FP for the predicted class and one FN for the reference class |
In the formulas on this page, red terms lower the score. A near miss costs more than silence. Saying nothing about an event adds one FN; reporting it just outside the collar adds an FN and an FP:
1. Input representation¶
Each event is (recording_id, class_id, onset, offset):
recording_id,class_id: nonnegative integer identifiers. Names are mapped to identifiers by adapters, not by this metric.onset,offset: seconds,f64.- Intervals are half-open,
[onset, offset), and must have positive length.
Validation is strict and always on: non-finite timestamps, negative onsets,
offset <= onset and (when recording durations are supplied) events extending
past the recording end or referencing an unknown recording raise an error. Rows
are never dropped silently.
Optional recording durations ({recording_id: duration_seconds}) are used only
for boundary validation in this metric; they are required by exposure-based
metrics such as false alerts per hour, not by event F1.
2. Definition¶
For one (recording, class) group, a prediction \(p\) is eligible for a
reference \(r\) when both conditions hold:
where \(c_{\text{on}}\) is onset_collar, \(c_{\text{off}}\) is offset_collar and
\(\rho\) is offset_ratio. The second condition applies only when
evaluate_offset is true.
With \(M\) the matched pairs, counted over all classes and recordings:
mean_onset_error and mean_offset_error are the mean absolute differences
over matched pairs only, in seconds:
3. Matching policy¶
- Matching is one-to-one: a reference pairs with at most one prediction and a prediction with at most one reference.
- Eligibility is evaluated independently per
(recording, class)group; a prediction can never match a reference of another class or recording. - Matching is maximum cardinality within each group, computed with augmenting paths (Kuhn's algorithm). A greedy assignment is not used, because it can lose valid true positives (a regression test covers this).
- Among maximum-cardinality matchings the implementation does not minimise
total localization error. The selected matching is deterministic for a given
input order: events are sorted by
(onset, offset)and references are processed in that order, preferring the lowest-index eligible prediction. Counts are invariant to input permutation; the particular pairs need not be. - Collar comparisons are exact (
<=) with no floating-point epsilon.offset <= onset + collarmatches;offsetone ULP beyond does not. Note that decimal inputs such as1.2 - 1.0are not exact in binary, so "0.2 s collar" is not bit-exactly 0.2 in every case. Timings that matter at the boundary should be expressed in binary-exact values or compared through fixtures that acknowledge this. - Ties between predictions (identical onset and offset) are resolved by input order; they are interchangeable for the counts and for the error statistics.
4. Aggregation, units and undefined values¶
average="micro" pools counts over all classes and then computes the ratios
(the TP-weighted result). average="macro" computes each ratio per class and
takes the unweighted mean over the classes where that ratio is defined. For
a ratio \(m\) with defined classes \(C_m\):
Two consequences follow:
- Macro F1 is not the harmonic mean of macro precision and macro recall, and the precision, recall and F1 means can have different support (a class with predictions but no references contributes to macro precision only).
- Per-class statistics are always returned, sorted by class id, including
classes that appear only in references or only in predictions. Nothing is
dropped:
result.classesandresult.n_classesmake the support auditable.
Undefined results are None (JSON null), never NaN and never silently zero:
| Situation | precision | recall | F1 |
|---|---|---|---|
| No predictions | None |
value | value |
| No references | value | None |
value |
| No predictions and no references | None |
None |
None |
Units: ratios are dimensionless; localization errors are seconds.
5. Defaults and profiles¶
The defaults form the dcase2016 profile: onset_collar = 0.2,
offset_collar = 0.2, offset_ratio = 0.2, evaluate_offset = True, and
average = "micro".
Provenance: the collar values and the max(offset_collar, ratio * duration)
offset rule follow the 2016 Mesaros et al. protocol and DCASE 2016 Task 2
practice. Micro averaging is the sed_eval-style overall result (pooled
counts). Neither value is universal: other challenges use different collars and
macro averaging, so callers should pass the profile they intend to reproduce.
sed_eval 0.2.1 exposes the same rule as t_collar plus
percentage_of_length, but its percentage_of_length default is 0.5, not
0.2. Reproducing this profile in sed_eval requires passing
t_collar=0.2, percentage_of_length=0.2 explicitly.
evaluate_offset=False implements an onset-only protocol and must be labelled
as such in reports.
6. Hand-computed example¶
References [(0,0,0.0,1.0), (0,0,2.0,3.0), (0,0,4.0,5.0)], predictions
[(0,0,0.0,1.0), (0,0,2.0,3.0), (0,0,7.0,8.0)], collars 0.2 / 0.2 / 0.2:
TP = 2,FP = 1,FN = 1precision = recall = 2/3,F1 = 4/6 = 2/3- mean onset and offset error over the two matched pairs:
0s
Macro is not the F1 of macro precision and recall. With class 0 holding 1 match
among 10 references and class 1 holding 1 match among 10 predictions, each
class has F1 = 2/11, so macro F1 = 2/11 ≈ 0.182, while macro precision and
macro recall are both 0.55 and their harmonic mean is 0.55.
7. Related implementations, verification and complexity¶
- References:
sed_eval0.2.1 event-based metrics withevent_matching_type="optimal"(Hopcroft–Karp maximum-cardinality matching), Mesaros et al. 2016. - Parity:
tests/parity/test_event_f1_sed_eval.pycompares counts and P/R/F1 againstsed_evalwith the samet_collarandpercentage_of_length. Cases: hand fixtures, exact collar boundaries, an onset-only protocol, seeded random perturbations, 120 URBAN-SED test clips (638 events, 10 classes) and 60 AudioSet strong clips (625 events, 86 classes). Counts agree exactly; ratios agree to1e-12. The parity dependency is a test-only extra, never a runtime dependency. - One intentional reporting difference:
sed_evalcounts leftover reference/system pairs that satisfy the collars but disagree on class as substitutions (Nsubs) and subtracts them from itsNfp/Nfn. This implementation follows the classification conventionFP = n_predicted - TP,FN = n_reference - TP, so its insertion and deletion counts equalsed_eval'sNfp + NsubsandNfn + Nsubs. Substitution counts are not reported yet. - Empty-system behaviour also differs by design: with no predictions,
sed_evalreportsNaNF1 and precision; this implementation reports precisionNoneandF1 = 0(see §4). - Additional local evidence: hand-computed fixtures and a brute-force maximum-matching oracle over deterministic pseudo-random small cases.
- Numerical tolerance: fixtures compare with
1e-12absolute tolerance on ratios derived from exact integer counts. - Complexity: eligibility is
O(n_ref * n_pred)per group and Kuhn's algorithm isO(V * E)in the worst case; both are computed per(recording, class)group, so independent recordings and classes scale separately.
Limitations¶
- Maximum-cardinality matching does not minimise localization error, and no per-class onset/offset-constrained matching is offered.
- No substitution (
Nsubs) statistic and no error rate; insertion/deletion counts follow the FP/FN convention described in §7, which differs fromsed_eval's event-based reporting. - Only one matching policy is implemented; intersection-based metrics (PSDS) will need a different one and must not reuse this matcher.
- No support yet for confidence values, class names, score tracks or recording boundaries beyond optional validation.
- Collar parameters are in seconds only; there is no sample-index or tick representation.
Common questions¶
What collar does event F1 use by default?¶
0.2 s on the onset. On the offset, the larger of 0.2 s and 20% of the reference duration.
Is there partial credit for a near miss?¶
No. A prediction just outside a collar counts as one false positive and one false negative.
What is the difference between micro and macro event F1?¶
Micro pools counts over all classes before computing ratios. Macro averages each ratio over the classes where it is defined.