scientific-skills/neurokit2/references/complexity.md
Complexity measures quantify the irregularity, unpredictability, and multiscale structure of time series signals. NeuroKit2 provides comprehensive entropy, fractal dimension, and nonlinear dynamics measures for assessing physiological signal complexity.
Compute multiple complexity metrics simultaneously for exploratory analysis.
complexity_indices = nk.complexity(signal, sampling_rate=1000, show=False)
Returns:
Use case:
Before computing complexity measures, optimal embedding parameters should be determined:
Determine optimal time delay (τ) for phase space reconstruction.
optimal_tau = nk.complexity_delay(signal, delay_max=100, method='fraser1986', show=False)
Methods:
'fraser1986': Mutual information first minimum'theiler1990': Autocorrelation first zero crossing'casdagli1991': Cao's methodUse for: Embedding delay in entropy, attractor reconstruction
Determine optimal embedding dimension (m).
optimal_m = nk.complexity_dimension(signal, delay=None, dimension_max=20,
method='afn', show=False)
Methods:
'afn': Average False Nearest Neighbors'fnn': False Nearest Neighbors'correlation': Correlation dimension saturationUse for: Entropy calculations, phase space reconstruction
Determine optimal tolerance (r) for entropy measures.
optimal_r = nk.complexity_tolerance(signal, method='sd', show=False)
Methods:
'sd': Standard deviation-based (0.1-0.25 × SD typical)'maxApEn': Maximize ApEn'recurrence': Based on recurrence rateUse for: Approximate entropy, sample entropy
Determine optimal k parameter for Higuchi fractal dimension.
optimal_k = nk.complexity_k(signal, k_max=20, show=False)
Use for: Higuchi fractal dimension calculation
Entropy quantifies randomness, unpredictability, and information content.
Shannon entropy - classical information-theoretic measure.
shannon_entropy = nk.entropy_shannon(signal)
Interpretation:
Use cases:
Approximate Entropy (ApEn) - regularity of patterns.
apen = nk.entropy_approximate(signal, delay=1, dimension=2, tolerance='sd')
Parameters:
delay: Time delay (τ)dimension: Embedding dimension (m)tolerance: Similarity threshold (r)Interpretation:
Physiological applications:
Sample Entropy (SampEn) - improved ApEn.
sampen = nk.entropy_sample(signal, delay=1, dimension=2, tolerance='sd')
Advantages over ApEn:
Interpretation:
Typical values:
Multiscale Entropy (MSE) - complexity across temporal scales.
mse = nk.entropy_multiscale(signal, scale=20, dimension=2, tolerance='sd',
method='MSEn', show=False)
Methods:
'MSEn': Multiscale Sample Entropy'MSApEn': Multiscale Approximate Entropy'CMSE': Composite Multiscale Entropy'RCMSE': Refined Composite Multiscale EntropyInterpretation:
Use cases:
Fuzzy Entropy - uses fuzzy membership functions.
fuzzen = nk.entropy_fuzzy(signal, delay=1, dimension=2, tolerance='sd', r=0.2)
Advantages:
Permutation Entropy - based on ordinal patterns.
perment = nk.entropy_permutation(signal, delay=1, dimension=3)
Method:
Interpretation:
Use cases:
Spectral Entropy - based on power spectrum.
spec_ent = nk.entropy_spectral(signal, sampling_rate=1000, bands=None)
Method:
Interpretation:
Use cases:
Singular Value Decomposition Entropy.
svd_ent = nk.entropy_svd(signal, delay=1, dimension=2)
Method:
Use cases:
Differential Entropy - continuous analog of Shannon entropy.
diff_ent = nk.entropy_differential(signal)
Use for: Continuous probability distributions
Tsallis Entropy:
tsallis = nk.entropy_tsallis(signal, q=2)
Rényi Entropy:
renyi = nk.entropy_renyi(signal, alpha=2)
Additional specialized entropies:
entropy_attention(): Attention entropyentropy_grid(): Grid-based entropyentropy_increment(): Increment entropyentropy_slope(): Slope entropyentropy_dispersion(): Dispersion entropyentropy_symbolicdynamic(): Symbolic dynamics entropyentropy_range(): Range entropyentropy_phase(): Phase entropyentropy_quadratic(), entropy_cumulative_residual(), entropy_rate(): Specialized variantsFractal dimensions characterize self-similarity and roughness.
Katz Fractal Dimension - waveform complexity.
kfd = nk.fractal_katz(signal)
Interpretation:
1: increasing roughness and complexity
Advantages:
Higuchi Fractal Dimension - self-similarity.
hfd = nk.fractal_higuchi(signal, k_max=10)
Method:
Interpretation:
Use cases:
Petrosian Fractal Dimension - rapid estimation.
pfd = nk.fractal_petrosian(signal)
Advantages:
Sevcik Fractal Dimension - normalized waveform complexity.
sfd = nk.fractal_sevcik(signal)
Normalized Length Density - curve length-based measure.
nld = nk.fractal_nld(signal)
Power Spectral Density Slope - frequency-domain fractal measure.
slope = nk.fractal_psdslope(signal, sampling_rate=1000)
Method:
Interpretation:
Hurst Exponent - long-range dependence.
hurst = nk.fractal_hurst(signal, show=False)
Interpretation:
Use cases:
Correlation Dimension - attractor dimensionality.
corr_dim = nk.fractal_correlation(signal, delay=1, dimension=10, radius=64)
Method:
Interpretation:
Detrended Fluctuation Analysis - scaling exponent.
dfa_alpha = nk.fractal_dfa(signal, multifractal=False, q=2, show=False)
Interpretation:
HRV applications:
Multifractal DFA - multiscale fractal properties.
mfdfa_results = nk.fractal_mfdfa(signal, q=None, show=False)
Method:
Returns:
Use cases:
Multifractal Nonlinearity - deviation from monofractal.
tmf = nk.fractal_tmf(signal)
Interpretation:
Density Fractal Dimension.
density_fd = nk.fractal_density(signal)
Line Length - total variation measure.
linelength = nk.fractal_linelength(signal)
Use case:
Largest Lyapunov Exponent - chaos and divergence.
lyap = nk.complexity_lyapunov(signal, delay=None, dimension=None,
sampling_rate=1000, show=False)
Interpretation:
Use cases:
Lempel-Ziv Complexity - algorithmic complexity.
lz = nk.complexity_lempelziv(signal, symbolize='median')
Method:
Interpretation:
Use cases:
Recurrence Quantification Analysis - phase space recurrences.
rqa_indices = nk.complexity_rqa(signal, delay=1, dimension=3, tolerance='sd')
Metrics:
Interpretation:
Use cases:
Hjorth Parameters - time-domain complexity.
hjorth = nk.complexity_hjorth(signal)
Metrics:
Use cases:
Decorrelation Time - memory duration.
decorr_time = nk.complexity_decorrelation(signal, show=False)
Interpretation:
Relative Roughness - smoothness measure.
roughness = nk.complexity_relativeroughness(signal)
Fisher Information - measure of order.
fisher = nk.fisher_information(signal, delay=1, dimension=2)
Interpretation:
Use cases:
Fisher-Shannon Information Product.
fs = nk.fishershannon_information(signal)
Method:
Mutual Information - shared information between variables.
mi = nk.mutual_information(signal1, signal2, method='knn')
Methods:
'knn': k-nearest neighbors (nonparametric)'kernel': Kernel density estimation'binning': Histogram-basedUse cases:
| Measure | Minimum Length | Optimal Length |
|---|---|---|
| Shannon entropy | 50 | 200+ |
| ApEn, SampEn | 100-300 | 500-1000 |
| Multiscale entropy | 500 | 1000+ per scale |
| DFA | 500 | 1000+ |
| Lyapunov | 1000 | 5000+ |
| Correlation dimension | 1000 | 5000+ |
General guidelines:
Sensitivity:
Standardization:
Stationarity:
Context-dependent:
Complexity vs. randomness:
Cardiovascular:
Neuroscience:
Psychology:
Aging:
Critical transitions: