/ concept-collection / timeseries-compressibility
Sign in
concept-collection / timeseries-compressibility
timeseries-compressibility / README.md
82 lines · 4.6 KBPreviewCodeBlameHistoryRaw
1# timeseries-compressibility
3Interactive exploration of how compressible quantized time series are.
5The generating model is: i.i.d. Gaussian noise (std σ, measured in quantization
6steps) → FIR filter → round to integers. The app shows the filter (convolution
7kernel and frequency response, with cutoffs in Hz against a chosen sample
8rate), a window of the generated integer signal (stationary by default, with a
9play toggle to let it stream endlessly), and the measured compression of a
10block of the generated integers under ten methods — zlib, zstd, and an rANS
11entropy coder, each raw, delta-coded, and LPC-residual-coded, plus the
12conditional-Gaussian coder below — as bits per sample and as ratio against raw
13int16 storage. The predictor order and the
14block size are controls, so the measurement can be pushed from 10k to a million
15samples and LPC from order 1 to 128. Under the chart, every coder that codes
16against an explicit model is scored against it — ANS against the order-0
17entropy of the stream it was handed, the arithmetic coder against its own
18predictive distribution — which separates how well a coder does its job (1–2%
19overhead for ANS, its symbol table plus its arithmetic loss) from how good the
20model was in the first place.
22The tenth method is the one that can pass those hollow bars: the same LPC
23prediction kept at full precision, each sample arithmetic-coded under a
24discretized Gaussian centred on the real-valued prediction. When the
25prediction error is a fraction of a quantization step (narrowband filters,
26moderate σ), whether the prediction falls near a bin centre or a bin edge is
27worth ~0.3–0.4 bits/sample — information the integer residual has already
28destroyed, which is why LPC+ANS plateaus far above R there. Its only limit is
29R itself. Like every other bar, its size is real: encoded, decoded, verified,
30side information included.
32The entropy rate R of the process — the bits/sample limit no lossless method
33can beat — is estimated in the browser by the method of the companion
34[timeseries-entropy](https://github.com/concept-collection/timeseries-entropy)
35package: an unbiased Monte-Carlo estimator of H(z_next | a long past), by Gibbs
36sampling the latent Gaussian under the rounding constraints and applying
37Rhee–Glynn randomized telescoping to the sampled chain. The package's analytic
38approximation of R — Szegő's one-step prediction error with roundoff as a 1/12
39dither floor, fed through the Gaussian⊕uniform entropy — is drawn as a dotted
40reference line at all times, so the Monte-Carlo estimate lands beside its
41prediction. A button starts a web
42worker that averages one independent past at a time (live mean ± se, dashed
43line on the chart) until stopped; the app also shows the exact command to run
44the Python original at the same settings as an independent check. The
45in-browser code in `src/entropy/` is a hand-synced TypeScript port of that
46package — change one, change the other. A WebGPU Gibbs sweep may replace the
47scalar one someday; the sweep is isolated so it can be swapped.
49## Run it
51```sh
52npm install
53npm run dev
54```
56## Layout
58```
59src/model/ the latent source (fixed seeded randomness indexed by sample
60 position, convolved zero-phase with the kernel on demand)
61 and the FIR presets
62src/entropy/ the unbiased entropy-rate estimator: hand-synced TypeScript
63 port of the timeseries-entropy package (Gibbs conditional
64 sampler, Rhee–Glynn telescoping, Cody erfc / Acklam ndtri,
65 xoshiro128** RNG, the analytic rate prediction of theory.py)
66src/compress/ lossless codecs run in the browser: zlib (fflate), zstd (wasm),
67 ans.ts (a bit-identical port of simple_ans), FLAC-style
68 integer LPC (borrowed from entropy-quantized-linear-transform),
69 and conditionalGaussian.ts — real-coefficient prediction with
70 each sample arithmetic-coded under a discretized Gaussian at
71 the real-valued prediction
72src/worker/ the codecs and the estimator run off the main thread; the
73 estimator worker refines one past at a time until terminated
74src/components/ controls, filter plots, signal canvas, compression chart,
75 and the entropy-rate method note
76```
78Every reported size round-trips through the decoder and includes whatever the
79decoder needs (ANS symbol table, LPC coefficients). The signal view and the
80compression block read the same fixed latent noise sequence — parameter changes
81transform the same underlying data rather than resampling it, and the first
82window shown is the start of the block that gets compressed.
moveopenescclose