SymbolicInference
Documentation for SymbolicInference.
See the illustrated vignettes for step-by-step data analysis and interpretation:
- RQA Moment-Based Hypothesis Testing Vignette — analytical i.i.d. recurrence tests via marked Bivariate Generating Functions
- Dynamical Systems & Pole Scans Vignette — Markov null calibration (
:markov& verticalLAM), damping-invariant Hilbert unit-cylinder embedding, multimode beating, cross-coincidence slides, and sliding pole scans - Graphs & Symbolic Transition Networks Vignette — Symbolic Transition Networks, time-reversal cycle asymmetry, and recurrence network topology & entropy
SymbolicInference.compute_quarter_period_delaySymbolicInference.cross_coincidence_testSymbolicInference.cycle_asymmetry_testSymbolicInference.encode_ordinal_symbolsSymbolicInference.encode_quadrant_symbolsSymbolicInference.extract_phase_runsSymbolicInference.extract_recurrencesSymbolicInference.extract_recurrences_crossSymbolicInference.extract_recurrences_jointSymbolicInference.hilbert_unit_cylinderSymbolicInference.persistence_barcodeSymbolicInference.persistence_barcodeSymbolicInference.plot_motifsSymbolicInference.plot_motifs_crossSymbolicInference.plot_motifs_jointSymbolicInference.plot_rqa_momentsSymbolicInference.rec_matrix_motifsSymbolicInference.recurrence_network_motifsSymbolicInference.rqa_moments_testSymbolicInference.rqa_resonance_beating_testSymbolicInference.sliding_pole_scanSymbolicInference.symbolic_transition_networkSymbolicInference.symbolic_word_test
SymbolicInference.compute_quarter_period_delay — Method
compute_quarter_period_delay(fs::Real, f_mode_hz::Real) -> IntCompute the quarter-period embedding delay lag $d = \max(1, \text{round}(f_s / (4 f_{\text{mode}})))$ in samples to avoid oversampling persistence traps (Caveat 3 of symbolic-blackholes).
SymbolicInference.cross_coincidence_test — Method
cross_coincidence_test(x::AbstractVector{<:Real}, y::AbstractVector{<:Real};
delay_samples::Int=8, epsilon::Real=0.5, lmin::Int=3,
n_slides::Int=100, use_hilbert::Bool=true,
tol_rad::Real=0.58, pad::Int=64,
null_model::Symbol=:markov,
rng=Random.default_rng())Evaluate zero-lag dynamical coupling and temporal coincidence between two aligned signals x and y using:
- Joint Recurrence Matrix (
JointRecurrenceMatrix) and Cross Recurrence Matrix (CrossRecurrenceMatrix) analytical determinism moments viarqa_moments_test(defaulting tonull_model=:markovso autocorrelated marginals do not inflate Z-scores). - Zero-lag Cross-Recurrence synchronization rate and instantaneous Hilbert phase-step coherence
mean(cos(Δφ_x(t) - Δφ_y(t))). - Empirical calibration against
n_slidescircular time-slide surrogates ofy.
Returns a named tuple (jrm_test, crm_test, jrm, crm, det_jrm, det_crm, sync_crm, z_jrm_analytical, z_crm_analytical, phase_coherence, det_jrm_slide_null, z_slide_jrm, p_slide_jrm, sync_crm_slide_null, z_slide_crm, p_slide_crm, phase_slide_null, z_slide_phase, p_slide_phase, composite_z).
SymbolicInference.cycle_asymmetry_test — Method
cycle_asymmetry_test(syms::AbstractVector{<:Integer},
cycle::AbstractVector{<:Integer};
lag::Int=1, m::Int=maximum(syms))Test time-reversal asymmetry (non-equilibrium irreversibility / directed circulation) on a Symbolic Transition Network for a cycle cycle (either open [i_1, ..., i_k] denoting i_1 -> ... -> i_k -> i_1, or closed [i_1, ..., i_k, i_1]).
Constructs the exact detailed-balance reversible Markov null $\mathbf{P}_{\text{rev}}$ by row-normalizing the symmetrized flux matrix $\mathbf{W}_{\text{sym}} = \frac{1}{2}(\mathbf{C} + \mathbf{C}^T)$, then uses AnalyticComb.transfer_matrix_moments to compute:
- The exact analytical null mean (
0.0) and finite-sample variance of the net signed transition flux $\Delta J_c = N_{\text{edges}}(c) - N_{\text{edges}}(c_{\text{rev}})$. - Exact analytical moments and Z-scores for full-cycle closed word occurrences $c$ and $c_{\text{rev}}$ under $\mathbf{P}_{\text{rev}}$.
Returns a named tuple (cycle_word, reverse_word, obs_edge_fwd, obs_edge_rev, net_edge_flux, expected_flux, std_flux, z_flux, p_flux, obs_word_fwd, obs_word_rev, expected_word, std_word, z_word_fwd, z_word_rev, P, P_rev).
SymbolicInference.encode_ordinal_symbols — Method
encode_ordinal_symbols(x::AbstractVector{<:Real}; m::Int=3, d::Int=1) -> Vector{Int}Encode scalar time series x into Bandt–Pompe ordinal permutation symbols of embedding dimension m >= 2 and delay d >= 1, mapping each $m$-tuple onto its lexicographical Lehmer rank in 1:factorial(m).
SymbolicInference.encode_quadrant_symbols — Method
encode_quadrant_symbols(u::AbstractVector{<:Real}, v::AbstractVector{<:Real}) -> Vector{Int}
encode_quadrant_symbols(h::AbstractVector{<:Real}; pad::Int=64) -> Vector{Int}Discretize a phase trajectory (u(t), v(t)) (or raw scalar signal h(t) via Hilbert transform) into the 4-letter quadrant alphabet Σ = {1, 2, 3, 4}:
1:u >= 0, v >= 0(phase in[0, π/2))2:u < 0, v >= 0(phase in[π/2, π))3:u < 0, v < 0(phase in[-π, -π/2))4:u >= 0, v < 0(phase in[-π/2, 0))
SymbolicInference.extract_phase_runs — Method
extract_phase_runs(u::AbstractVector{<:Real}, v::AbstractVector{<:Real}, d::Int; tol_rad::Real=0.58)Evaluate instantaneous phase progression at lag d. A step i -> i + d is classified as a locked prograde step (b_i = 1) when the phase advance $\Delta \phi_d(i)$ lies within $[\pi/2 - \text{tol\_rad}, \pi/2 + \text{tol\_rad}]$ or advances by one quadrant counterclockwise.
SymbolicInference.extract_recurrences — Method
extract_recurrences(data_source::Vector{Float64}, motifs_dict::Dict{String, Vector}; num_windows::Int64 = 3)This function returns x and y coordinates for a given window considering start and size of each motif. The y coordinates are the values from data provided by the user.
SymbolicInference.extract_recurrences_cross — Method
extract_recurrences_cross(data_source::Vector{Float64}, data_source2::Vector{Float64},
motifs_dict::Dict{String, Vector}; num_windows::Int64 = 3)This function returns x and y coordinates for a given window considering start and size of each motif detected from two time-series in cross-recurrence matrices. The y coordinates are the values from data provided by the user.
SymbolicInference.extract_recurrences_joint — Method
extract_recurrences_joint(data_source::Vector{Float64}, data_source2::Vector{Float64},
motifs_dict::Dict{String, Vector}; num_windows::Int64 = 3)This function returns x and y coordinates for a given window considering start and size of each motif detected from two time-series in joint-recurrence matrices . The y coordinates are the values from data provided by the user.
SymbolicInference.hilbert_unit_cylinder — Method
hilbert_unit_cylinder(h::AbstractVector{<:Real}; delay_samples::Int=8, pad::Int=64)Normalize out instantaneous amplitude decay or modulation (Caveat 2 of symbolic-blackholes) by computing the reflection-padded complex analytic signal $z(t) = h(t) + i \mathcal{H}[h(t)]$ and projecting onto the unit phase circle: $u(t) = \text{Re}(z(t))/|z(t)|, \; v(t) = \text{Im}(z(t))/|z(t)|$.
Returns a NamedTuple:
z: Complex analytic signalenv: Instantaneous amplitude envelope $|z(t)|$u,v: Unit-circle quadrature coordinatesphase: Instantaneous phase in $[-\pi, \pi]$unwrapped_phase: Continuous unwrapped phasedphi: Step-wise wrapped phase increment $\Delta \phi(t)$cylinder_4d: $N_{\text{eff}} \times 4$ matrix $[u(t), v(t), u(t+d), v(t+d)]$ on the unit phase cylinder
SymbolicInference.persistence_barcode — Method
persistence_barcode(time_series1,time_series2; range = collect(0.1:0.1:0.9), n_windows=10,alpha_thresh=0.05)Return barcode plot for each window. Points are plotted whenever the p-value is smaller than alpha_thresh.
SymbolicInference.persistence_barcode — Method
persistence_barcode(time_series; range = collect(0.1:0.1:0.9), n_windows=10,alpha_thresh=0.05)Return barcode plot for each window. Points are plotted whenever the p-value is smaller than alpha_thresh.
SymbolicInference.plot_motifs — Method
plot_motifs(time_series::Vector{Float64},coordinates::Vector{Any}; plot_size=(2000, 1000), n_motifs=2)Plot motifs from coordinates extracted with extract_recurrences.
SymbolicInference.plot_motifs_cross — Method
plot_motifs_cross(time_series::Vector{Float64},time_series2::Vector{Float64},
coordinates::Vector{Any}; plot_size=(2000, 1000), n_motifs=2)Plot motifs from coordinates extracted with extract_recurrences_cross.
SymbolicInference.plot_motifs_joint — Method
plot_motifs_joint(time_series::Vector{Float64},time_series2::Vector{Float64},
coordinates::Vector{Any}; plot_size=(2000, 1000), n_motifs=2)Plot motifs from coordinates extracted with extract_recurrences_joint.
SymbolicInference.plot_rqa_moments — Method
plot_rqa_moments(moments_dict::Dict{String, Any}; title_prefix="", plot_size=(1200, 480), z_thresh=1.96)Plot the results of rqa_moments_test across off-diagonal windows:
- Left panel: Observed statistic vs. exact analytical expected value $\mu_i$ and $\pm z_{\text{thresh}} \sigma_i$ null band.
- Right panel: Standardized $Z$-scores per off-diagonal window along with the global aggregated $Z$-score and $p$-value.
SymbolicInference.rec_matrix_motifs — Method
rec_matrix_motifs(rec_matrix::Union{RecurrenceMatrix,CrossRecurrenceMatrix,JointRecurrenceMatrix,AbstractMatrix};
seqs="recurrences", window_range=collect(1:6), n_motifs=2,
null_model::Symbol=:iid, markov_params=nothing, verbose=false)Returns set of probabilities associated with consecutive runs in off-diagonals.
Argument seqs sets the type of consecutive sequences: either 'double' (recurrences and non-recurrences), 'recurrences', or 'poincare' (non-recurrences). The diagonals given by window_range are considered, along with n_motifs for each diagonal.
null_model=:iid(default): usesAnalyticComb.weighted_bin_runs_pvalwith Bernoulli ratep = RR.null_model=:markov: usesAnalyticComb.markov_bin_runs_pvalcalibrated to 1st-order Markov transition probabilities (estimated fromrec_matrixor supplied viamarkov_params).
SymbolicInference.recurrence_network_motifs — Method
recurrence_network_motifs(rec_matrix::Union{RecurrenceMatrix,JointRecurrenceMatrix,AbstractMatrix};
theiler::Int=1)Treat a recurrence matrix rec_matrix (with main-diagonal Theiler band |i - j| < theiler zeroed out) as an undirected simple adjacency matrix $\mathbf{A}$, computing:
- Degree distribution statistics (
degrees,mean_degree,std_degree,edge_count,edge_density) - Exact closed-walk invariants (
closed_2,closed_3 = Tr(A^3),closed_4 = Tr(A^4)) - Motif statistics:
n_triangles = Tr(A^3)/6,connected_triples, globaltransitivity, andmean_clustering - Spectral radius $\rho(\mathbf{A})$ and topological entropy $h_{\text{top}} = \log \rho(\mathbf{A})$
- Null graph baselines: Erdős–Rényi $G(N, p)$ triangle/transitivity expectations (respecting the Theiler band) and exact
AnalyticComb.random_mapping_moments(N)attractor statistics.
SymbolicInference.rqa_moments_test — Method
rqa_moments_test(rec_matrix::Union{RecurrenceMatrix,CrossRecurrenceMatrix,JointRecurrenceMatrix,AbstractMatrix};
lmin::Int=2, window_range=nothing, seqs="recurrences", metric="determinism",
null_model::Symbol=:iid, direction::Symbol=:diagonal,
markov_params=nothing, theiler::Int=1)Perform analytical hypothesis testing on Recurrence Quantification Analysis (RQA) diagonal (direction=:diagonal, e.g. Determinism DET) or vertical (direction=:vertical, e.g. Laminarity LAM and Trapping Time TT) statistics using exact moments (mean, var, std) derived from Bivariate Generating Functions (BGFs) in AnalyticComb.jl.
Arguments
rec_matrix: ARecurrenceMatrix,CrossRecurrenceMatrix,JointRecurrenceMatrix, or binaryAbstractMatrix.lmin::Int=2: Minimum run length threshold $l_{\min}$ (standard RQA default is 2).window_range=nothing: Off-diagonal lags (direction=:diagonal, defaults to1:6) or column indices (direction=:vertical, defaults to1:size(rec_matrix, 2)).seqs="recurrences": Sequence type ("recurrences"for 1-runs,"poincare"for 0-runs, or"double"for both).metric="determinism":"determinism"(or"length_ge"): Total number of points in runs of length $\ge l_{\min}$ (numerator ofDETorLAM)."motif_count"(or"count_ge"): Number of distinct runs/lines of length $\ge l_{\min}$."exact_length"(or"count_eq"): Count of lines of exact length $l_{\min}$ (line-length histogram $P(l_{\min})$).
null_model::Symbol=:iid::iid(Bernoulli trials with $p = RR$) or:markov(1st-order Markov chain calibrated on the recurrence segments or supplied viamarkov_params).direction::Symbol=:diagonal::diagonal(lag off-diagonals) or:vertical(columns, with Theiler exclusiontheileraround the main diagonal for square non-cross recurrence matrices).markov_params=nothing: Optional(p00, p01, p10, p11)NamedTuple or Tuple calibrated on external reference noise.theiler::Int=1: Main-diagonal exclusion half-width fordirection=:verticalon square matrices.
Returns
A Dict{String, Any} containing "Window", "Observed", "Expected", "Std", "ZScores", "PValues", "Global", "NullModel", "Direction", and "MarkovParams".
SymbolicInference.rqa_resonance_beating_test — Method
rqa_resonance_beating_test(x::AbstractVector{<:Real}, fs::Real,
f_primary::Real, f_secondary::Real;
epsilon::Real=0.5, lmin::Int=3,
use_hilbert::Bool=true, pad::Int=64,
null_model::Symbol=:iid)Test for multimode oscillation, frequency resonance, and amplitude/phase-velocity beating between a primary frequency f_primary and a secondary frequency f_secondary in a sampled 1D signal x (sampling rate fs).
When use_hilbert=true, x is first embedded onto the damping-invariant 4D Hilbert unit cylinder via hilbert_unit_cylinder at quarter-period lag d = compute_quarter_period_delay(fs, f_primary). Otherwise, a standardized 2D delay embedding at the same lag is used.
Recurrence quantification moments (rqa_moments_test) are evaluated across lags spanning T_1 = fs / f_primary, T_2 = fs / f_secondary, the beat period T_beat = fs / |f_secondary - f_primary|, and T_beat / 2, alongside both Poincaré gap analysis (seqs="poincare") and normalized spectral projection of the instantaneous phase-advance series Δφ_d(t) onto the beat frequency Δf = |f_secondary - f_primary|.
Returns a named tuple (rqa_rec, rqa_poinc, rmat, lag_T1, lag_T2, lag_beat, z_global, p_global, z_primary, z_secondary_shelf, z_beat_peak, z_poincare_global, z_poincare_max, beat_power, beat_score).
SymbolicInference.sliding_pole_scan — Method
sliding_pole_scan(x::AbstractVector{<:Real}, window_size::Int, step_size::Int;
delay_samples::Int=8, lmin::Int=3, tol_rad::Real=0.58,
pad::Int=64, method::Symbol=:phase, epsilon::Real=0.5,
laplace::Real=0.5, baseline_markov=nothing)Slide a window of length window_size (advancing by step_size) across x, tracking phase-lock persistence (method=:phase, via extract_phase_runs) or local recurrence persistence (method=:recurrence) in each window.
For each window, estimates 1st-order Markov transition parameters (p00, p01, p10, p11) and computes:
z0,gap: dominant pole and gapz0 - 1of the Markov run-avoidance GF viaAnalyticComb.markov_dominant_pole.persistence_pole,persistence_gap:1 / p11and1 / p11 - 1(vanishing toward0as coherent locking stabilizes).z_scores: exact Markov BGF Z-score of observed run persistence againstbaseline_markov(or pooled signal Markov parameters whenbaseline_markov=nothing).z_local: clustering Z-score against the window's own Markov parameters.
Returns a named tuple (starts, ends, centers, z0, gap, persistence_pole, persistence_gap, p11, p_stat, prograde_rate, max_run, z_scores, z_local, baseline_markov).
SymbolicInference.symbolic_transition_network — Method
symbolic_transition_network(syms::AbstractVector{<:Integer};
m::Int=maximum(syms), lag::Int=1)Construct the Symbolic Transition Network (STN) of a discrete symbolic trajectory syms taking values in 1:m at transition lag lag.
Computes:
counts:m × minteger transition count matrix $\mathbf{C}$P:m × mrow-stochastic empirical transition probability matrix $\mathbf{P}$stationary: stationary distribution $\boldsymbol{\pi}$ satisfying $\boldsymbol{\pi}^T \mathbf{P} = \boldsymbol{\pi}^T$entropy_rate: Markov entropy rate $h = -\sum_{i,j} \pi_i P_{ij} \log P_{ij}$ (nats/step)closed_walks: closed walk traces on $\mathbf{P}$zeta_inv_coeffs: reciprocal dynamical zeta polynomial coefficients $\det(\mathbf{I} - z \mathbf{P})$ fromAnalyticComb.graph_closed_walks_gftopological_entropy: $h_{\text{top}} = \log \rho(\mathbf{A})$ of the binary transition support graph $\mathbf{A} = \mathbb{I}(\mathbf{C} > 0)$
SymbolicInference.symbolic_word_test — Method
symbolic_word_test(syms::AbstractVector{<:Integer}, pattern::AbstractVector{<:Integer};
alphabet_size::Int=maximum(syms), null_model::Symbol=:iid,
overlapping::Bool=true, probs=nothing, trans_matrix=nothing)Test the statistical significance of an arbitrary symbolic word/motif pattern inside a 1D symbolic sequence syms over alphabet 1:alphabet_size:
null_model=:iid: Uses Guibas–Odlyzko autocorrelation polynomials (AnalyticComb.pattern_occurrences_momentsand exact finite-sampleAnalyticComb.pattern_pval).null_model=:markov: Constructs an exact KMP–Markov transfer matrix (AnalyticComb.transfer_matrix_moments) calibrated to the empirical (or suppliedtrans_matrix) 1st-order transition probabilities.
Returns a NamedTuple: (observed, expected, var, std, z_score, p_value, p_value_exact, null_model).