Skip to main content

The ValidAnytime detector suite, offline: CUSUM, EWMA, static threshold, rolling band — plus an offline port of the anytime-valid backtest gate, golden-tested against the production engine.

Project description

validanytime-detectors

PyPI Python versions CI License: Apache 2.0

The ValidAnytime detector suite, offline: every detector you already know — CUSUM, EWMA chart, static threshold, rolling band — plus an offline port of the anytime-valid backtest path the ValidAnytime cloud runs, with the hosted gate's machine-readable verdict.

Pure Python, zero dependencies — the float32 emulation uses only the standard library, so pip install validanytime-detectors pulls in nothing else. Nothing here talks to the network. Apache-2.0 licensed.

pip install validanytime-detectors

Contents

The 30-second version

from validanytime_detectors import backtest_gate

# your believed-normal metric history (judge scores, accuracy, latency, ...)
verdict = backtest_gate(history)

print(verdict["summary"])
# "Quiet across 240 normal points, then caught the injected degradation
#  9 step(s) after it began. This is the day it would have caught it."
assert verdict["passed"]

backtest_gate replays your history through the two-tier stack and grades it exactly like the hosted POST /v1/onboarding/backtest:

  • it must stay quiet on your normal history (a page-tier fire there is a false alarm and fails the gate), and
  • it must catch an injected degradation appended to the tail (synthetic, and labeled as such in the verdict via "injected": true).

The verdict is a plain dict with the same fields as the hosted gate — passed, false_alarm_on_normal, caught_at_seq, fires, warned_on_normal, warn_fires, summary — so an agent or a CI job can consume either interchangeably. This is what powers the validanytime-gate GitHub Action.

Two tiers, stated honestly

Warning tier — the classical detectors. cusum_events, ewma_chart_events, static_threshold_events, rolling_band_events are sensitive and usually faster to fire, but their calibration is model-based: an ARL or false-alarm rate computed for iid Gaussian z-scores. On realistic metric textures their false-alarm rate can exceed the nominal promise by orders of magnitude. Warnings are hints to tune, not budgeted pages, and the gate never grades on them (warned_on_normal is surfaced, never a failure).

Page tier — the e-process monitors. The coverage e-process and the Shiryaev–Roberts e-detector page within a stated false-alarm budget, and the guarantee holds at every look, however often you check — that is what "anytime-valid" means. Only this tier can pass or fail the gate.

from validanytime_detectors import cusum_events, CUSUM_H_ARL_2000

r = cusum_events(values)          # k=0.5, h solved for nominal ARL 2000
print(r.events)                   # 1-based alarm seqs (renewal resets)

Engine fidelity

The e-process path (replay_series, grade_replay, inject_drift, suggest_config) is a float32-emulated port of the production engine's backtest path — same conformal calibrator, same e-process monitors, same alarm thresholds — verified against the production engine's own outputs by golden tests: identical first-alarm points on the full fixture corpus, and evidence curves matching to 0.01%. It is a port, not the same binary; transcendental rounding can differ by 1 ulp, which the fixture corpus (with deliberately near-threshold cases) is designed to catch.

The offline path replays plain numeric histories. Delayed labels, fleet-wide false-discovery control, alarm certificates, and routing are hosted-product features and are not in this package.

Run the parity tests

The golden fixtures are generated from the real production engine and vendored in this repo (tests/fixtures/), so the parity suite — the proof of the fidelity claim above — runs fully offline with no account and no service:

pip install -e '.[dev]'
pytest -q          # golden engine parity + classical parity + gate behavior
ruff check .       # lint
ruff format --check .
pyright            # types

NumPy is a test-only dependency (it computes the float32 reference values the port is pinned against); the package itself imports nothing outside the standard library.

Related

  • /try — the same backtest in your browser, no install, with the detector bake-off.
  • validanytime — the thin API client for the hosted product.
  • Docs for agents — MCP server, copy-paste agent prompts, and the CI gate.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

validanytime_detectors-0.1.2.tar.gz (86.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

validanytime_detectors-0.1.2-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

Details for the file validanytime_detectors-0.1.2.tar.gz.

File metadata

  • Download URL: validanytime_detectors-0.1.2.tar.gz
  • Upload date:
  • Size: 86.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for validanytime_detectors-0.1.2.tar.gz
Algorithm Hash digest
SHA256 afa49bcbf9578d8dc3d697c94b155f45e1a3275ba480c4837a989cefedcb2144
MD5 6620bfa1a338075f612a374966bf27eb
BLAKE2b-256 c6a4d977a54015b7ab28f978281eb847ec493d22a17e669df8173ff3535b9a7d

See more details on using hashes here.

File details

Details for the file validanytime_detectors-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for validanytime_detectors-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 367497f4dda25c075cfb4f2b7688d4481d00add4d4d3a378481a46ed34761d0c
MD5 c4cc42ec8ecb6c07a2a0801bdaf08033
BLAKE2b-256 443bff9daf01902b5ae3a269a2258aabbc281f63bdeff443c5bb002c312714a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page