Hydrofon wikiThe manual of an underwater listening app 文A eesti

Manual:Metrics

Other languages: eesti English

A headline figure such as "85% accuracy" or "1,000 false alarms per hour" tells you little until you know which decision rule turned model scores into labels and what denominator the rate divided by. This page defines the core metrics used in Hydrofon, explains why earlier numbers disagreed across the app (audit finding F02), and describes the unified four-layer evaluation core in app/evaluation.py.

What each number means

Hydrofon splits audio into short analysis windows (0.975 s for YAMNet, 1.0 s for band models) and compares each window with the ground truth (background, interference or engine). The core metrics are:

Accuracy (accuracy)
Share of all scored windows that received the right class. When recordings consist mostly of quiet background, accuracy can look deceptively high even when a model misses boats.
Balanced accuracy (balanced_accuracy)
Unweighted mean of each class's recall. For three classes, random guessing scores 33.3% (for two classes, 50%). A model cannot score well just by always predicting the most common class.
Engine recall (recall)
TP / (TP + FN): fraction of real engine windows (or real engine episodes, at the event layer) that the model caught. Low recall means missed boats.
Engine precision (precision)
TP / (TP + FP): fraction of windows called engine that actually were engine. Low precision means frequent false alarms. Recall and precision combine into F1 = 2·TP / (2·TP + FP + FN). Binary evaluation also reports false positive rate (FPR = FP / (TN + FP)) and specificity = TN / (TN + FP).
False alarms per hour
How often the system calls engine per hour of engine-free audio. The number depends heavily on whether you count single windows, runs of consecutive windows, confirmed events or user notifications — and on how engine-free time is measured.

Three incompatible rules in the legacy code (F02)

The project's code audit (finding F02, docs/audit/leidude_staatus.md) showed that three parts of Hydrofon originally used three different decision rules and denominators:

Where Decision rule False-alarm count and denominator
Training (app/train.py) 3-class argmax for trained models; score >= 0.3 for YAMNet Runs of consecutive wrong windows; denominator n_negative_windows × hop_s
Clip analysis (app/analysis.py) Mixed: accuracy via 3-class argmax, recall and false_alarms via score >= threshold Runs of consecutive windows above threshold; denominator raw sum of non-engine segment durations
Live alarm (app/detector.py Alarm) score >= threshold (0.3) for 3 consecutive windows, cooldown_s = 10.0 s Repeats every cooldown during one continuous engine pass; does not check time gaps

Because Clip analysis mixed two rules in one function, a single window with probabilities [0.05, 0.60, 0.35] (argmax = interference, but engine = 0.35 >= 0.30) counted as both correct (for accuracy) and a false alarm (for false_alarms). Denominators also diverged: on the Wolfset seed=0 test split, non-engine segments total 848.18 s (14.14 min), whereas n_windows × hop_s gave 755.04 s for YAMNet and 753.50 s for bands — roughly an 11% gap.

The GUI has not yet switched to the new core

The unified evaluation core (app/evaluation.py) and event engine (app/events.py) exist and are covered by unit tests, but neither is wired into the desktop GUI yet. Clip analysis still displays metrics from app/analysis.py, and the live view still uses the legacy Alarm class (Alarms and events). Historical tables in docs/treenimise_tulemused.md also predate the unified core (The baseline).

The four evaluation layers (app/evaluation.py)

To stop mixing incompatible numbers, app/evaluation.py (specified in docs/evaluation.md) separates evaluation into four layers that are never merged into one headline metric. Every result carries its decision_rule (name, version, parameters) and its denominator / denominator_name.

Layer Function Question answered What it does not show
1. 3-class argmax multiclass() How well does the model tell background, interference and engine apart per window (confusion matrix, balanced_accuracy, macro_f1)? Ignores score thresholds and alarm rate; not applicable to raw YAMNet.
2. Binary threshold binary() / binary_from_decisions() How well does the model separate engine from non-engine at a chosen rule (score_engine >= threshold or argmax == engine)? Fair comparison across YAMNet and trained models. Ignores consecutive windows, hysteresis and episode counts.
3. Detection events match_events() How many real engine episodes are detected (event_recall), how quickly (delay_s), and how many false events occur per negative hour (false_events_per_hour)? Does not count repeated alerts shown to the user.
4. User notifications notifications() How many alerts the user actually receives (notification_recall, repeats, false_notifications_per_hour, first-notification delay)? Does not distinguish one long false event from several short ones without layer 3.

In layer 3, detector events [onset_s, offset_s) are matched one-to-one (one_to_one_overlap v1) against merged truth engine episodes (truth_episodes). An episode starting at the beginning of a recording (<= recording_start_s + EPS) is marked left-censored (left_censored = True) and excluded from delay statistics because the engine may already have been running before recording started.

Honest denominators, T_negative and null-with-reason

Mapping windows to truth (windows_to_truth)
By default (min_coverage = 1.0, float slack EPS = 1e-6 s), a window receives a class label only when it lies wholly inside one segment and no differently labelled segment overlaps it. ignore segments keep truth = "ignore" with valid_for_scoring = False; unlabelled or boundary-straddling windows get truth = None and valid_for_scoring = False. Audio gaps and non-finite scores are never scored as negative (binary() raises ValueError on NaN/inf).
Undefined values are null with a reason
Whenever a denominator is zero — for example T_negative = 0, a class has zero support in the truth, or the model never predicted a class — app/evaluation.py returns {"value": null, "reason": "..."} rather than a fake 0.0 or 1.0. That separates an undefined metric from a real zero (engine windows existed, TP + FN > 0, and the model caught none, giving recall = 0.0). If a class is missing from a 3-class test, full balanced_accuracy and macro_f1 are null; the mean over the remaining classes is reported separately under balanced_accuracy_present_classes and macro_f1_present_classes.
T_negative as an interval union
Negative truth time T_negative is computed as the union of non-engine (background, interference) intervals — optionally intersected with evaluated windows for observed negative time — minus ignore segments, engine segments and excluded gaps (exclude). Overlapping analysis windows or overlapping segments therefore never double-count negative time (fixing audit finding N-04). The hourly rate is:
false_events_per_hour = 3600 * N_false / T_negative

When T_negative = 0, the function returns null with a reason. legacy_window_time_s(n_windows, hop_s), legacy_train_metrics() and legacy_analysis_metrics() are kept only to reproduce older reports exactly.

See also

This page has not been saved yet.

The Hydrofon project · volli.page