Analysis
An operating point that meets two requirements
Two requirements: no more than one false switch every two hours, and 90 percent of deliberate switches within 15 seconds. Simulate a head's scores with neighboring windows alike, as real ones are, and search thresholds and holds for one that meets both. Then put in your own head's numbers from the light switch.
import numpy as np
rng = np.random.default_rng(10)
W = 4.0 # a score every four seconds
OFF, ON, SD, RHO = 0.2, 0.8, 0.15, 0.5 # your head's scores: means, spread, and how alike
# neighboring windows are. Put in your own.
def noise(rows, cols):
"""Window-to-window noise that carries over from one window to the next."""
e = rng.normal(0, SD, (rows, cols))
for j in range(1, cols):
e[:, j] = RHO * e[:, j - 1] + np.sqrt(1 - RHO ** 2) * e[:, j]
return e
def held(above, hold):
"""Where `hold` windows in a row have been above the threshold."""
count = np.zeros(above.shape, int)
for j in range(above.shape[1]):
count[:, j] = np.where(above[:, j], (count[:, j - 1] if j else 0) + 1, 0)
return count >= hold
def false_per_hour(threshold, hold, hours=200):
on = held(OFF + noise(1, int(hours * 3600 / W)) > threshold, hold)[0]
return np.sum(on[1:] & ~on[:-1]) / hours
def slow_tail(threshold, hold, trials=5000):
"""The 90th percentile of the delay from a change to On, with windows on a grid."""
t0 = rng.uniform(0, W, trials)
ends = W * np.arange(1, 13)
share = np.clip((ends[None] - t0[:, None]) / W, 0, 1)
h = held(OFF + share * (ON - OFF) + noise(trials, len(ends)) > threshold, hold)
return np.percentile(ends[np.argmax(h, axis=1)] - t0, 90)
print("threshold hold false an hour 90% of switches within")
for threshold in (0.5, 0.6, 0.7):
for hold in (1, 2, 3):
f, tail = false_per_hour(threshold, hold), slow_tail(threshold, hold)
ok = " meets both" if f <= 0.5 and tail <= 15 else ""
print(f"{threshold:9.1f} {hold:5d} {f:14.2f} {tail:13.1f} s{ok}")
You should seeOne rule meeting both, a threshold of 0.7 with no hold: 0.39 false switches an hour, and 90 percent within 12.3 seconds. The demo's rule, 0.5 with no hold, gives 17 false switches an hour. Holds help less than independence would suggest: at 0.5, two in a row still leave 2.8 an hour.
Then report: the rule your own head's scores allow, or which requirement it can't meet, and what would have to change.