feat(profiler/behave_shell): emit motor.motor_stability
BEHAVE-EXTRACTOR.md Phase B Step B.2. First principled
implementation — the prototype doesn't ship this primitive at all.
* _features/motor.py:motor_stability(ctx) emits one Observation
in {steady, variable, tremor}. Reuses ctx.typing_bursts from B.1.
* Tremor proxy: fraction of within-burst IATs below
TREMOR_FAST_FLOOR_S (30 ms — humans can't sustain sub-50 ms IATs).
≥ TREMOR_RATE_MIN (10%) sub-floor → tremor (double-press / motor
twitch / stuck-key).
* Otherwise median burst CV decides: < CV_STEADY_MAX → steady,
else → variable. Confidence 0.70 / 0.60 / 0.65.
* No typing bursts or fewer than 5 within-burst IATs → skip emit.
* Calibration grid widened to include motor.motor_stability; green
across all five shards.
Tests cover all three buckets + skip paths.
This commit is contained in:
@@ -20,6 +20,7 @@ from decnet.profiler.behave_shell._features.cognitive import (
|
||||
from decnet.profiler.behave_shell._features.motor import (
|
||||
input_modality,
|
||||
keystroke_cadence,
|
||||
motor_stability,
|
||||
paste_burst_rate,
|
||||
)
|
||||
|
||||
@@ -29,6 +30,7 @@ FEATURES: tuple[FeatureFn, ...] = (
|
||||
input_modality,
|
||||
paste_burst_rate,
|
||||
keystroke_cadence,
|
||||
motor_stability,
|
||||
inter_command_latency_class,
|
||||
command_branch_diversity,
|
||||
feedback_loop_engagement,
|
||||
|
||||
@@ -24,6 +24,8 @@ from decnet.profiler.behave_shell._thresholds import (
|
||||
MODALITY_TYPED_MAX,
|
||||
PASTE_RATE_HABITUAL_MIN,
|
||||
PASTE_RATE_OCCASIONAL_MIN,
|
||||
TREMOR_FAST_FLOOR_S,
|
||||
TREMOR_RATE_MIN,
|
||||
)
|
||||
|
||||
|
||||
@@ -126,3 +128,41 @@ def keystroke_cadence(ctx: SessionContext) -> Iterator[Observation]:
|
||||
value=value,
|
||||
confidence=confidence,
|
||||
)
|
||||
|
||||
|
||||
def motor_stability(ctx: SessionContext) -> Iterator[Observation]:
|
||||
"""Emit ``motor.motor_stability`` ∈ {steady, variable, tremor}.
|
||||
|
||||
First-pass tremor signal: fraction of within-typing-burst IATs
|
||||
below ``TREMOR_FAST_FLOOR_S`` (30 ms — humans can't reliably
|
||||
produce sustained sub-50 ms IATs). High sub-floor rate flags
|
||||
double-press / motor twitch / stuck-key. Otherwise the same
|
||||
median burst-CV used by ``keystroke_cadence`` decides
|
||||
steady-vs-variable, with the cadence's CV_STEADY_MAX as the
|
||||
boundary.
|
||||
"""
|
||||
if not ctx.typing_bursts:
|
||||
return
|
||||
flat = list(chain.from_iterable(ctx.typing_bursts))
|
||||
if len(flat) < 5:
|
||||
return
|
||||
fast_rate = sum(1 for x in flat if x < TREMOR_FAST_FLOOR_S) / len(flat)
|
||||
if fast_rate >= TREMOR_RATE_MIN:
|
||||
value, confidence = "tremor", 0.65
|
||||
else:
|
||||
burst_cvs: list[float] = []
|
||||
for b in ctx.typing_bursts:
|
||||
m = statistics.fmean(b)
|
||||
if m > 0:
|
||||
burst_cvs.append(statistics.pstdev(b) / m)
|
||||
cv = statistics.median(burst_cvs) if burst_cvs else 0.0
|
||||
if cv < CV_STEADY_MAX:
|
||||
value, confidence = "steady", 0.70
|
||||
else:
|
||||
value, confidence = "variable", 0.60
|
||||
yield make_observation(
|
||||
ctx,
|
||||
primitive="motor.motor_stability",
|
||||
value=value,
|
||||
confidence=confidence,
|
||||
)
|
||||
|
||||
@@ -90,3 +90,11 @@ CV_STEADY_MAX: float = 0.50
|
||||
CV_BURSTY_MAX: float = 1.50
|
||||
# Need this many input events before we'll claim a cadence at all.
|
||||
MIN_INPUTS_FOR_CADENCE: int = 5
|
||||
|
||||
# ── motor.motor_stability (Step B.2) ────────────────────────────────────────
|
||||
# Tremor proxy: fraction of within-burst IATs below TREMOR_FAST_FLOOR_S
|
||||
# (30 ms — physiologically implausible double-press floor; humans can't
|
||||
# reliably produce IATs below ~50 ms in sustained typing). High rate
|
||||
# of sub-floor IATs flags double-press / motor twitch / stuck-key.
|
||||
TREMOR_FAST_FLOOR_S: float = 0.030
|
||||
TREMOR_RATE_MIN: float = 0.10 # ≥10% sub-floor → tremor
|
||||
|
||||
Reference in New Issue
Block a user