ui#
The SMdRQA.ui package provides the interactive Streamlit interface
(pip install SMdRQA[ui], launched with smdrqa-ui or
python -m SMdRQA.ui) together with UI-independent helpers that are
also usable — and tested — without the UI dependencies installed:
script recording for reproducibility, window-size sensitivity analysis,
and regime-based simulation.
See the Interactive UI (Streamlit) section of the RQA2 reference guide for a walkthrough of the app itself.
recorder#
Script recorder for the SMdRQA UI.
Every action taken in the UI appends an equivalent block of plain Python
to a ScriptRecorder, so the whole interactive session can be
downloaded as a standalone, seeded, reproducible .py script.
- class ScriptRecorder(seed)[source]#
Bases:
objectAccumulates Python code blocks mirroring UI actions.
- Parameters:
seed (int) – Random seed chosen in the UI. Baked into the script header so rerunning the exported file reproduces the session exactly.
Examples
>>> rec = ScriptRecorder(seed=42) >>> rec.record("x = np.arange(10)", comment="Create data") >>> print(rec.script())
- HEADER_TEMPLATE = '"""\nSMdRQA reproducibility script.\n\nAuto-generated by the SMdRQA UI on {timestamp}.\nRerunning this file reproduces every analysis performed in the UI\nsession, including random-seed-dependent steps.\n"""\n\nimport os\n\nimport numpy as np\nimport pandas as pd\n\nfrom SMdRQA.RQA2 import RQA2, RQA2_simulators, RQA2_tests, RQA2_ml\nfrom SMdRQA.ui.simulate import sample_regime_values, simulate_signal\n\nSEED = {seed}\nnp.random.seed(SEED)\n\nsignals, ids, labels = [], [], []\n'#
- property n_blocks#
sensitivity#
Window-size sensitivity analysis for the SMdRQA UI.
Seeded, vectorised re-implementation of the bootstrap procedure in
SMdRQA.window_size: for each candidate window size, line-length
distributions are pooled over all diagonal sub-windows of the recurrence
plot, resampled n_boot times, and the width of the 5–95 % quantile
interval of the chosen RQA measure is reported. Narrow intervals mean
the measure is stable at that window size.
- MEASURES = {'avg_diag': ('diag', 'average'), 'avg_vert': ('vert', 'average'), 'percent_det': ('diag', 'percent'), 'percent_lam': ('vert', 'percent')}#
measure name -> (histogram kind, statistic)
- window_size_sensitivity(rp, measure, *, min_size=20, max_size=None, step=10, n_boot=1000, seed=42, progress_callback=None)[source]#
Bootstrap CI width of an RQA measure across window sizes.
- Parameters:
rp (ndarray) – Recurrence plot (square 0/1 matrix).
measure ({‘percent_det’, ‘percent_lam’, ‘avg_diag’, ‘avg_vert’}) – RQA measure to analyse.
min_size (int, default 20) – Smallest window size tested.
max_size (int, optional) – Largest window size tested (exclusive). Defaults to RP size.
step (int, default 10) – Window-size increment.
n_boot (int, default 1000) – Number of bootstrap samples per window size.
seed (int, default 42) – Seed for the bootstrap RNG (the legacy implementation in
SMdRQA.window_sizeis unseeded).progress_callback (callable, optional) – Called as
progress_callback(index, total, window_size).
- Returns:
pandas.DataFrame – Columns
window_sizeandci_width(95 % quantile − 5 % quantile).
simulate#
Simulation helpers for the SMdRQA UI.
Provides editable per-system parameter defaults (matching the
RQA2_simulators signatures), a registry of bifurcation-parameter
regimes with suggested chaos thresholds, distribution-based parameter
sampling for regime-labelled batch generation, and a standalone
simulate_signal used both by the UI and by the exported
reproducibility scripts.
- REGIMES = {'chua': {'above_label': 'chaotic', 'below_label': 'periodic', 'note': "With the default beta/m0/m1, Chua's circuit shows limit cycles at low alpha and double-scroll chaos around the canonical alpha=15.6; alpha≈8.8 is an approximate transition guide.", 'param': 'alpha', 'threshold': 8.8}, 'henon': {'above_label': 'chaotic', 'below_label': 'periodic', 'note': 'With b=0.3 the Hénon map is largely periodic below a≈1.06 and chaotic (with periodic windows) up to the canonical a=1.4.', 'param': 'a', 'threshold': 1.06}, 'kuramoto': {'above_label': 'synchronized', 'below_label': 'incoherent', 'note': 'For Gaussian natural frequencies the critical coupling is K_c = omega_sd·sqrt(8/pi) ≈ 1.596·omega_sd: incoherent below, synchronised above.', 'param': 'K', 'threshold': None}, 'lorenz': {'above_label': 'chaotic', 'below_label': 'fixed_point', 'note': 'With sigma=10, beta=8/3 the Lorenz fixed points lose stability at rho≈24.74; rho=28 is the canonical chaotic attractor.', 'param': 'rho', 'threshold': 24.74}, 'rossler': {'above_label': 'chaotic', 'below_label': 'periodic', 'note': 'With a=b=0.2 the Rössler system period-doubles into chaos as c grows: c≈3.5 gives a simple limit cycle, chaos onsets near c≈4.2, and c=5.7 is the canonical chaotic attractor.', 'param': 'c', 'threshold': 4.2}}#
Bifurcation-parameter metadata per system.
thresholdis the suggested value separating the two dynamical regimes (holding the other parameters at their defaults); thresholds are approximate guides taken from the standard literature, not exact bifurcation points.
- SYSTEM_PARAM_DEFAULTS = {'chua': {'alpha': 15.6, 'beta': 28.0, 'm0': -1.143, 'm1': -0.714}, 'henon': {'a': 1.4, 'b': 0.3}, 'kuramoto': {'K': 1.0, 'n_osc': 10, 'omega_sd': 1.0}, 'lorenz': {'beta': 2.6666666666666665, 'rho': 28.0, 'sigma': 10.0}, 'rossler': {'a': 0.2, 'b': 0.2, 'c': 5.7}, 'sine': {}, 'white_noise': {}}#
Editable parameters per system, mirroring RQA2_simulators defaults.
- regime_threshold(system, params=None)[source]#
Suggested regime threshold for system (None if no regime).
- sample_regime_values(distribution, dist_params, n, side, threshold, rng)[source]#
Draw n bifurcation-parameter values on one side of threshold.
- Parameters:
distribution ({‘uniform’, ‘normal’, ‘fixed’})
dist_params (dict) –
{'low', 'high'}for uniform,{'mean', 'sd'}for normal,{'value'}for fixed.n (int) – Number of samples.
side ({‘below’, ‘above’}) – Which side of threshold the samples must fall on; draws are clipped to that side so regime labels stay truthful.
threshold (float) – Regime boundary.
rng (numpy.random.Generator)
- Returns:
ndarray of shape (n,)
- simulate_signal(sim, system, length, noise_sd, rng, **params)[source]#
Simulate one signal from system with explicit parameters.
- Parameters:
sim (RQA2_simulators) – Seeded simulator instance.
system (str) – One of
SYSTEM_PARAM_DEFAULTS.length (int) – Number of samples.
noise_sd (float) – SD of additive Gaussian observation noise (0 disables).
rng (numpy.random.Generator) – RNG for the observation noise.
**params – System parameters overriding the defaults (e.g.
c=4.0for Rössler,K=2.0, n_osc=15for Kuramoto).
- Returns:
ndarray – 1-D for sine/white noise, else (length, n_dims).