diff --git a/AGENTS.md b/AGENTS.md index b6bfa5a3..4855daa1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -966,6 +966,10 @@ right, ownship teal left, only Debrief detects ownship turns, `splitter_ownship_ chart's quantity as a drop-down; the Preset drop-down shows the matching preset or "custom"; a waypoint drag keeps the adjacent legs' speeds (`moveWaypoint(..., "speed")`; the square keeps duration); ctrl-click deletes a waypoint. Schema 0.39.0. +Owner 2026-11-22: bearings are lost in ownship's turns and for 120 s after each; the demonstrator +drops them by default (`DemoScenario.turn_loss_s`, null keeps all; `TmaProblem.bearing_valid`, +rows kept so grids stay regular; schema 0.40.0). Spec 035's golden problems and spec 036's +readings pin `turn_loss_s: null`. ## Stack (owner decisions, 2026-10-31) diff --git a/conformance/onnx/demo_node.mjs b/conformance/onnx/demo_node.mjs index 529b1270..c69eafa0 100644 --- a/conformance/onnx/demo_node.mjs +++ b/conformance/onnx/demo_node.mjs @@ -209,6 +209,64 @@ test("LinkML validation accepts every preset and rejects a bad file with its mes assert.ok(errs.some((e) => e.includes('"extra"')), errs.join("; ")); }); +// ---------- bearings lost in ownship's turns (owner, 2026-11-22) ---------- +test("bearings are lost during each ownship turn and 120 s after; the kept ones do not change", () => { + const sc = preset("good-geometry"); + assert.equal(sc.turn_loss_s, 120); + const b = bearings(sc), keep = bearings({ ...sc, turn_loss_s: null }); + assert.deepEqual(Array.from(b.z), Array.from(keep.z)); + assert.ok(keep.valid.every((v) => v === 1)); + const turns = T.manoeuvres(b.paths.own).filter((m) => m.course); + assert.equal(turns.length, 3); + for (let i = 0; i < b.n; i++) { + const lost = turns.some((m) => b.t[i] >= m.t0 - 1e-9 && b.t[i] <= m.t1 + 120 + 1e-9); + assert.equal(b.valid[i], lost ? 0 : 1, `row ${i} t ${b.t[i]}`); + } + // a 60-degree turn at 1 deg/s lasts about a minute, then two minutes: about 36 rows of 5 s each + const nLost = b.n - b.valid.reduce((a, v) => a + v, 0); + assert.ok(nLost > 90 && nLost < 130, `${nLost} lost`); + // a scenario saved without the field takes the default + const legacy = clone(sc); + delete legacy.turn_loss_s; + assert.equal(normaliseScenario(legacy).turn_loss_s, 120); + assert.deepEqual(Array.from(bearings(legacy).valid), Array.from(b.valid)); + // the schema accepts null and rejects a negative tail + assert.deepEqual(checkScenario(schema, { ...sc, turn_loss_s: null }), []); + assert.ok(checkScenario(schema, { ...sc, turn_loss_s: -1 }).length > 0); +}); + +test("least squares with lost bearings flagged equals least squares on the received rows only", async () => { + const sc = preset("good-geometry"); + const b = bearings(sc); + const { problem } = problemOf(sc, b, windowRows(sc, b)); + assert.ok(problem.bearing_valid.includes(0)); + const keep = problem.t_s.map((_, k) => k).filter((k) => problem.bearing_valid[k]); + const pick = (a) => keep.map((k) => a[k]); + const sub = { ...problem, t_s: pick(problem.t_s), bearing_rad: pick(problem.bearing_rad), own_x_m: pick(problem.own_x_m), own_y_m: pick(problem.own_y_m), own_course_rad: pick(problem.own_course_rad), own_speed_mps: pick(problem.own_speed_mps), bearing_valid: undefined }; + const a = await solver("ls-js").solve(problem, { run }), c = await solver("ls-js").solve(sub, { run }); + for (const k of [0, keep.length - 1]) { + assert.ok(Math.abs(a.x_m[keep[k]] - c.x_m[k]) < 1e-6 && Math.abs(a.vx_mps[keep[k]] - c.vx_mps[k]) < 1e-9); + } + for (let q = 0; q < 16; q++) assert.ok(Math.abs(a.cov_end[q] - c.cov_end[q]) <= 1e-8 * (Math.abs(c.cov_end[q]) + 1)); + // the scored residuals skip lost bearings + const r = await solveScenario(sc, "ls-js"); + assert.equal(r.ev.residual.length, keep.length); +}); + +test("the learned model's inputs zero a lost bearing's features and keep ownship's", () => { + const sc = preset("good-geometry"); + const b = bearings(sc); + const { problem: p } = problemOf(sc, b, windowRows(sc, b)); + const full = TLM.periodFeatures(p.t_s, p.own_x_m, p.own_y_m, p.bearing_rad, p.sigma_rad); + const lost = TLM.periodFeatures(p.t_s, p.own_x_m, p.own_y_m, p.bearing_rad, p.sigma_rad, p.bearing_valid); + const k = p.bearing_valid.indexOf(0), N = TLM.N_FEATURES; + assert.deepEqual([0, 1, 4].map((j) => lost.f[k * N + j]), [0, 0, 0]); + for (const j of [2, 3, 5, 6, 7, 8]) assert.equal(lost.f[k * N + j], full.f[k * N + j]); + // the smoothed bearing interpolates over the gap + const zs = TLM.smoothedBearing(p.bearing_rad, p.bearing_valid); + assert.ok(zs.every(Number.isFinite)); +}); + // ---------- ONNX ---------- test("the ONNX physics layer with one leg equals the JavaScript solve on noise-free bearings", async () => { const sc = { ...preset("good-geometry"), sigma_deg: 0 }; @@ -322,7 +380,9 @@ test("spec 036 follow-up: Debrief's splitter states the ownship turns it found, }); test("two target turns inside ownship legs: joined legs find both, Debrief one, independent slices land between", async () => { - const sc = preset("two-target-turns"); + // spec 036's reading, every bearing kept (with the owner's turn loss, seed 1's first turn is + // placed at 50 min, outside the 120 s match; seeds 2, 3 and 5 still find both) + const sc = { ...preset("two-target-turns"), turn_loss_s: null }; const j = await split(sc, "arctan-joined"); assert.equal(j.legs.matched, 2); assert.equal(j.legs.false_, 0); diff --git a/conformance/onnx/demo_page.mjs b/conformance/onnx/demo_page.mjs index 961b5cb2..d0c34f4e 100644 --- a/conformance/onnx/demo_page.mjs +++ b/conformance/onnx/demo_page.mjs @@ -124,6 +124,20 @@ try { await settled(); + // owner 2026-11-22: bearings lost in ownship's turns; the control turns the loss off and on + const lostText = async () => page.locator("[data-testid=window-slider]").innerText(); + const withLoss = await lostText(); + await page.locator("[data-testid=turn-loss]").uncheck(); + await page.waitForTimeout(50); + await settled(); + const without = await lostText(); + const sNo = await state(); + await page.locator("[data-testid=turn-loss]").check(); + await page.waitForTimeout(50); + await settled(); + const sYes = await state(); + check("bearings lost in ownship turns: stated under the window, and the control turns the loss off", /lost in ownship's turns/.test(withLoss) && !/lost in ownship's turns/.test(without) && sNo.sc.turn_loss_s === null && sYes.sc.turn_loss_s === 120, { withLoss: withLoss.split(";")[1] }); + // acceptance 5: the URL restores the exact scenario and solution await page.locator("[data-testid=reseed]").click(); await page.waitForTimeout(50); diff --git a/conformance/onnx/demo_problems.mjs b/conformance/onnx/demo_problems.mjs index 52fdc2c2..b5bef477 100644 --- a/conformance/onnx/demo_problems.mjs +++ b/conformance/onnx/demo_problems.mjs @@ -1,6 +1,8 @@ // Spec 035: the demonstrator's solver problems for the golden least-squares vectors. Every // preset at sigma 1 and 0, the target-turn preset narrowed to its first leg, written as JSON -// for demo_golden.py (Python's tma2.references.lsq.solve_batch on the same arrays). +// for demo_golden.py (Python's tma2.references.lsq.solve_batch on the same arrays). Spec 035's +// problems keep every bearing (turn_loss_s null), so the golden files' digests stand; the +// lost-bearing path is checked in demo_node.mjs. // node demo_problems.mjs > demo/problems.json import { PRESETS } from "../../site/static/demo-data/js/presets.js"; import { bearings, windowRows, problemOf } from "../../site/static/demo-data/js/scenario.js"; @@ -10,10 +12,10 @@ export function goldenCases() { // spec 035's presets only: a later preset (golden: false) would change the problems' digest // that the golden files bind for (const p of PRESETS.filter((q) => q.golden !== false)) { - for (const sigma of [1, 0]) out.push({ id: `${p.id}-s${sigma}`, sc: { ...p.scenario, sigma_deg: sigma } }); + for (const sigma of [1, 0]) out.push({ id: `${p.id}-s${sigma}`, sc: { ...p.scenario, sigma_deg: sigma, turn_loss_s: null } }); } const tt = PRESETS.find((p) => p.id === "target-turn").scenario; - out.push({ id: "target-turn-first-leg", sc: { ...tt, window: { start_s: 0, end_s: 3500 } } }); + out.push({ id: "target-turn-first-leg", sc: { ...tt, window: { start_s: 0, end_s: 3500 }, turn_loss_s: null } }); return out.map(({ id, sc }) => { const b = bearings(sc); const { problem } = problemOf(sc, b, windowRows(sc, b)); diff --git a/schema/tma.yaml b/schema/tma.yaml index a5984781..e383069e 100644 --- a/schema/tma.yaml +++ b/schema/tma.yaml @@ -6,7 +6,7 @@ description: >- principle I). Frame: local flat-earth Cartesian, x east, y north, metres, origin at ownship's window-start position. Bearings and courses are true, clockwise from north, radians in [0, 2π). Speeds in m/s. Times in seconds since window start. All stored floats are float32-rounded. -version: 0.39.0 +version: 0.40.0 license: Apache-2.0 prefixes: linkml: https://w3id.org/linkml/ @@ -2205,6 +2205,7 @@ classes: target: { range: DemoTrack, required: true, inlined: true } sigma_deg: { range: float, required: true, minimum_value: 0, maximum_value: 5, description: "Standard deviation of the zero-mean Gaussian bearing noise (FR-011)." } interval_s: { range: float, required: true, minimum_value: 1, maximum_value: 120, description: "Bearing sample interval (FR-010)." } + turn_loss_s: { range: float, minimum_value: 0, maximum_value: 1800, description: "Owner 2026-11-22: bearings are lost while ownship turns and for this many seconds after each turn ends (default 120); null keeps every bearing." } seed: { range: integer, required: true, minimum_value: 0, maximum_value: 4294967295, description: "Seed of the noise generator; the same seed and scenario give identical bearings." } window: { range: DemoWindow, required: true, inlined: true } solver: { range: string, required: true, description: "Name of the selected solver plug-in (FR-024)." } @@ -2228,6 +2229,7 @@ classes: own_course_rad: { range: float, multivalued: true, description: "Ownship course at each bearing (the learned model reads ownship legs from it)." } own_speed_mps: { range: float, multivalued: true } sigma_rad: { range: float, required: true } + bearing_valid: { range: integer, multivalued: true, description: "1 where the bearing was received, 0 where it was lost (an ownship turn and its tail); absent: every bearing received. Lost rows keep their place so the time grid stays regular." } knots: { range: DemoSpan, multivalued: true, inlined_as_list: true, description: "Manoeuvre spans a solver may use when it accepts knots (the oracle is told the truth's)." } TmaSolution: diff --git a/scripts/research/demo_charts.mjs b/scripts/research/demo_charts.mjs index 10dfc02c..b4bb1e22 100644 --- a/scripts/research/demo_charts.mjs +++ b/scripts/research/demo_charts.mjs @@ -28,7 +28,8 @@ async function run(name, feeds) { return o; } const commit = execSync("git rev-parse HEAD", { cwd: root }).toString().trim(); -const preset = (id) => clone(PRESETS.find((p) => p.id === id).scenario); +// spec 035's figures kept every bearing (before the owner's 2026-11-22 turn loss): pinned here +const preset = (id) => ({ ...clone(PRESETS.find((p) => p.id === id).scenario), turn_loss_s: null }); async function solve(sc, name) { const b = bearings(sc), rows = windowRows(sc, b); const { problem, origin, t0 } = problemOf(sc, b, rows); diff --git a/scripts/research/demo_splitters.mjs b/scripts/research/demo_splitters.mjs index ed3ce96b..efad88b2 100644 --- a/scripts/research/demo_splitters.mjs +++ b/scripts/research/demo_splitters.mjs @@ -37,7 +37,8 @@ async function run(name, feeds) { return o; } const commit = execSync("git rev-parse HEAD", { cwd: root }).toString().trim(); -const preset = (id) => clone(PRESETS.find((p) => p.id === id).scenario); +// spec 036's readings kept every bearing (before the owner's 2026-11-22 turn loss): pinned here +const preset = (id) => ({ ...clone(PRESETS.find((p) => p.id === id).scenario), turn_loss_s: null }); async function trial(sc, name) { const b = bearings(sc), rows = windowRows(sc, b); diff --git a/site/blog/2026-11-21-leg-splitters-kickoff.md b/site/blog/2026-11-21-leg-splitters-kickoff.md index 4eafe53d..02e2e4f4 100644 --- a/site/blog/2026-11-21-leg-splitters-kickoff.md +++ b/site/blog/2026-11-21-leg-splitters-kickoff.md @@ -76,3 +76,20 @@ This is spec 036. hover tooltips on squares and circles say the same. - Schema 0.39.0: `TmaSolution.splitter_ownship_spans`, and the `DemoSplitterInfo` flags `detects_target` and `detects_ownship`. + +## 2026-11-22: bearings lost in ownship's turns + +The owner noted that bearings are lost while ownship turns and for two minutes after each turn +ends. The demonstrator now drops them by default. A scenario's `turn_loss_s` sets the tail +(120 s); null keeps every bearing, and a checkbox under the noise controls turns the loss off. +Lost bearings keep their rows, flagged in the problem's `bearing_valid` (schema 0.40.0), so every +solver and splitter keeps its regular time grid and skips them, as Python's `valid` column does. +Least squares, the physics layer, C, the arctan splitters and the learned model's inputs all +ignore them, and the plot, bearings chart and residuals hide them. The noise is still drawn for +every row, so the bearings that are kept do not change. On the good-geometry preset, 120 of +1,429 bearings are lost (three turns of 1 to 1.5 minutes, each plus two minutes). + +Spec 035's golden problems and spec 036's readings and figures kept every bearing, so their +scripts and tests pin `turn_loss_s: null`. With the loss on, joined legs on the two-turn preset +places the first turn at 50 min instead of 46.5 on seed 1, outside the 120 s match. Seeds 2, 3 +and 5 still find both turns. This is one draw, not a result. diff --git a/site/src/pages/demo.js b/site/src/pages/demo.js index 0b287178..44319c98 100644 --- a/site/src/pages/demo.js +++ b/site/src/pages/demo.js @@ -9,7 +9,7 @@ import useBaseUrl from "@docusaurus/useBaseUrl"; import BrowserOnly from "@docusaurus/BrowserOnly"; import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; import * as T from "../../static/demo-data/js/track.js"; -import { bearings, windowRows, problemOf, targetManoeuvresIn, ownTurnsIn, SCHEMA_VERSION } from "../../static/demo-data/js/scenario.js"; +import { bearings, windowRows, problemOf, targetManoeuvresIn, ownTurnsIn, validCount, TURN_LOSS_S, SCHEMA_VERSION } from "../../static/demo-data/js/scenario.js"; import { evaluate, observability, compareLegs, OBS_GREEN, OBS_AMBER, OBS_SIGMA_DEG } from "../../static/demo-data/js/metrics.js"; import { PRESETS, DEFAULT_SCENARIO, clone, normaliseScenario } from "../../static/demo-data/js/presets.js"; import { SOLVER_LIST, SPLITTER_LIST } from "../../static/demo-data/js/solver-info.js"; @@ -284,11 +284,12 @@ function Demo() { const derived = useMemo(() => { const b = bearings(sc); const rows = windowRows(sc, b); - if (rows.length < 4) return { b, rows, problem: null }; + const received = validCount(b, rows); + if (received < 4) return { b, rows, received, problem: null }; const { problem, origin, t0 } = problemOf(sc, b, rows); const kn = targetManoeuvresIn(sc, b); const obs = observability(sc, b, rows, kn); - return { b, rows, problem, origin, t0, kn, obs, ownTurns: ownTurnsIn(sc, b) }; + return { b, rows, received, problem, origin, t0, kn, obs, ownTurns: ownTurnsIn(sc, b) }; }, [sc]); const info = SOLVER_LIST.find((s) => s.name === sc.solver) || SOLVER_LIST[0]; const splitterName = sc.splitter || "none"; @@ -616,6 +617,7 @@ function Demo() { const step = Math.max(1, Math.ceil(b.n / 48)); const bearingLines = []; for (let i = 0; i < b.n; i += step) { + if (!b.valid[i]) continue; // lost in ownship's turn const r = Math.hypot(b.tx[i] - b.ox[i], b.ty[i] - b.oy[i]) * 1.15; const x1 = b.ox[i] + r * Math.sin(b.z[i]), y1 = b.oy[i] + r * Math.cos(b.z[i]); bearingLines.push(); @@ -795,14 +797,16 @@ function Demo() { if (ev || derived.problem) { // bearings drawn around their circular mean, so a track across north does not jump 360° let cs = 0, cc = 0; - for (let i = 0; i < b.n; i++) { cs += Math.sin(b.z[i]); cc += Math.cos(b.z[i]); } + for (let i = 0; i < b.n; i++) if (b.valid[i]) { cs += Math.sin(b.z[i]); cc += Math.cos(b.z[i]); } const mean = Math.atan2(cs, cc); const unwrap = (z) => (mean + Math.atan2(Math.sin(z - mean), Math.cos(z - mean))) / DEG; - const meas = Array.from(b.t, (t, i) => [t, unwrap(b.z[i])]); + const meas = []; + for (let i = 0; i < b.n; i++) if (b.valid[i]) meas.push([b.t[i], unwrap(b.z[i])]); + const lostMarks = b.lost.map(([a, e]) => [a, Math.min(e, period), "#d0d0d0"]); const pred = ev ? ev.predicted.map(([t, z]) => [t, unwrap(z)]) : []; const res = ev ? ev.residual : []; brgChart = { - bearings: (w, h) => (inWin(p[0]) ? "#8c8c00" : "#bbb") }, { points: pred, colour: EST, width: 1.5 }]} marks={[[win.start_s, win.end_s, "#2ca02c"], ...trueMarks, ...foundMarks]} />, + bearings: (w, h) => (inWin(p[0]) ? "#8c8c00" : "#bbb") }, { points: pred, colour: EST, width: 1.5 }]} marks={[[win.start_s, win.end_s, "#2ca02c"], ...lostMarks, ...trueMarks, ...foundMarks]} />, residuals: (w, h) => , }; } @@ -990,7 +994,7 @@ function Demo() {
- Analysis window {fmtMin(win.start_s)} – {fmtMin(Math.min(win.end_s, period))} of {fmtMin(period)} (min:s); {derived.rows.length} bearings go to the solver. Drag either end; the solve runs on release. + Analysis window {fmtMin(win.start_s)} – {fmtMin(Math.min(win.end_s, period))} of {fmtMin(period)} (min:s); {derived.received} bearings go to the solver{derived.received < derived.rows.length ? ` (${derived.rows.length - derived.received} lost in ownship's turns)` : ""}. Drag either end; the solve runs on release.
@@ -1009,6 +1013,12 @@ function Demo() { +
diff --git a/site/static/demo-data/demo-scenario.schema.json b/site/static/demo-data/demo-scenario.schema.json index 7f3b7283..d8231373 100644 --- a/site/static/demo-data/demo-scenario.schema.json +++ b/site/static/demo-data/demo-scenario.schema.json @@ -146,6 +146,15 @@ "target": { "$ref": "#/$defs/DemoTrack" }, + "turn_loss_s": { + "description": "Owner 2026-11-22: bearings are lost while ownship turns and for this many seconds after each turn ends (default 120); null keeps every bearing.", + "maximum": 1800, + "minimum": 0, + "type": [ + "number", + "null" + ] + }, "window": { "$ref": "#/$defs/DemoWindow" } @@ -162,5 +171,5 @@ ], "title": "DemoScenario", "type": "object", - "version": "0.39.0" + "version": "0.40.0" } diff --git a/site/static/demo-data/js/metrics.js b/site/static/demo-data/js/metrics.js index f67916a8..3858957f 100644 --- a/site/static/demo-data/js/metrics.js +++ b/site/static/demo-data/js/metrics.js @@ -19,7 +19,7 @@ export const OBS_AMBER = 0.25; // Cramér-Rao bound for the target's track over the window rows, the manoeuvre times known: // parameters are position and velocity at the window start plus one velocity increment at the // middle of each target manoeuvre in the window; information from the window's bearings at the -// truth. Returns per-row sds of range (m), bearing (rad), course (rad) and speed (m/s), and the +// truth (lost bearings, b.valid 0, carry none). Returns per-row sds of range (m), bearing (rad), course (rad) and speed (m/s), and the // condition number of the scaled information. export function crb(b, rows, knotsAbs, sigma) { const t0 = b.t[rows[0]]; @@ -29,6 +29,7 @@ export function crb(b, rows, knotsAbs, sigma) { const row = new Float64Array(P); const w = 1 / (sigma * sigma); for (const i of rows) { + if (b.valid && !b.valid[i]) continue; const tau = b.t[i] - t0; const dx = b.tx[i] - b.ox[i], dy = b.ty[i] - b.oy[i]; const r2 = dx * dx + dy * dy; @@ -102,6 +103,7 @@ export function evaluate(sc, b, rows, origin, t0, sol, knotsAbs) { if (i === undefined) continue; const pred = wrap2pi(Math.atan2(out.ex[k] - b.ox[i], out.ey[k] - b.oy[i])); out.predicted.push([out.t[k], pred]); + if (b.valid && !b.valid[i]) continue; // a lost bearing has no residual out.residual.push([out.t[k], sigma > 0 ? wrapPi(b.z[i] - pred) / sigma : NaN]); } const bound = crb(b, rows, knotsAbs, Math.max(sigma, 1e-9)); diff --git a/site/static/demo-data/js/presets.js b/site/static/demo-data/js/presets.js index eb35fcfe..1ba1331b 100644 --- a/site/static/demo-data/js/presets.js +++ b/site/static/demo-data/js/presets.js @@ -1,13 +1,13 @@ // Spec 035 FR-041: preset scenarios (generic and unclassified, NFR-5). Distances in NM from an // arbitrary origin, two-hour engagements, bearings every 5 s at 1 degree. -import { SCHEMA_VERSION } from "./scenario.js"; +import { SCHEMA_VERSION, TURN_LOSS_S } from "./scenario.js"; import { LEGACY_SOLVERS } from "./solver-info.js"; const leg = (course_deg, speed_kt, minutes, turn_rate_dps = 1) => ({ course_deg, speed_kt, duration_s: minutes * 60, turn_rate_dps }); const zigzag = () => ({ start_x_nm: 0, start_y_nm: 0, legs: [leg(0, 8, 30), leg(60, 8, 30), leg(330, 8, 30), leg(60, 8, 30)] }); const base = (name, ownship, target, extra = {}) => ({ schema_version: SCHEMA_VERSION, name, ownship, target, - sigma_deg: 1, interval_s: 5, seed: 1, window: { start_s: 0, end_s: 7140 }, solver: "ls-js", show_ellipses: false, ...extra, + sigma_deg: 1, interval_s: 5, turn_loss_s: TURN_LOSS_S, seed: 1, window: { start_s: 0, end_s: 7140 }, solver: "ls-js", show_ellipses: false, ...extra, }); export const PRESETS = [ @@ -63,5 +63,8 @@ export function normaliseScenario(sc) { out.splitter = splitter; } if (!out.splitter) out.splitter = "none"; + // owner, 2026-11-22: bearings are lost in ownship's turns and two minutes after; a scenario + // saved before then takes the default + if (out.turn_loss_s === undefined) out.turn_loss_s = TURN_LOSS_S; return out; } diff --git a/site/static/demo-data/js/scenario.js b/site/static/demo-data/js/scenario.js index 32fe4460..a4b86cb9 100644 --- a/site/static/demo-data/js/scenario.js +++ b/site/static/demo-data/js/scenario.js @@ -4,7 +4,21 @@ // same bearings whatever the window. import { buildPath, stateAt, manoeuvres, DEG } from "./track.js"; -export const SCHEMA_VERSION = "0.39.0"; +export const SCHEMA_VERSION = "0.40.0"; + +// Owner, 2026-11-22: bearings are lost while ownship turns and for two minutes after each turn +// is complete. A scenario's turn_loss_s is that tail in seconds (null: bearings kept through +// turns); a scenario without the field takes the default. +export const TURN_LOSS_S = 120; +export const turnLossOf = (sc) => (sc.turn_loss_s === undefined ? TURN_LOSS_S : sc.turn_loss_s); + +// [t0, t1] intervals (s) in which no bearing is received: each ownship course change from its +// start to its end plus the scenario's tail +export function lossIntervals(sc, ownPath) { + const tail = turnLossOf(sc); + if (tail === null || !(tail >= 0)) return []; + return manoeuvres(ownPath).filter((m) => m.course).map((m) => [m.t0, m.t1 + tail]); +} const TWO_PI = 2 * Math.PI; export const wrap2pi = (a) => { const w = a % TWO_PI; @@ -58,6 +72,8 @@ export function period(sc, paths = null) { } // The whole scenario's truth and bearings: arrays over t = 0, dt, ... up to the period. +// `valid[i]` is 0 where the bearing is lost (an ownship turn and its tail); the noise is drawn +// for every row all the same, so the kept bearings do not change with the loss setting. export function bearings(sc) { const own = buildPath(sc.ownship), tgt = buildPath(sc.target); const T = Math.min(own.end, tgt.end); @@ -70,6 +86,7 @@ export function bearings(sc) { t: new Float64Array(n), z: new Float64Array(n), truth: new Float64Array(n), ox: new Float64Array(n), oy: new Float64Array(n), ovx: new Float64Array(n), ovy: new Float64Array(n), tx: new Float64Array(n), ty: new Float64Array(n), tvx: new Float64Array(n), tvy: new Float64Array(n), + valid: new Uint8Array(n).fill(1), lost: lossIntervals(sc, own), }; for (let i = 0; i < n; i++) { const t = i * dt; @@ -80,11 +97,13 @@ export function bearings(sc) { const b = wrap2pi(Math.atan2(q.x - o.x, q.y - o.y)); out.truth[i] = b; out.z[i] = wrap2pi(b + sig * g.gauss()); + for (const [a, e] of out.lost) if (t >= a - 1e-9 && t <= e + 1e-9) out.valid[i] = 0; } return out; } -// indices of the bearings inside the window [start, end] +// indices of the bearing rows inside the window [start, end]; lost bearings keep their row (the +// solvers' grids are regular) and are flagged invalid in the problem export function windowRows(sc, b) { const a = Math.max(0, sc.window.start_s), e = Math.min(sc.window.end_s, b.period); const rows = []; @@ -103,7 +122,7 @@ export function problemOf(sc, b, rows) { const p = { t_s: new Array(n), bearing_rad: new Array(n), own_x_m: new Array(n), own_y_m: new Array(n), own_course_rad: new Array(n), own_speed_mps: new Array(n), - sigma_rad: sc.sigma_deg * DEG, knots: [], + sigma_rad: sc.sigma_deg * DEG, knots: [], bearing_valid: new Array(n), }; rows.forEach((i, k) => { p.t_s[k] = b.t[i] - t0; @@ -112,6 +131,7 @@ export function problemOf(sc, b, rows) { p.own_y_m[k] = b.oy[i] - origin[1]; p.own_course_rad[k] = wrap2pi(Math.atan2(b.ovx[i], b.ovy[i])); p.own_speed_mps[k] = Math.hypot(b.ovx[i], b.ovy[i]); + p.bearing_valid[k] = b.valid[i]; }); const tEnd = b.t[rows[n - 1]]; for (const m of manoeuvres(b.paths.tgt)) { @@ -135,3 +155,10 @@ export function ownTurnsIn(sc, b) { const a = sc.window.start_s, e = Math.min(sc.window.end_s, b.period); return manoeuvres(b.paths.own).filter((m) => m.course && m.t1 >= a && m.t0 <= e); } + +// the number of bearings received (not lost) among `rows` +export function validCount(b, rows) { + let n = 0; + for (const i of rows) n += b.valid[i]; + return n; +} diff --git a/site/static/demo-data/js/solver-info.js b/site/static/demo-data/js/solver-info.js index 336df80f..7a1033d5 100644 --- a/site/static/demo-data/js/solver-info.js +++ b/site/static/demo-data/js/solver-info.js @@ -14,7 +14,7 @@ export const INFO = { export const SOLVER_LIST = [INFO.lsJs, INFO.layer, INFO.tlm1, INFO.tlm2, INFO.tlm3]; export const LEGACY_SOLVERS = { "layer-cv": ["layer", "none"], "layer-oracle": ["layer", "truth"] }; -// Spec 036: the leg splitters (DemoSplitterInfo, schema 0.38.0) +// Spec 036: the leg splitters (DemoSplitterInfo, schema 0.39.0) export const SPLITTER_INFO = { none: { name: "none", label: "None (one leg)", version: "none", assumptions: "No manoeuvre: one constant-velocity leg over the window.", told_truth: false, detects_target: false, detects_ownship: false }, truth: { name: "truth", label: "Told the true manoeuvres (oracle)", version: "truth", assumptions: "The page tells it the target's true manoeuvre spans and their kinds (a course-only change gets the layer's speed-continuity prior; a speed change does not): a ceiling for any splitter, not a system. Every other splitter's spans are treated as course changes, C's convention.", told_truth: true, detects_target: true, detects_ownship: false }, diff --git a/site/static/demo-data/js/solvers.js b/site/static/demo-data/js/solvers.js index fb64e983..98f2a554 100644 --- a/site/static/demo-data/js/solvers.js +++ b/site/static/demo-data/js/solvers.js @@ -12,6 +12,9 @@ import * as TLM from "./tlm.js"; const DEG = Math.PI / 180; const MIN_SIGMA = 0.1 * DEG; // the physics layer's and C's floor: a noise-free run still divides by sigma +// bearings received among the problem's rows (spec 035 problems without the flag: all of them) +const nValid = (p) => (p.bearing_valid ? p.bearing_valid.reduce((a, v) => a + (v ? 1 : 0), 0) : p.t_s.length); + const now = () => (typeof performance !== "undefined" ? performance.now() : Date.now()); // the problem as spec 021's scenario arrays, every `stride`-th bearing @@ -23,6 +26,7 @@ function scenarioArrays(p, stride = 1, sigmaFloor = 0) { const s = { n, t: new Float64Array(n), ox: new Float64Array(n), oy: new Float64Array(n), z: new Float64Array(n), valid: new Uint8Array(n).fill(1), course: new Float64Array(n), speed: new Float64Array(n), sigma: Math.max(p.sigma_rad, sigmaFloor), zigIndex: 0, idx }; idx.forEach((i, k) => { s.t[k] = p.t_s[i]; + if (p.bearing_valid) s.valid[k] = p.bearing_valid[i] ? 1 : 0; s.ox[k] = p.own_x_m[i]; s.oy[k] = p.own_y_m[i]; s.z[k] = p.bearing_rad[i]; @@ -41,6 +45,7 @@ function cvInformation(p, th, sigma) { const I = Array.from({ length: 4 }, () => new Float64Array(4)); const w = 1 / (sigma * sigma); for (let i = 0; i < p.t_s.length; i++) { + if (p.bearing_valid && !p.bearing_valid[i]) continue; const t = p.t_s[i]; const dx = th[0] + th[2] * t - p.own_x_m[i], dy = th[1] + th[3] * t - p.own_y_m[i]; const r2 = dx * dx + dy * dy; @@ -68,7 +73,7 @@ export const lsJs = { async solve(p) { const t0 = now(); const s = scenarioArrays(p); - if (s.n < 4) return failed(this.info, t0, "fewer than four bearings in the window"); + if (nValid(p) < 4) return failed(this.info, t0, "fewer than four bearings in the window"); const r = solveBatch(s, s.n); if (r === null || !Array.from(r.theta).every(Number.isFinite)) return failed(this.info, t0, "no solution"); const th = r.theta; @@ -110,7 +115,7 @@ function layerSolver(mode) { const stride = Math.max(1, Math.ceil(p.t_s.length / ROWS)); const s = scenarioArrays(p, stride, MIN_SIGMA); if (s.n > ROWS) return failed(info, t0, "too many bearings for the graph"); - if (s.n < 4) return failed(info, t0, "fewer than four bearings in the window"); + if (nValid(p) < 4) return failed(info, t0, "fewer than four bearings in the window"); const k = s.n - 1; let trs = []; let courseOnly = null; @@ -182,8 +187,9 @@ function tlmSolver(seed) { const dt = n > 1 ? p.t_s[1] - p.t_s[0] : 0; if (Math.abs(dt - TLM.DT) > 1e-6) return failed(info, t0, "the learned model reads 5-second bearings: set the interval to 5 s"); if (n > TLM.MAX_ROWS) return failed(info, t0, "the learned model reads at most two hours (1,440 bearings): narrow the window"); - if (n < 2 * TLM.PATCH) return failed(info, t0, "fewer than twelve bearings in the window"); - const { f, mask, th } = TLM.periodFeatures(p.t_s, p.own_x_m, p.own_y_m, p.bearing_rad, Math.max(p.sigma_rad, 1e-6)); + if (n < 2 * TLM.PATCH || nValid(p) < 2 * TLM.PATCH) return failed(info, t0, "fewer than twelve bearings in the window"); + const valid = p.bearing_valid || new Uint8Array(n).fill(1); + const { f, mask, th } = TLM.periodFeatures(p.t_s, p.own_x_m, p.own_y_m, p.bearing_rad, Math.max(p.sigma_rad, 1e-6), valid); if (ctx.progress) ctx.progress({ stage: "running the network" }); const o = await ctx.run(`tlm-s${seed}`, { features: { dtype: "float32", shape: [1, TLM.MAX_ROWS, TLM.N_FEATURES], data: f }, @@ -194,7 +200,7 @@ function tlmSolver(seed) { const mean = []; for (let j = 0; j < T; j++) mean.push([o.mean[3 * j], o.mean[3 * j + 1], o.mean[3 * j + 2]]); if (!mean.flat().every(Number.isFinite)) return failed(info, t0, "non-finite output"); - const tr = TLM.directTrack(mean, p.own_x_m, p.own_y_m, p.bearing_rad, th); + const tr = TLM.directTrack(mean, p.own_x_m, p.own_y_m, p.bearing_rad, th, valid); const out = { solver: info.name, solver_version: info.version, status: "converged", t_s: [], x_m: [], y_m: [], vx_mps: [], vy_mps: [] }; for (let k = 0; k < n; k++) { out.t_s.push(p.t_s[k]); diff --git a/site/static/demo-data/js/splitters.js b/site/static/demo-data/js/splitters.js index 102eceec..155ea7a1 100644 --- a/site/static/demo-data/js/splitters.js +++ b/site/static/demo-data/js/splitters.js @@ -1,7 +1,7 @@ // Spec 036: the demonstrator's leg splitters. A splitter reads the window's bearings and ownship's // track and states where it thinks the target manoeuvred, as time spans; a TMA solver that accepts // knots (the ONNX physics layer) then fits constant-velocity legs joined across those spans. -// Each splitter declares a DemoSplitterInfo (schema 0.38.0) and `split(problem, ctx)` → +// Each splitter declares a DemoSplitterInfo (schema 0.39.0) and `split(problem, ctx)` → // {spans: [{start_s, end_s, stat}], rows_dt_s, runtime_ms, message}. // // Only the "truth" splitter is shown the problem's true manoeuvre spans; the worker strips them @@ -33,6 +33,7 @@ export function splitterArrays(p, targetDt = 10, maxRows = ROWS) { const s = { n, stride, idx, t: new Float64Array(n), ox: new Float64Array(n), oy: new Float64Array(n), z: new Float64Array(n), valid: new Uint8Array(n).fill(1), course: new Float64Array(n), speed: new Float64Array(n), sigma: Math.max(p.sigma_rad, MIN_SIGMA), zigIndex: 0 }; idx.forEach((i, k) => { s.t[k] = p.t_s[i]; + if (p.bearing_valid) s.valid[k] = p.bearing_valid[i] ? 1 : 0; s.ox[k] = p.own_x_m[i]; s.oy[k] = p.own_y_m[i]; s.z[k] = p.bearing_rad[i]; diff --git a/site/static/demo-data/js/tlm.js b/site/static/demo-data/js/tlm.js index 66f0b1a1..9a63668a 100644 --- a/site/static/demo-data/js/tlm.js +++ b/site/static/demo-data/js/tlm.js @@ -12,25 +12,33 @@ const DEG = Math.PI / 180; const L_UNIT = 1.0e4, V_UNIT = 10.0, D_UNIT = 100.0, T_UNIT = 7200.0; const SMOOTH_ROWS = 7; -// [MAX_ROWS * 9] float32 features and the [MAX_ROWS] row mask; every bearing is valid here -export function periodFeatures(t, ox, oy, z, sigma) { +// [MAX_ROWS * 9] float32 features and the [MAX_ROWS] row mask (frame.features): a row without a +// bearing (`valid[k]` 0, a bearing lost in ownship's turn) keeps its ownship and time features and +// zeros its bearing features; the frame turns to the first valid bearing +const allValid = (n) => new Uint8Array(n).fill(1); +export function firstValid(z, valid) { + for (let k = 0; k < z.length; k++) if (valid[k]) return z[k]; + return 0; +} +export function periodFeatures(t, ox, oy, z, sigma, valid = allValid(t.length)) { const n = t.length; const f = new Float32Array(MAX_ROWS * N_FEATURES); const mask = new Uint8Array(MAX_ROWS); - const th = z[0]; + const th = firstValid(z, valid); const c = Math.cos(th), s = Math.sin(th); const lsig = Math.log(Math.max(sigma, 1e-6) / DEG); for (let k = 0; k < n; k++) { const tk = k * DT; // the model's clock: rows from 0 at its own spacing const dx = k ? ox[k] - ox[k - 1] : 0, dy = k ? oy[k] - oy[k - 1] : 0; const dt = k ? tk - (k - 1) * DT : 0; + const ok = valid[k] ? 1 : 0; const b = z[k] - th; const o = k * N_FEATURES; - f[o] = Math.sin(b); - f[o + 1] = Math.cos(b); + f[o] = Math.sin(b) * ok; + f[o + 1] = Math.cos(b) * ok; f[o + 2] = (dx * c - dy * s) / D_UNIT; f[o + 3] = (dy * c + dx * s) / D_UNIT; - f[o + 4] = 1; + f[o + 4] = ok; f[o + 5] = lsig; f[o + 6] = dt / 10.0; f[o + 7] = tk / T_UNIT; @@ -60,11 +68,16 @@ function unwrap(z) { return out; } -// learned.smoothed_bearing with every bearing valid: unwrap, then a centred running median of -// seven rows with the ends repeated -export function smoothedBearing(z) { - const u = unwrap(z); - const h = SMOOTH_ROWS >> 1, n = u.length; +// learned.smoothed_bearing: valid bearings unwrapped, interpolated over the rows without one, +// then a centred running median of seven rows with the ends repeated +export function smoothedBearing(z, valid = allValid(z.length)) { + const n = z.length; + const ks = []; + for (let k = 0; k < n; k++) if (valid[k]) ks.push(k); + if (!ks.length) return new Float64Array(n).fill(NaN); + const uk = unwrap(Float64Array.from(ks, (k) => z[k])); + const u = ks.length === n ? uk : interp(n, ks, Array.from(uk)); + const h = SMOOTH_ROWS >> 1; const out = new Float64Array(n); const win = new Float64Array(SMOOTH_ROWS); for (let i = 0; i < n; i++) { @@ -90,7 +103,7 @@ function interp(n, xs, ys) { // learned.direct_track: the model's own track at every row (x, y, vx, vy), from its per-token // means ([T][3]); position is the stated range along the smoothed measured bearing -export function directTrack(mean, ox, oy, z, th) { +export function directTrack(mean, ox, oy, z, th, valid = allValid(z.length)) { const n = z.length; const last = tokenRows(n); const col = (c) => last.map((_, j) => mean[j][c]); @@ -100,7 +113,7 @@ export function directTrack(mean, ox, oy, z, th) { for (let k = 0; k < last[0]; k++) lnR[k] = mean[0][0] + slope * (k - last[0]); } const c = Math.cos(th), s = Math.sin(th); - const zs = smoothedBearing(z); + const zs = smoothedBearing(z, valid); const out = []; for (let k = 0; k < n; k++) { const r = L_UNIT * Math.exp(lnR[k]); diff --git a/src/tma2/types/generated/tma.py b/src/tma2/types/generated/tma.py index e470a8cc..31ae8ba8 100644 --- a/src/tma2/types/generated/tma.py +++ b/src/tma2/types/generated/tma.py @@ -31,7 +31,7 @@ metamodel_version = "1.12.0" -version = "0.39.0" +version = "0.40.0" class ConfiguredBaseModel(BaseModel): @@ -3993,6 +3993,7 @@ class DemoScenario(ConfiguredBaseModel): target: DemoTrack = Field(default=..., json_schema_extra = { "linkml_meta": {'domain_of': ['Scenario', 'DemoScenario']} }) sigma_deg: float = Field(default=..., description="""Standard deviation of the zero-mean Gaussian bearing noise (FR-011).""", ge=0, le=5, json_schema_extra = { "linkml_meta": {'domain_of': ['DemoScenario']} }) interval_s: float = Field(default=..., description="""Bearing sample interval (FR-010).""", ge=1, le=120, json_schema_extra = { "linkml_meta": {'domain_of': ['DemoScenario']} }) + turn_loss_s: Optional[float] = Field(default=None, description="""Owner 2026-11-22: bearings are lost while ownship turns and for this many seconds after each turn ends (default 120); null keeps every bearing.""", ge=0, le=1800, json_schema_extra = { "linkml_meta": {'domain_of': ['DemoScenario']} }) seed: int = Field(default=..., description="""Seed of the noise generator; the same seed and scenario give identical bearings.""", ge=0, le=4294967295, json_schema_extra = { "linkml_meta": {'domain_of': ['ScenarioMetadata', 'PhysicsModelConfig', 'DetectorConfig', @@ -4034,6 +4035,7 @@ class TmaProblem(ConfiguredBaseModel): own_course_rad: Optional[list[float]] = Field(default=None, description="""Ownship course at each bearing (the learned model reads ownship legs from it).""", json_schema_extra = { "linkml_meta": {'domain_of': ['TmaProblem']} }) own_speed_mps: Optional[list[float]] = Field(default=None, json_schema_extra = { "linkml_meta": {'domain_of': ['TmaProblem']} }) sigma_rad: float = Field(default=..., json_schema_extra = { "linkml_meta": {'domain_of': ['TmaProblem']} }) + bearing_valid: Optional[list[int]] = Field(default=None, description="""1 where the bearing was received, 0 where it was lost (an ownship turn and its tail); absent: every bearing received. Lost rows keep their place so the time grid stays regular.""", json_schema_extra = { "linkml_meta": {'domain_of': ['TmaProblem']} }) knots: Optional[list[DemoSpan]] = Field(default=None, description="""Manoeuvre spans a solver may use when it accepts knots (the oracle is told the truth's).""", json_schema_extra = { "linkml_meta": {'domain_of': ['DetectorConfig', 'KnotSet', 'EModelConfig', diff --git a/src/tma2/types/generated/tma.schema.json b/src/tma2/types/generated/tma.schema.json index 78b4f1ba..bc0e393b 100644 --- a/src/tma2/types/generated/tma.schema.json +++ b/src/tma2/types/generated/tma.schema.json @@ -874,6 +874,15 @@ "target": { "$ref": "#/$defs/DemoTrack" }, + "turn_loss_s": { + "description": "Owner 2026-11-22: bearings are lost while ownship turns and for this many seconds after each turn ends (default 120); null keeps every bearing.", + "maximum": 1800, + "minimum": 0, + "type": [ + "number", + "null" + ] + }, "window": { "$ref": "#/$defs/DemoWindow" } @@ -5788,6 +5797,16 @@ }, "type": "array" }, + "bearing_valid": { + "description": "1 where the bearing was received, 0 where it was lost (an ownship turn and its tail); absent: every bearing received. Lost rows keep their place so the time grid stays regular.", + "items": { + "type": "integer" + }, + "type": [ + "array", + "null" + ] + }, "knots": { "description": "Manoeuvre spans a solver may use when it accepts knots (the oracle is told the truth's).", "items": { @@ -6360,6 +6379,6 @@ ], "title": "tma", "type": "object", - "version": "0.39.0" + "version": "0.40.0" } diff --git a/src/tma2/types/generated/version.py b/src/tma2/types/generated/version.py index c6a41d35..6abc4222 100644 --- a/src/tma2/types/generated/version.py +++ b/src/tma2/types/generated/version.py @@ -1,2 +1,2 @@ # Generated from schema/tma.yaml by scripts/gen_types.py. Do not edit. -SCHEMA_VERSION = "0.39.0" +SCHEMA_VERSION = "0.40.0" diff --git a/tests/unit/test_demo_schema.py b/tests/unit/test_demo_schema.py index 82fabc64..eb0f80db 100644 --- a/tests/unit/test_demo_schema.py +++ b/tests/unit/test_demo_schema.py @@ -30,7 +30,7 @@ def test_pydantic_accepts_a_scenario() -> None: leg = {"course_deg": 10.0, "speed_kt": 8.0, "duration_s": 600.0, "turn_rate_dps": 1.0} sc = DemoScenario.model_validate( { - "schema_version": "0.39.0", + "schema_version": "0.40.0", "ownship": {"start_x_nm": 0.0, "start_y_nm": 0.0, "legs": [leg]}, "target": {"start_x_nm": 1.0, "start_y_nm": 9.0, "legs": [leg]}, "sigma_deg": 1.0, diff --git a/tests/unit/test_types.py b/tests/unit/test_types.py index 893dea46..3015cb72 100644 --- a/tests/unit/test_types.py +++ b/tests/unit/test_types.py @@ -13,7 +13,7 @@ def test_schema_version_reads_gitma_files() -> None: from tma2.data.versions import compatible - assert SCHEMA_VERSION == "0.39.0" + assert SCHEMA_VERSION == "0.40.0" assert compatible("0.16.0", SCHEMA_VERSION)