PSTACK-COMPRESS: Experimental Code v2
Description
This dataset contains the complete Python source code accompanying the paper: Piotr Frydrych, "The Preisach Extremum Stack as an Order-2 Davenport–Schinzel Sequence: Online Compression and Sufficient Statistics for Rate-Independent Streams," Discrete Applied Mathematics, submitted May 2026. The code implements PSTACK-COMPRESS (Algorithm 1 from the paper): an online, linear-time algorithm for lossless compression of rate-independent data streams based on the Preisach extremum stack. The extremum stack Π_n records the alternating local maxima and minima of a discrete sequence that survive the Preisach wiping-out rule. The paper proves that Π_n is the Kolmogorov-minimal sufficient statistic for the class R of all computable rate-independent functionals, and that PSTACK-COMPRESS is asymptotically optimal: no online algorithm can produce a shorter exact representation for any R-query. The dataset includes: pstack_dam_experiments.py — full implementation of PSTACK-COMPRESS, eight synthetic signal generators (monotone, slow sine, trend+noise, white noise, piecewise/SCADA-like, ECG-like, financial random walk, adversarial worst-case), a self-test suite verifying the Definition 4 stack invariant at every time step, and benchmark routines reproducing all numerical results reported in Sections 7.1–7.4 of the paper (compression ratios, adversarial lower bound verification, white noise k/n distribution, speedup of online vs. naive algorithm). README.md — detailed usage instructions, description of all signal classes, code examples reproducing specific tables and figures from the paper, and citation information. No real-world datasets are used. All signals are generated synthetically and deterministically from fixed random seeds, ensuring full reproducibility of every number reported in the paper. Keywords Preisach operator, extremum stack, Davenport–Schinzel sequences, rate-independent functionals, online compression, Kolmogorov complexity, sufficient statistic, time series, data streams, hysteresis Related publication Frydrych, P. (2026). The Preisach Extremum Stack as an Order-2 Davenport–Schinzel Sequence: Online Compression and Sufficient Statistics for Rate-Independent Streams.
Files
Steps to reproduce
All results in Sections 7.1–7.4 of the paper can be reproduced from scratch with the following steps. No internet connection, no external datasets, and no additional software beyond Python and NumPy are required. Step 1. Install dependencies. Run: pip install numpy Tested with Python 3.8–3.12 and NumPy 1.21–1.26. No other packages are needed. Step 2. Verify algorithm correctness (self-test). Run: python pstack_dam_experiments.py --test Runs 7 hand-crafted test cases and checks the Definition 4 stack invariant (strictly decreasing maxima, strictly increasing minima) at every time step. Expected output: ALL PASS. This step should be run before any benchmarks to confirm the implementation is correct in the current Python environment. Step 3. Reproduce Table 2 (compression ratios) and the speedup table. Run: python pstack_dam_experiments.py Runs the full benchmark over 8 signal classes x 5 sequence lengths (n = 100, 500, 1000, 5000, 10000), averaged over 20 random seeds, and prints compression ratios n/k to stdout. Also prints the speedup of the online algorithm over naive recomputation for n = 50–1000. Runtime: approximately 10–30 seconds on a standard laptop. To save results to JSON: python pstack_dam_experiments.py --output results.json Step 4. Reproduce the adversarial lower bound (Section 7.2). Run the following Python snippet: for n in [100, 1000, 10000]: sig = make_signal('adversarial', n, seed=0); k = pstack_online(sig)[-1]; print(n, k, k/n) Expected: k/n converges to 0.500 as n increases, confirming the tightness of Theorem 17. Step 5. Reproduce the white noise distribution (Section 7.3). Compute peak_stack_size(make_signal('white_noise', 10000, seed=s)) / 10000 for s in range(100) and average. Expected: mean k/n = 0.333 +/- 0.002, confirming the asymptotic E[k/n] = 1/3 result. Step 6. Increase statistical precision (optional). Run: python pstack_dam_experiments.py --seeds 100 --output results_100seeds.json