sessions of 2026-11-18 (the optimization campaign; three runs without summary, interrupted and rerun)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-11-18 17:47:59 +01:00
1 parent 8a81c53cd9
commit 0cfbd1b7bc
363 files changed
+30822

No files matched your search

@@ -0,0 +1,12 @@
#!/bin/bash
# Runs the four checks of the request on the live detectors and writes <name>-<tag>.txt in the session folder, then compares the benchmark against PREV. Args: TAG PREV_BENCHMARK
set -e
R=/home/maxime/aimsight-optimizer; S=$R/sessions/NORDEND_2026-08-17T0515_2026-11-07T1400_20261118T1024Z; TAG=$1; PREV=$2
cd $R
python3 detectors/scripts/categories.py data/NORDEND --from 2026-08-17 --to 2026-11-08 > $S/events-$TAG.txt 2>&1
python3 detectors/bench/sensors.py data/NORDEND --from 2026-08-17 --to 2026-11-08 > $S/sensors-$TAG.txt 2>&1
python3 detectors/bench/score.py data/NORDEND --labels labeling/auto/NORDEND.jsonl --from 2026-08-17 --to 2026-11-08 > $S/range-$TAG.txt 2>&1
python3 detectors/bench/regression.py --labels labeling/auto --data data > $S/benchmark-$TAG.txt 2>&1
python3 detectors/bench/compare.py $PREV $S/benchmark-$TAG.txt > $S/compare-$TAG.txt 2>&1 || true
grep -c skipped $S/events-$TAG.txt $S/benchmark-$TAG.txt || true
cat $S/compare-$TAG.txt
@@ -0,0 +1,22 @@
# Daily median error_value per sensor, and its share of measurements "high" by visibility.py's rule (median + K_MAD MAD and FACTOR x median over the window). Args: station_folder FROM TO sensor[,sensor...]
import sys, statistics
from datetime import datetime, timezone
sys.path[:0] = ["/home/maxime/aimsight-tools/scripts", "/home/maxime/aimsight-detectors/scripts"]
from data import load
from episodes import level
from visibility import K_MAD, FACTOR
folder, a, b, sensors = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4].split(",")
ms = load(folder)
a = datetime.fromisoformat(a).replace(tzinfo=timezone.utc)
b = datetime.fromisoformat(b).replace(tzinfo=timezone.utc)
days, lim = {}, {}
for s in sensors:
v = [m for m in ms.get(s, []) if a <= m["t"] < b and m["error_value"] is not None]
med, mad = level([m["error_value"] for m in v])
lim[s] = max(med + K_MAD * mad, FACTOR * med)
for m in v:
days.setdefault(m["t"].date(), {}).setdefault(s, []).append(m["error_value"])
print("limit " + " ".join(f"{lim[s]:>12.3g}" for s in sensors))
for d in sorted(days):
print(d, " ".join(f"{statistics.median(days[d][s]):7.3g} {100 * sum(x > lim[s] for x in days[d][s]) / len(days[d][s]):3.0f}%" if s in days[d] else " -" for s in sensors))
@@ -0,0 +1,22 @@
# Daily rejection share (error_value > error_threshold) per sensor of a station. Args: station_folder FROM TO sensor[,sensor...]
import sys
from datetime import datetime, timezone
sys.path[:0] = ["/home/maxime/aimsight-tools/scripts", "/home/maxime/aimsight-detectors/scripts"]
from data import load
from target_issue import rejected
folder, a, b, sensors = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4].split(",")
ms = load(folder)
a = datetime.fromisoformat(a).replace(tzinfo=timezone.utc)
b = datetime.fromisoformat(b).replace(tzinfo=timezone.utc)
days = {}
for s in sensors:
for m in ms.get(s, []):
t = m["t"] if m["t"].tzinfo else m["t"].replace(tzinfo=timezone.utc)
if a <= t < b:
c = days.setdefault(t.date(), {}).setdefault(s, [0, 0])
c[0] += rejected(m)
c[1] += 1
print("day " + " ".join(f"{s:>8}" for s in sensors))
for d in sorted(days):
print(d, " ".join(f"{100 * days[d][s][0] / days[d][s][1]:7.0f}%" if s in days[d] else " -" for s in sensors))
@@ -0,0 +1,18 @@
# Raw episodes of one detector module (before categories.py), optionally for one sensor, over a window (FROM minus 3 days history, as score.py). Args: detectors_dir station_folder module FROM TO [sensor]
import sys
from datetime import timedelta
from pathlib import Path
det, folder, mod, a, b = sys.argv[1:6]
sensor = sys.argv[6] if len(sys.argv) > 6 else None
sys.path[:0] = [str(Path(det) / "scripts"), "/home/maxime/aimsight-tools/scripts"]
import importlib
from data import load, parse_time
ms = load(folder)
h, e = parse_time(a) - timedelta(days=3), parse_time(b)
chunk = {s: k for s, l in ms.items() if (k := [m for m in l if h <= m["t"] < e])}
m = importlib.import_module(mod)
eps = m.detect(chunk, e) if mod == "no_data" else m.detect(chunk)
for ep in sorted(eps, key=lambda x: x["start"]):
if sensor and sensor not in ep["sensors"]:
continue
print(ep["start"], ep["end"], ep["kind"], "/", ep["label"], ",".join(ep["sensors"][:5]) if len(ep["sensors"]) < 6 else f"{len(ep['sensors'])} sensors", "|", ep["text"][:100])
@@ -0,0 +1,18 @@
# Lists the labels of a JSONL file touching a range: id, bounds, family, first N chars of description. Args: file FROM TO [N] [family-filter]
import json, sys
f, a, b = sys.argv[1:4]
n = int(sys.argv[4]) if len(sys.argv) > 4 else 120
fam = sys.argv[5] if len(sys.argv) > 5 else None
rows = []
for l in open(f):
l = l.strip()
if not l:
continue
d = json.loads(l)
if d['start'] < b and d['end'] >= a and (not fam or d['family'] == fam):
rows.append(d)
rows.sort(key=lambda d: d['start'])
from collections import Counter
print(Counter(d['family'] for d in rows))
for d in rows:
print(d['id'], d['start'], d['end'], d['family'], '|', d['description'][:n])
@@ -0,0 +1,30 @@
# Label-by-label match: for each label, the detector events overlapping it (family, variety, bounds, sensors); then events overlapping no label. Args: detectors_dir station_folder labels.jsonl FROM TO [family]
import json, sys
from pathlib import Path
det, folder, labels, a, b = sys.argv[1:6]
fam = sys.argv[6] if len(sys.argv) > 6 else None
sys.path.insert(0, str(Path(det) / "bench"))
import score # noqa
from data import load # noqa
ms = load(folder)
evs = score.events(ms, a, b, folder=folder)
labs = [json.loads(l) for l in open(labels) if l.strip()]
labs = [d for d in labs if d["start"] < b and d["end"] >= a]
labs.sort(key=lambda d: d["start"])
def ov(x, y):
return x["start"] <= y["end"] and x["end"] >= y["start"]
for d in labs:
if fam and d["family"] != fam:
continue
hit = [e for e in evs if e["start"] < d["end"] and e["end"] > d["start"]]
print(f"{d['id']} {d['start']}→{d['end']} [{d['family']}]")
for e in hit:
mark = "=" if e["category"] == d["family"] else "x"
lab = e["episodes"][0]["label"]
print(f" {mark} {e['start']}→{e['end']} {e['category']} / {lab} ({len(e['sensors'])}: {','.join(e['sensors'][:6])})")
print("\n# events overlapping no label of their family")
for e in evs:
same = [d for d in labs if d["family"] == e["category"] and d["start"] <= e["end"] and d["end"] >= e["start"]]
if not same and (not fam or e["category"] == fam):
others = [f"{d['id']}:{d['family']}" for d in labs if d["start"] <= e["end"] and d["end"] >= e["start"]]
print(f" {e['start']}→{e['end']} {e['category']} / {e['episodes'][0]['label']} ({len(e['sensors'])}: {','.join(e['sensors'][:6])}) over {' '.join(others) or '-'}")
@@ -0,0 +1,24 @@
# From a match.py output: labels with no overlapping event of their own family, grouped by family, with their duration in h and the other events seen. Args: match.txt
import sys, re
from datetime import datetime
cur, rows = None, []
for line in open(sys.argv[1]):
if line.startswith("#"):
break
m = re.match(r"(\S+) (\S+)→(\S+) \[(.+)\]", line)
if m:
cur = [m.group(1), m.group(2), m.group(3), m.group(4), [], False]
rows.append(cur)
elif cur and line.strip():
cur[4].append(line.strip())
cur[5] |= line.strip().startswith("=")
def h(a, b):
f = lambda s: datetime.strptime(s, "%Y-%m-%dT%H:%MZ")
return (f(b) - f(a)).total_seconds() / 3600
fams = sorted({r[3] for r in rows})
for fam in fams:
miss = [r for r in rows if r[3] == fam and not r[5]]
tot = [r for r in rows if r[3] == fam]
print(f"## {fam}: {len(miss)} of {len(tot)} labels without an event of the family, {sum(h(r[1], r[2]) for r in miss):.0f} h")
for r in miss:
print(f" {r[0]} {r[1]}→{r[2]} ({h(r[1], r[2]):.1f} h) : {' | '.join(x[2:60] for x in r[4][:3])}")
@@ -0,0 +1,27 @@
# Daily share of "own" rejections per sensor: rejected while at most K other sensors are rejected at the same instant. Args: station_folder FROM TO sensor[,sensor...] K
import sys
from datetime import datetime, timezone
sys.path[:0] = ["/home/maxime/aimsight-tools/scripts", "/home/maxime/aimsight-detectors/scripts"]
from data import load
from target_issue import rejected
folder, a, b, sensors, k = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4].split(","), int(sys.argv[5])
ms = load(folder)
a = datetime.fromisoformat(a).replace(tzinfo=timezone.utc)
b = datetime.fromisoformat(b).replace(tzinfo=timezone.utc)
at = {}
for s, l in ms.items():
for m in l:
if rejected(m):
at[m["t"]] = at.get(m["t"], 0) + 1
days = {}
for s in sensors:
for m in ms.get(s, []):
t = m["t"]
if a <= t < b:
c = days.setdefault(t.date(), {}).setdefault(s, [0, 0])
c[0] += rejected(m) and at[t] - 1 <= k
c[1] += 1
print("day " + " ".join(f"{s:>8}" for s in sensors))
for d in sorted(days):
print(d, " ".join(f"{100 * days[d][s][0] / days[d][s][1]:7.0f}%" if s in days[d] else " -" for s in sensors))
@@ -0,0 +1,7 @@
# Replaces exactly one occurrence of OLD by NEW in FILE (fails if OLD is absent or not unique). Args: FILE OLD NEW
import sys
f, old, new = sys.argv[1:4]
s = open(f).read()
if s.count(old) != 1:
sys.exit(f"replace.py: {old!r} found {s.count(old)} times in {f}")
open(f, "w").write(s.replace(old, new))
@@ -0,0 +1,16 @@
#!/bin/bash
# Copies the detectors to WORK/<name>, applies a python replacement (file, old, new) given as triples, then runs the NORDEND range score and the full benchmark of the copy into WORK/<name>/{range,bench}.txt. Args: WORK name [file old new]...
set -e
W=$1; N=$2; shift 2
R=/home/maxime/aimsight-optimizer
rm -rf "$W/$N"; mkdir -p "$W/$N"
cp -r /home/maxime/aimsight-detectors/scripts /home/maxime/aimsight-detectors/bench "$W/$N/"
rm -rf "$W/$N"/*/__pycache__
while [ $# -ge 3 ]; do
python3 "$R/sessions/NORDEND_2026-08-17T0515_2026-11-07T1400_20261118T1024Z/tools/replace.py" "$W/$N/scripts/$1" "$2" "$3"
shift 3
done
cd "$R"
python3 "$W/$N/bench/score.py" data/NORDEND --labels labeling/auto/NORDEND.jsonl --from 2026-08-17 --to 2026-11-08 > "$W/$N/range.txt" 2>&1
python3 "$W/$N/bench/regression.py" --labels labeling/auto --data data > "$W/$N/bench.txt" 2>&1
echo "done $N"