| Algorithm 2. Spatial Event Corrector. |
|
Inputs: Active expectations E_S = ⟨S, bindings, [t_a, t_b]⟩ // from pattern context & anchors Observation buffer O_K // last K s of {x(t), μ_Z(x), class, bbox flags} Config method ∈ {BN, LSTM, TRAJ}, ∆_probe, ε_t, δ, B Thresholds τ_BN, τ_LSTM, τ_TRAJ BN params Θ_BN LSTM params M_LSTM (model weights), T (window), stride Trajectory params μ_ROI(·), exemplars H, FastDTW radius r, blend β State: none (stateless; queries only) procedure CORRECTOR(E_S): // ----- GAP DETECTION ----- let ⟨S, bindings, [t_a, t_b]⟩ = E_S if now < t_b + Δ_probe: return // wait a small patience window if exists RAW SpatialEvent(type = S, bindings, t_raw ∈ [t_a, t_b]) in O_K: return // no gap → nothing to correct // ----- EVIDENCE ASSEMBLY ----- E ← slice O_K for variables in ‘bindings’ over [t_a − δ, t_b + δ] if E is empty: return // ----- SINGLE-METHOD IMPUTATION (chosen by config) ----- switch method: case BN: … if p < τ_BN: return conf ← p case LSTM: … if p_t(t*) < τ_LSTM: return conf ← p_t(t*) case TRAJ: … if best = Ø or best.score < τ_TRAJ: return t* ← argmax_{p∈best.σ} μ_ROI(p) // most plausible time inside segment conf ← best.score // ----- DEDUP AGAINST RAW EVENTS ----- if exists RAW SpatialEvent(type = S, bindings, t_raw) with |t_raw − t*| ≤ ε_t in O_K: return // prefer raw observation // ----- EMIT ADDITIVE CORRECTED EVENT ----- emit SpatialEvent ⟨type = S, bindings, t* = t*, conf = conf, corrected = true⟩ // ----- TIME BUDGET GUARD (optional) ----- ensure wall-clock time ≤ B ms (degrade by skipping LSTM or lowering DTW radius if needed) |