feat(optimizer): sweep expansion bands + presence mode; tolerate scattered dropped votes

Make the flood-fill and expansion knobs reachable from the DE sweep:

- kpn_bindings: read expand_band_lo/hi and presence_mode from the replay
  cfg dict (presence_mode accepts "flood"/"track_extent" or a numeric
  >=0.5 toggle), and carry is_scene_boundary onto the replayed frame.
- replay.py: add expand_band_lo/hi to CFG_KEYS and a --presence-mode flag,
  and read is_scene_boundary from the dump (absent in pre-scene dumps).
- optimize.py: map the continuous presence_flood knob (0..1, >=0.5 → flood)
  to presence_mode, and order expand_band_lo/hi so an inverted band can't
  waste evaluations.

Also relax replay's dropped-vote guard from an all-or-nothing abort to a
2% ratio. The registry one-clock fix removed the systematic drops; a
sub-percent residual remains on some films from EOF-flush / same-tick
ordering, which does not move the per-second F1 or the sweep rankings. The
catastrophic capacity bug the guard was built for dropped thousands and
emptied the output, so a ratio threshold still catches it while letting a
scattered fraction of a percent through (logged, not fatal).
This commit is contained in:
2026-08-09 10:21:45 +02:00
parent 584f23546a
commit d113c83189
3 changed files with 70 additions and 8 deletions
+19
View File
@@ -136,6 +136,8 @@ template<> struct PythonConverter<EmbeddedSceneFrame> {
ef.source.frame_idx = d.contains("frame_idx") ? nb::cast<int64_t>(d["frame_idx"]) : -1;
ef.source.eof = d.contains("eof") ? nb::cast<bool>(d["eof"]) : false;
ef.source.is_cut = d.contains("is_cut") ? nb::cast<bool>(d["is_cut"]) : false;
ef.source.is_scene_boundary = d.contains("is_scene_boundary")
? nb::cast<bool>(d["is_scene_boundary"]) : false;
if (ef.source.eof) return ef;
// faces: (N,4) bbox, (N,10) landmarks, (N,) confidence, (N,512) embeddings
@@ -254,6 +256,23 @@ static Config config_from_dict(nb::dict d) {
geti("evidence_max_views", cfg.evidence_max_views);
// gallery expansion (usually off for sweeps; expose so it can be toggled)
if (d.contains("expand_gallery")) cfg.expand_gallery = nb::cast<bool>(d["expand_gallery"]);
// AR-018: banded admission bounds for the per-film annex, in probability
// space. Reachable from a sweep — the config comment asks for both to be
// swept, and they are ignored unless expand_gallery is on. See track_gallery.hpp.
getf("expand_band_lo", cfg.expand_band_lo);
getf("expand_band_hi", cfg.expand_band_hi);
// Presence derivation. Accepts a string ("flood"/"track_extent") or a
// number (DE only produces floats: >=0.5 → flood) so the sweep can toggle
// it as a sixth knob. flood snaps to boundaries in the replayed frames
// (is_scene_boundary if present, else is_cut).
if (d.contains("presence_mode")) {
const auto& pm = d["presence_mode"];
bool flood = false;
if (nb::isinstance<nb::str>(pm)) flood = (nb::cast<std::string>(pm) == "flood");
else flood = (nb::cast<double>(pm) >= 0.5);
cfg.presence_mode = flood ? PresenceMode::flood : PresenceMode::track_extent;
}
/// TRACES: GR-004 | SR-001
if (d.contains("require_gallery_stamp"))
cfg.require_gallery_stamp = nb::cast<bool>(d["require_gallery_stamp"]);