hillclimb · run 1 · done (iteration budget reached (10)) · updated 2026-11-27 00:45

herd-alert-rule

Lower the false-alarm rate of a dairy-herd illness alert rule: false alarms per 100 healthy animal-weeks, measured at a fixed 80% early recall. Read README.md for the data and the rules of the scorer, then improve risk() in alert_rule.py. Ideas must generalize to a different herd on a different farm.

Dev score
55.94 → 1.04
-98.1% · lower is better
Held-out score
49.74 → 2.35
-95.3% · never shown to the agent
Experiments
10
5 accepted · 5 rejected · 0 errors
Time & cost
1.9 min
agent cost $0.44 as reported by the backend

Score over time

02040600123456789experiments, in the order they finished #1 accepted 13.062#2 rejected 41.7889#3 accepted 9.0393#4 rejected 12.5414#5 accepted 6.2944#7 rejected 5.8211#6 accepted 1.4198#8 rejected 6.1051#9 accepted 1.0412
best dev score so farheld-out score of the bestacceptedrejected

Accepted changes (5)

#1 · Replace the 7-day mean/stdev rumination z-score with a 14-day median/MAD baseline that skips partial-coverage days (<0.6) and sums clipped z-scores of rumination, activity and lying.

dev 55.9394 → 13.062held-out 49.7365 → 18.5913alert_rule.py +21 -20 agent 12s

The dev score went from 55.94 to 13.06 false alarms per 100 healthy animal-weeks, at early recall 0.803 over 71 episodes. I didn't run an ablation, so I can't say how much comes from the robust baseline, the coverage filter or the extra signals. I haven't checked held-out data.

Diff
diff --git a/alert_rule.py b/alert_rule.pyindex 9c6ea7a..232cbbb 100644--- a/alert_rule.py+++ b/alert_rule.py@@ -1,26 +1,27 @@-"""The alert rule Hillclimb is allowed to change.+"""Robust per-animal baseline, multi-signal, coverage-aware.""" 
-risk(history, today, herd) -> float. Higher means more likely to be getting sick.--  history: this animal's previous days, oldest first (at most 60), each a dict-           with keys animal, day, weekday, temp_c, activity, rumination, lying, coverage.-           Sensor values are None on days the collar reported nothing.-  today:   the same dict for today.-  herd:    today's dicts for every animal in the herd (including this one).+import statistics 
-Baseline: how far today's rumination has dropped below this animal's mean-over the previous 7 days, in units of its standard deviation.-""" 
-import statistics+def _z(history, today, key, sign, n=14):+    v = today[key]+    if v is None or today["coverage"] < 0.6:+        return None+    vals = [h[key] for h in history[-n:] if h[key] is not None and h["coverage"] >= 0.6]+    if len(vals) < 4:+        return None+    med = statistics.median(vals)+    mad = statistics.median([abs(x - med) for x in vals]) * 1.4826+    sd = max(mad, 0.3 * (statistics.pstdev(vals) or 1.0), 1e-6)+    return sign * (med - v) / sd 
 
 def risk(history, today, herd):
-    if today["rumination"] is None:-        return 0.0-    recent = [h["rumination"] for h in history[-7:] if h["rumination"] is not None]-    if len(recent) < 3:-        return 0.0-    mean = statistics.fmean(recent)-    sd = statistics.stdev(recent) or 1.0-    return (mean - today["rumination"]) / sd+    zs = [_z(history, today, "rumination", 1), _z(history, today, "activity", 1),+          _z(history, today, "lying", -1)]+    w = [1.0, 0.5, 0.5]+    tot = 0.0+    for z, wi in zip(zs, w):+        if z is not None:+            tot += wi * max(min(z, 6.0), -3.0)+    return tot

#3 · Add 0.6 times yesterday's multi-signal score (computed from history before yesterday) to today's score, so persistent multi-day deviations count more than one-day blips.

dev 13.062 → 9.0393held-out 18.5913 → 12.5539alert_rule.py +7 -0 agent 13s

Dev score went from 13.062 to 9.039 false alarms per 100 healthy animal-weeks, at early recall 0.803 over 71 episodes. That is an improvement of about 4, well above the 0.25 threshold. I tried only the 0.6 weight, so it isn't tuned, and I haven't checked held-out data.

Diff
diff --git a/alert_rule.py b/alert_rule.pyindex 232cbbb..dae953f 100644--- a/alert_rule.py+++ b/alert_rule.py@@ -17,6 +17,13 @@ def _z(history, today, key, sign, n=14): 
 
 def risk(history, today, herd):
+    t = _score(history, today)+    if len(history) >= 5:+        t += 0.6 * _score(history[:-1], history[-1])+    return t+++def _score(history, today):     zs = [_z(history, today, "rumination", 1), _z(history, today, "activity", 1),
           _z(history, today, "lying", -1)]
     w = [1.0, 0.5, 0.5]

#5 · Compute each animal's median/MAD baseline from days 3–16 back, skipping the most recent 2 days, so the onset of illness doesn't contaminate its own baseline.

dev 9.0393 → 6.2944held-out 12.5539 → 10.1581alert_rule.py +1 -1 agent 13s

Dev score fell from 9.0393 to 6.2944 false alarms per 100 healthy animal-weeks, at early recall 0.8028 over 71 episodes. That is a drop of about 2.7, above the 0.25 threshold. I tried only a 2-day gap and didn't tune it. I haven't checked held-out data.

Diff
diff --git a/alert_rule.py b/alert_rule.pyindex dae953f..a719ab7 100644--- a/alert_rule.py+++ b/alert_rule.py@@ -7,7 +7,7 @@ def _z(history, today, key, sign, n=14):     v = today[key]
     if v is None or today["coverage"] < 0.6:
         return None
-    vals = [h[key] for h in history[-n:] if h[key] is not None and h["coverage"] >= 0.6]+    vals = [h[key] for h in history[-n - 2:-2] if h[key] is not None and h["coverage"] >= 0.6]     if len(vals) < 4:
         return None
     med = statistics.median(vals)

#6 · Subtract the herd-wide median of today's per-animal multi-signal score from each animal's score, and do the same for yesterday's term. Weather and management shifts that hit the whole herd then cancel out, and only animal-specific deviations raise an alert.

dev 6.2944 → 1.4198held-out 10.1581 → 2.4916alert_rule.py +22 -2 agent 22s

The dev score went from 9.0393 to 2.461 false alarms per 100 healthy animal-weeks (52 false alarms), with early recall unchanged at 0.8028 over 71 episodes. The herd median uses module-level per-animal history, because `herd` only holds today's rows. It is only applied when at least 10 animals have enough history, so it falls back to no shift otherwise. I did not test it on held-out data, and I did not run an ablation on the 0.6 yesterday weight.

Diff
diff --git a/alert_rule.py b/alert_rule.pyindex a719ab7..14c7251 100644--- a/alert_rule.py+++ b/alert_rule.py@@ -16,10 +16,30 @@ def _z(history, today, key, sign, n=14):     return sign * (med - v) / sd
 
 
+_H = {}+_SHIFT = {}+++def _shift(herd, day):+    if day in _SHIFT:+        return _SHIFT[day]+    vals = []+    for r in herd:+        h = _H.get(r["animal"], [])+        if len(h) >= 5:+            vals.append(_score(h, r))+    _SHIFT[day] = statistics.median(vals) if len(vals) >= 10 else 0.0+    for r in herd:+        _H.setdefault(r["animal"], []).append(r)+    return _SHIFT[day]++ def risk(history, today, herd):
-    t = _score(history, today)+    d = today["day"]+    sh = _shift(herd, d)+    t = _score(history, today) - sh     if len(history) >= 5:
-        t += 0.6 * _score(history[:-1], history[-1])+        t += 0.6 * (_score(history[:-1], history[-1]) - _SHIFT.get(d - 1, 0.0))     return t
 
 

#9 · Widen each animal's median/MAD baseline window from 14 to 21 days (still skipping the latest 2 days and partial-coverage days), so the per-animal baseline is steadier and less affected by missing days.

dev 1.4198 → 1.0412held-out 2.4916 → 2.3479alert_rule.py +1 -1 agent 13s

Dev score went from 1.4198 to 1.0412 false alarms per 100 healthy animal-weeks (22 false alarms), with early recall unchanged at 0.8028 over 71 episodes. The gain is about 0.38, above the 0.25 threshold. I tried only n=21 and did not tune it, and I haven't checked held-out data.

Diff
diff --git a/alert_rule.py b/alert_rule.pyindex 14c7251..b77856a 100644--- a/alert_rule.py+++ b/alert_rule.py@@ -3,7 +3,7 @@ import statistics
 
 
-def _z(history, today, key, sign, n=14):+def _z(history, today, key, sign, n=21):     v = today[key]
     if v is None or today["coverage"] < 0.6:
         return None

Dev vs held-out

The held-out command ran 6 time(s), only on candidates that had already won on dev. Its scores never entered a prompt or a worktree. Policy: gate (tolerance 0). 1 dev win(s) were blocked by the gate.

Held-out improved 95.3% against 98.1% on dev: the gains carry over.

StepDevHeld-outHeld-out − dev
baseline55.939449.7365-6.2029
#113.06218.59135.5293
#39.039312.55393.5146
#56.294410.15813.8637
#61.41982.49161.0718
#91.04122.34791.3067
#7 (blocked)5.821112.60186.7807

Rejected ideas (5)

#HypothesisDevWhy it was not kept
2Subtract the herd-wide median rumination deviation from its own 7-day baseline today from each animal's rumination before scoring, so weather and management shifts hitting the whole herd don't trigger alerts.41.7889rejected: conflicts with a newer accepted change
4Veto the risk score (return -1) on any day when activity is above the animal's own 14-day median, since illness lowers activity and an activity rise is an oestrus-like benign burst.12.5414rejected: no improvement once combined with newer best: 12.5414 vs 9.0393
7Add 0.35 times the multi-signal score from two days ago to the existing today + 0.6×yesterday sum, so evidence over three days counts rather than two.5.8211rejected: held-out gate: 12.6018 is worse than best held-out 10.1581
8Weight activity surges (activity above the animal's baseline, a sign of oestrus) at 2.0 instead of 0.5 so they subtract more from the illness score, while activity drops keep the 0.5 weight.6.1051rejected: no improvement over its parent beyond noise: 6.1051 (needed better than 6.0444)
10Divide each animal's herd-median-adjusted score by the herd's robust day-wide spread of scores (floored at 1.0) so that days with herd-wide noise need larger animal-specific deviations to alert.–rejected: no change: the agent left the editable files as they were (made no edit, or reverted its own)

Cost and time

Active wall clock
1.9 min over 1 session(s)
Agent time (summed over workers)
2.7 min
Metric time
21s
Agent cost
$0.44 (reported by the backend; on a Claude subscription this is the notional API price, not a bill)
Backend · model
claude · claude-sonnet-5-5 · 2 worker(s)
#StatusAgentTurnsMetricCost
1accepted12s71s$0.04
2rejected15s70s$0.05
3accepted13s62s$0.03
4rejected21s121s$0.05
5accepted13s62s$0.03
6accepted22s94s$0.06
7rejected10s53s$0.03
8rejected19s82s$0.04
9accepted13s64s$0.04
10rejected24s120s$0.07

Setup

Metric
python3 score.py --split dev (min)
Held-out
python3 score.py --split heldout
Editable
alert_rule.py
Frozen
score.py, generate.py, README.md, data/dev_*
Noise policy
1 run(s) per candidate, baseline 3 run(s) (std 0); margin max(0.25, 2σ)
Branch
hillclimb/best @ 737842152560 (base 0ea67dfe78ff)