Skip to content

TypeScript executor

sequential-analysis — TypeScript executor

Continues runs of the Python library sequential-analysis in Node.js, and hands them back. It reads and writes the same formats, specified in SPEC.md:

  • checkpoints;
  • observation logs;
  • delivery and topology states.

Agreement with the Python library

  • History digests and random states are identical.
  • Outputs and states are identical for 34 of the 108 conformance cases. For the others they agree to 5e-14 relative, and to 5.9e-13 in thirteen cases (a value near zero, or a weight, that is a difference of much larger terms, in eight; bounds found by a root search, in four; a quadrature, in one): V8 rounds Math.log, log1p, exp, expm1 and cos differently from the C library.
  • Decisions never differ.
  • Round trip. A run checkpointed in Python, continued here and restored in Python again ends with the digest of the uninterrupted run (tests/test_typescript.py).

Runs on Node.js 16 or later (its tests need 18).

npm ci && npm test
node dist/src/cli.js procedures                    # what this executor implements
node dist/src/cli.js verify checkpoint.json        # structure, identity, state
node dist/src/cli.js continue checkpoint.json observations.jsonl --checkpoint next.json --outputs outputs.jsonl
import { restoreFromCheckpoint } from "sequential-analysis";

const run = restoreFromCheckpoint(JSON.parse(text));   // procedure, topology and delivery from the checkpoint
run.start();
for (const obs of observations) run.offer(obs);        // {input, value, source, seq, key, time}
const next = run.checkpoint();                         // continue in Python with Run.restore

What is implemented

The executor has two parts:

  • The run. Delivery, topologies, contracts, the history digest, checkpoints and the observation log.
  • Procedures. Every procedure of the Python library, as listed by procedures:
  • SPRT, 2-SPRT and plans;
  • CUSUM, Shiryaev–Roberts, the e-detectors and Bayesian online change-point detection (normal-gamma, Poisson-gamma and beta-Bernoulli models);
  • the mixture SPRTs, the betting and sign tests, the quantile test and the kernel two-sample test;
  • confidence sequences: betting, quantile, Catoni and asymptotic;
  • group sequential tests;
  • the A/B tests (including the exact bounded-metric test and the rate-ratio test), several tests with e-BH (MultipleTests), and online FDR control over a series of experiments (e-LOND);
  • the anytime-valid linear model (tests and confidence sequences for regression coefficients) and the anytime-valid log-rank test with its hazard-ratio confidence sequence;
  • the local-level and general Kalman filters, the robust (Student t) Kalman filter, the hidden Markov filter (categorical, Gaussian and Poisson emissions), the bootstrap particle filters (local level; linear Gaussian, stochastic volatility and Student t local level), EMA and the mean difference;
  • several series at once: vector autoregression (fixed or learnt online), lead-lag cross-correlations and regression on drifting coefficients (DynamicRegression); Lagged, which feeds a procedure the recent past of its inputs (an anytime-valid Granger test with the linear model inside);
  • streams of events: the Hawkes process filter and event studies;
  • volatility: the GARCH(1,1) and GJR-GARCH(1,1) filter.

Topologies: independent, positional pair, key join, time alignment and the as-of join of bars with irregular events. Its decayed sums use portableExp2 (only +, *, /), so they are bit for bit those of Python and a continued run keeps the same history digest.

Procedures that offer a numpy backend are continued here only when the run used backend="python": numpy's exp, log and sums are not specified to the last bit. A checkpoint with backend="numpy" is refused.

Designs, such as optimal plans and group sequential boundaries, are computed in Python. They reach this executor as part of the procedure's configuration.

License: AGPL-3.0-only, or a commercial license (see COMMERCIAL.md in the repository).