Skip to content

Python tool for aircraft Doppler audio geolocation using historical ADS-B flight data (Source-available)

Gate known-clock single events and explicit partial associations (#9)

Cinna Davis0812d5ab119c
diff --git a/docs/CONFIDENCE.md b/docs/CONFIDENCE.md
index a7dd925..365bdc8 100644
--- a/docs/CONFIDENCE.md
+++ b/docs/CONFIDENCE.md
@@ -16,21 +16,35 @@ scope and availability of requested archives, not capture of every aircraft.
## Default policy and evidence
-The default `DecisionPolicy` is `engineering-v1`, frozen before the held-out
-decision-fixture run. Development negative controls motivated explicit abstention
+The current default `DecisionPolicy` is `engineering-v2`; the original v1 receipts
+remain preserved. Development negative controls motivated explicit abstention
for noise, absent tracks, harmonic duplicates, incomplete coverage, bad residuals
and multiple plausible hypotheses. The engineering thresholds are deliberately
-simple and predeclared: at least two independent flyovers, <=3 Hz event RMSE,
+simple and predeclared: normally at least two independent flyovers, <=3 Hz event RMSE,
<=25% outliers, >=95% trajectory support, and 100 m maximum sensitivity radius.
For `negative_robust_ridge_loss_hz`, a competing loss within 0.5 Hz per independent
-event is a near tie. A location more than 200 m away or a different flight
-association then triggers ambiguity. Other score kinds have no declared gap
+event is a near tie. The declared subset-support score has a separate
+dimensionless near-tie threshold of 0.2 support units per independent group;
+it is not a Hz threshold or probability. Other score kinds have no declared gap
threshold and abstain. These are regression-tested engineering choices, **not
empirically calibrated thresholds for arbitrary aircraft audio**. No held-out
real recordings have established their false-localization rate.
-Every leading hypothesis must explain the event set with one locked recording
-clock; harmonics count once and must map to the same flight. Matching diagnostics
+One flyover can pass the event-count gate with a trusted recording-start window
+when the fitted clock lies within it and sensitivity tests cover that **entire
+input window**, not only a local clock perturbation. All residual, support,
+global-alternative and uncertainty gates still apply. A known clock is not
+inferred from the fitted candidate. W5 supplies the validated original request
+window as `recording_start_window_s`; W3 profiles expose the tested span in
+`sensitivity.settings.clock_bounds_s`.
+
+Matched flyovers use one locked recording clock; harmonics count once and must
+map to the same flight. The explicit subset score may leave proposals unmatched
+when `unmatched_event_ids` exactly enumerates the original discovered-minus-matched
+IDs. Entire harmonic groups must be retained. These omitted proposals remain
+unconfirmed sounds, not labelled aircraft misses or silently deleted evidence.
+Different retained subsets remain comparable only using their declared support
+score and may still trigger flight/location ambiguity. Matching diagnostics
use event-ID keys with `rmse_hz`, `outlier_fraction`, `support_fraction` and
`drift_at_bound`. Other required evidence keys are `clock_locked`,
`refinement_boundary_limited`, `alternatives_evaluated` and `sensitivity`.
@@ -62,7 +76,9 @@ branch; it does not establish that the real producer has provided such evidence.
| `no_matching_flights` | No event/track hypothesis |
| `insufficient_independent_events` | Too few flyovers after harmonic grouping |
| `inconsistent_harmonic_association` | Harmonics map to different flights |
-| `unexplained_events` | Candidate omits discovered events |
+| `incomplete_harmonic_group` | Partial association omits a matched event's harmonic |
+| `unexplained_events` | Unmatched proposals lack explicit subset-association evidence |
+| `recording_clock_mismatch` | Fitted start is outside the trusted original window |
| `timing_not_established` | Shared clock unverified |
| `matching_diagnostics_missing` | Event-fit evidence unavailable |
| `insufficient_track_support` | Incomplete trajectory support |
diff --git a/src/aircraft_geoloc/confidence.py b/src/aircraft_geoloc/confidence.py
index ec42793..269d98a 100644
--- a/src/aircraft_geoloc/confidence.py
+++ b/src/aircraft_geoloc/confidence.py
@@ -9,7 +9,7 @@ import math
from pyproj import Geod
-from .contracts import validate_result
+from .contracts import utc_timestamp, validate_result
@dataclass(frozen=True)
@@ -21,9 +21,10 @@ class DecisionPolicy:
max_outlier_fraction: float = 0.25
min_support_fraction: float = 0.95
near_tie_loss_per_event_hz: float = 0.5
+ near_tie_support_per_group: float = 0.2
def __post_init__(self):
- for name in ("target_radius_m", "max_event_rmse_hz", "near_tie_loss_per_event_hz"):
+ for name in ("target_radius_m", "max_event_rmse_hz", "near_tie_loss_per_event_hz", "near_tie_support_per_group"):
if not math.isfinite(getattr(self, name)) or getattr(self, name) <= 0:
raise ValueError(f"{name} must be positive and finite")
if type(self.min_independent_events) is not int or self.min_independent_events < 2:
@@ -38,7 +39,10 @@ def decide_location(events, candidates, coverage, *, matching_diagnostics=None,
``matching_diagnostics`` uses W3/W5's event-ID keys, plus clock_locked,
refinement_boundary_limited, alternatives_evaluated and sensitivity.
- Sensitivity must state complete=True, boundary_limited=False and list tested
+ A known-clock single event requires recording_start_window_s and complete
+ sensitivity across that whole input window (settings.clock_bounds_s). Partial
+ associations explicitly enumerate original unmatched_event_ids; these remain
+ unconfirmed acoustic proposals. Sensitivity must list tested
sources: frequency, clock, altitude and sound_speed. An altitude-only profile
cannot justify 100 m spatial precision. The orchestrator owns execution errors
and missing recording-clock needs_input; malformed evidence is failed here.
@@ -46,7 +50,7 @@ def decide_location(events, candidates, coverage, *, matching_diagnostics=None,
policy = policy or DecisionPolicy()
if not isinstance(policy, DecisionPolicy):
raise TypeError("policy must be a DecisionPolicy")
- diagnostics = {"policy": asdict(policy), "policy_version": "engineering-v1",
+ diagnostics = {"policy": asdict(policy), "policy_version": "engineering-v2",
"calibration": "uncalibrated", "probability": None,
"limitations": ["Archive availability does not establish capture of every aircraft.",
"Sensitivity checks are not a calibrated confidence interval."]}
@@ -90,10 +94,40 @@ def decide_location(events, candidates, coverage, *, matching_diagnostics=None,
return result("inconsistent_harmonic_association", "Harmonics of one event map to different flight segments.")
groups[key] = (event, flight)
diagnostics["independent_event_groups"] = len(groups)
- if len(groups) < policy.min_independent_events:
+ sensitivity = evidence.get("sensitivity", {})
+ window = evidence.get("recording_start_window_s")
+
+ def interval(value):
+ return (isinstance(value, (list, tuple)) and len(value) == 2 and
+ all(not isinstance(v, bool) and isinstance(v, (int, float)) and math.isfinite(v) for v in value)
+ and value[0] <= value[1])
+
+ if window is not None:
+ if not interval(window):
+ return result("invalid_evidence", "The trusted recording-start window must have two finite ordered endpoints.", "failed")
+ fitted = utc_timestamp(best["recording_start_utc"]).timestamp()
+ if not window[0] <= fitted <= window[1]:
+ return result("recording_clock_mismatch", "The fitted recording start lies outside the trusted recording window.")
+ diagnostics["recording_start_window_s"] = list(window)
+ settings = sensitivity.get("settings", {}) if isinstance(sensitivity, dict) else {}
+ tested_clock = settings.get("clock_bounds_s") if isinstance(settings, dict) else None
+ known_clock = (interval(window) and interval(tested_clock) and
+ tested_clock[0] <= window[0] and tested_clock[1] >= window[1])
+ diagnostics["known_clock_single_event"] = bool(len(groups) == 1 and known_clock)
+ if len(groups) < policy.min_independent_events and not (len(groups) == 1 and
+ policy.min_independent_events == 2 and known_clock):
return result("insufficient_independent_events", "Too few independent flyovers constrain location; harmonics count once.")
- if set(best["event_ids"]) != set(lookup):
- return result("unexplained_events", "The leading hypothesis leaves discovered events unexplained.")
+ unmatched = set(lookup) - set(best["event_ids"])
+ if unmatched:
+ declared = evidence.get("unmatched_event_ids")
+ if (best["score_kind"] != "matched_group_support_minus_normalized_residual" or
+ not isinstance(declared, list) or not all(isinstance(key, str) for key in declared) or
+ len(set(declared)) != len(declared) or set(declared) != unmatched):
+ return result("unexplained_events", "Unmatched acoustic proposals need an explicit subset-association record.")
+ if any(lookup[key].get("harmonic_group_id", key) in groups for key in unmatched):
+ return result("incomplete_harmonic_group", "A matched flyover omits one of its measured harmonic ridges.")
+ diagnostics["unmatched_event_ids"] = sorted(unmatched)
+ diagnostics["unmatched_proposal_status"] = "unconfirmed acoustic proposals; not labelled aircraft misses"
if evidence.get("clock_locked") is not True:
return result("timing_not_established", "One shared recording clock has not been verified across all events.")
for event, _ in groups.values():
@@ -115,17 +149,21 @@ def decide_location(events, candidates, coverage, *, matching_diagnostics=None,
if fit.get("drift_at_bound") is not False:
return result("source_drift_unresolved", "The source-frequency drift model is missing or reaches its allowed bound.")
- if best["score_kind"] != "negative_robust_ridge_loss_hz":
+ subset_scores = best["score_kind"] == "matched_group_support_minus_normalized_residual"
+ if best["score_kind"] != "negative_robust_ridge_loss_hz" and not subset_scores:
return result("unsupported_score_kind", "This ranking score has no declared ambiguity threshold in the decision policy.")
for alternative in candidates[1:]:
- # Unmatched/subset candidates cannot be compared as equal-size losses.
- if set(alternative["event_ids"]) != set(best["event_ids"]):
+ # Raw losses require equal event sets; subset support has declared units.
+ if not subset_scores and set(alternative["event_ids"]) != set(best["event_ids"]):
return result("incomparable_candidates", "Competing candidates do not explain the same event set.")
separation = abs(Geod(ellps="WGS84").inv(best["lon"], best["lat"], alternative["lon"], alternative["lat"])[2])
same_flights = dict(zip(best["event_ids"], best["flight_ids"])) == dict(zip(alternative["event_ids"], alternative["flight_ids"]))
- loss_gap = (best["score"] - alternative["score"]) / len(groups)
- if (separation > 2 * policy.target_radius_m or not same_flights) and loss_gap <= policy.near_tie_loss_per_event_hz:
- diagnostics["competing_hypothesis"] = {"separation_m": separation, "loss_gap_per_event_hz": loss_gap,
+ alternative_groups = {lookup[key].get("harmonic_group_id", key) for key in alternative["event_ids"]}
+ gap = (best["score"] - alternative["score"]) / max(len(groups), len(alternative_groups))
+ threshold = policy.near_tie_support_per_group if subset_scores else policy.near_tie_loss_per_event_hz
+ units = "support_units_per_group" if subset_scores else "loss_hz_per_group"
+ if (separation > 2 * policy.target_radius_m or not same_flights) and gap <= threshold:
+ diagnostics["competing_hypothesis"] = {"separation_m": separation, "score_gap": gap, "gap_units": units,
"same_flight_association": same_flights}
return result("ambiguous_locations" if separation > 2 * policy.target_radius_m else "ambiguous_flight_match",
"Competing hypotheses fit nearly as well; no unique precise location is supported.")
diff --git a/tests/test_confidence.py b/tests/test_confidence.py
index 8f56f86..ca1558a 100644
--- a/tests/test_confidence.py
+++ b/tests/test_confidence.py
@@ -98,3 +98,40 @@ def test_w3_vertical_only_profile_is_not_a_100m_confidence_claim():
diag["sensitivity"] = {"radius_m": 0.0, "kind": "sensitivity", "method": "profiled_relative_altitude_offsets",
"complete": True, "boundary_limited": False, "profiles": []}
assert decide((events, candidates, coverage, diag))["reason_code"] == "uncertainty_not_established"
+
+
+def test_known_clock_single_event_requires_full_trusted_window_sensitivity():
+ from aircraft_geoloc.contracts import utc_timestamp
+ events, candidates, coverage, diag = evidence()
+ events = events[:1]
+ candidates[0].update(event_ids=["e0"], flight_ids=["a"])
+ start = utc_timestamp(candidates[0]["recording_start_utc"]).timestamp()
+ assert decide((events, candidates, coverage, diag))["reason_code"] == "insufficient_independent_events"
+ diag["recording_start_window_s"] = [start-1, start+1]
+ diag["sensitivity"]["settings"] = {"clock_bounds_s": [start, start]}
+ assert decide((events, candidates, coverage, diag))["reason_code"] == "insufficient_independent_events"
+ diag["sensitivity"]["settings"]["clock_bounds_s"] = [start-1, start+1]
+ result = decide((events, candidates, coverage, diag))
+ assert result["status"] == "succeeded"
+ assert result["diagnostics"]["known_clock_single_event"] is True
+ diag["recording_start_window_s"] = [start+1, start+2]
+ assert decide((events, candidates, coverage, diag))["reason_code"] == "recording_clock_mismatch"
+
+
+def test_explicit_subset_keeps_unconfirmed_proposals_without_forcing_matches():
+ events, candidates, coverage, diag = evidence()
+ extra = deepcopy(events[1])
+ extra.update(event_id="e2", harmonic_group_id="g2")
+ events.append(extra)
+ candidates[0].update(score_kind="matched_group_support_minus_normalized_residual", score=1.8)
+ assert decide((events, candidates, coverage, diag))["reason_code"] == "unexplained_events"
+ diag["unmatched_event_ids"] = ["e2"]
+ result = decide((events, candidates, coverage, diag))
+ assert result["status"] == "succeeded"
+ assert result["diagnostics"]["unmatched_event_ids"] == ["e2"]
+ alternative = dict(candidates[0], lat=45., event_ids=["e0", "e2"], flight_ids=["a", "c"], score=1.7)
+ assert decide((events, candidates+[alternative], coverage, diag))["reason_code"] == "ambiguous_locations"
+ alternative["score"] = 0.5
+ assert decide((events, candidates+[alternative], coverage, diag))["status"] == "succeeded"
+ extra["harmonic_group_id"] = "g0"
+ assert decide((events, candidates, coverage, diag))["reason_code"] == "incomplete_harmonic_group"