mstsa 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mstsa-0.3.0/LICENSE +0 -0
- mstsa-0.3.0/PKG-INFO +190 -0
- mstsa-0.3.0/README.md +154 -0
- mstsa-0.3.0/mstsa/__init__.py +92 -0
- mstsa-0.3.0/mstsa/_c_entropy_build.py +23 -0
- mstsa-0.3.0/mstsa/_lz76_build.py +22 -0
- mstsa-0.3.0/mstsa/_se_build.py +29 -0
- mstsa-0.3.0/mstsa/eeg.py +243 -0
- mstsa-0.3.0/mstsa/markov.py +1035 -0
- mstsa-0.3.0/mstsa/microsynt.py +238 -0
- mstsa-0.3.0/mstsa/mstsa.py +1193 -0
- mstsa-0.3.0/mstsa/src/c_entropy.c +55 -0
- mstsa-0.3.0/mstsa/src/lz76.c +46 -0
- mstsa-0.3.0/mstsa/src/se.c +176 -0
- mstsa-0.3.0/mstsa/stats.py +933 -0
- mstsa-0.3.0/mstsa.egg-info/PKG-INFO +190 -0
- mstsa-0.3.0/mstsa.egg-info/SOURCES.txt +22 -0
- mstsa-0.3.0/mstsa.egg-info/dependency_links.txt +1 -0
- mstsa-0.3.0/mstsa.egg-info/requires.txt +12 -0
- mstsa-0.3.0/mstsa.egg-info/top_level.txt +1 -0
- mstsa-0.3.0/pyproject.toml +60 -0
- mstsa-0.3.0/setup.cfg +4 -0
- mstsa-0.3.0/setup.py +9 -0
- mstsa-0.3.0/tests/test_mstsa.py +211 -0
mstsa-0.3.0/LICENSE
ADDED
|
File without changes
|
mstsa-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mstsa
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Microstate Time Series Analysis
|
|
5
|
+
Author-email: Frederic von Wegner <fvw.github@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/Frederic-vW/mstsa
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/Frederic-vW/mstsa/issues
|
|
8
|
+
Project-URL: Documentation, https://github.com/Frederic-vW/mstsa#readme
|
|
9
|
+
Keywords: EEG,microstate,time series,information theory,Markov chain,entropy
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Requires-Python: >=3.8
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: numpy>=1.21
|
|
25
|
+
Requires-Dist: scipy>=1.7
|
|
26
|
+
Requires-Dist: matplotlib>=3.4
|
|
27
|
+
Requires-Dist: numba>=0.54
|
|
28
|
+
Requires-Dist: cffi>=1.15
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
32
|
+
Requires-Dist: sphinx; extra == "dev"
|
|
33
|
+
Requires-Dist: sphinx-rtd-theme; extra == "dev"
|
|
34
|
+
Requires-Dist: numpydoc; extra == "dev"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# mstsa — Microstate Time Series Analysis
|
|
38
|
+
|
|
39
|
+
[](LICENSE)
|
|
40
|
+
[](https://www.python.org/)
|
|
41
|
+
|
|
42
|
+
`mstsa` is a Python package for information-theoretic and statistical analysis
|
|
43
|
+
of discrete symbolic time series, with a particular focus on EEG microstate
|
|
44
|
+
sequences.
|
|
45
|
+
|
|
46
|
+
The source code is available at [GitHub](https://github.com/Frederic-vW/mstsa).
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Features
|
|
51
|
+
|
|
52
|
+
### Symbol statistics
|
|
53
|
+
- Empirical probability mass function (`pmf`)
|
|
54
|
+
- Transition probability matrices — conditional (`tpm_cond`), joint
|
|
55
|
+
(`tpm_joint`), expected under independence (`tpm_joint_exp`)
|
|
56
|
+
- Sojourn-time (lifetime) distributions (`lifetime_histograms`,
|
|
57
|
+
`lifetimes_unordered`)
|
|
58
|
+
- Microstate duration, occurrence, and coverage (`dur_occ_cov`)
|
|
59
|
+
- Embedded jump process extraction (`embedded_process`)
|
|
60
|
+
|
|
61
|
+
### Information-theoretic measures
|
|
62
|
+
- Shannon entropy (`h1`), joint entropy (`h2`), *k*-gram entropy (`hk`)
|
|
63
|
+
- Rényi entropy (`renyi_entropy`), Tsallis entropy (`tsallis_entropy`)
|
|
64
|
+
- Entropy rate and excess entropy by linear regression (`entropy_rate`)
|
|
65
|
+
- Active information storage (`ais`)
|
|
66
|
+
- Auto-information function — empirical (`aif`) and Markov-predicted (`aif_mc`)
|
|
67
|
+
- Partial auto-information function (`paif`)
|
|
68
|
+
- Sample entropy for continuous signals (`sample_entropy_cont`,
|
|
69
|
+
`sample_entropy_fast_cont_py`) and discrete sequences (`sample_entropy_disc`,
|
|
70
|
+
`sample_entropy_fast_disc_py`)
|
|
71
|
+
- Lempel-Ziv complexity (`lz76`)
|
|
72
|
+
|
|
73
|
+
### Markov chain analysis
|
|
74
|
+
- First-order Markov chain surrogate generation (`mc_sample_path`)
|
|
75
|
+
- Theoretical entropy rate under Markov assumption (`entropy_rate_mc`, `entropy_rates_mc`)
|
|
76
|
+
- Theoretical auto-information function of a Markov chain (`aif_mc`)
|
|
77
|
+
- Expected sample entropy under a Markov model (`sample_entropy_mc`, `sample_entropies_mc`)
|
|
78
|
+
- Theoretical duration, occurrence, and coverage under a Markov model (`dur_occ_cov_mc`)
|
|
79
|
+
- Joint and trajectory probabilities under a Markov model (`p_joint_mc`, `p_ngram_mc`)
|
|
80
|
+
- Continuous-time Markov chain generator matrix (`generator_matrix`)
|
|
81
|
+
- Stationary distribution (`p_stationary`)
|
|
82
|
+
- Relaxation time / spectral gap (`relaxation_time`)
|
|
83
|
+
- Nearest reversible Markov chain (`nearest_reversible_mc`, requires `cvxopt`)
|
|
84
|
+
|
|
85
|
+
### Statistical tests (Kullback-Technometrics framework)
|
|
86
|
+
- Zero-order Markovianity / i.i.d. test (`test_markov0`)
|
|
87
|
+
- First-order Markovianity test (`test_markov1`)
|
|
88
|
+
- Second-order Markovianity test (`test_markov2`)
|
|
89
|
+
- Conditional homogeneity / stationarity (`test_cond_homogeneity`)
|
|
90
|
+
- Marginal homogeneity (`test_j_homogeneity`)
|
|
91
|
+
- Joint transition homogeneity (`test_jk_homogeneity`)
|
|
92
|
+
- Transition-matrix symmetry / detailed balance (`test_symmetry`)
|
|
93
|
+
- Geometric (exponential) sojourn-time test (`test_geometric_seq`, `test_geometric_dist`)
|
|
94
|
+
- Test against reference transition matrix (`test_transition_matrix`)
|
|
95
|
+
- Microstate syntax / transition test across subjects (`transition_syntax_test`)
|
|
96
|
+
|
|
97
|
+
### Other analyses
|
|
98
|
+
- Detrended fluctuation analysis (`dfa`) and rescaled-range analysis
|
|
99
|
+
(`rescaled_range`), with Hurst exponents of microstate indicator functions
|
|
100
|
+
(`hurst_exponents_dfa`, `hurst_exponents_rs`)
|
|
101
|
+
- Detailed balance statistics (`detailed_balance`, `detailed_balance_cond`,
|
|
102
|
+
`detailed_balance_joint`)
|
|
103
|
+
- Random walk construction from symbolic sequence (`randomwalk`, `partitions`)
|
|
104
|
+
- Power spectral densities of characteristic microstate functions (`spectra`)
|
|
105
|
+
- EEG complexity measures Ω, Σ, Φ, LC (`complexity_ospl`)
|
|
106
|
+
- Multiple-comparisons correction (`multiple_comparisons`)
|
|
107
|
+
- Microstate syntax analysis (`Microsynt`)
|
|
108
|
+
|
|
109
|
+
### Optional C extensions
|
|
110
|
+
For improved performance on entropy computations (`hk`), sample entropy, and
|
|
111
|
+
Lempel-Ziv complexity, `mstsa` builds optional CFFI-linked C extensions
|
|
112
|
+
(`_c_entropy`, `_se`, `_lz76`) automatically during installation, provided a
|
|
113
|
+
C compiler is available on the system (e.g. `gcc`/`build-essential` on
|
|
114
|
+
Linux, Xcode Command Line Tools on macOS, MSVC Build Tools on Windows). No
|
|
115
|
+
manual build step is required.
|
|
116
|
+
|
|
117
|
+
If a compiler is unavailable or a compiled extension otherwise fails to
|
|
118
|
+
import, `mstsa` falls back automatically to pure-Python / Numba
|
|
119
|
+
implementations and emits a `UserWarning` noting the slower fallback is in
|
|
120
|
+
use.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Installation
|
|
125
|
+
|
|
126
|
+
### From PyPI (once published)
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
pip install mstsa
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### From source
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
git clone https://github.com/Frederic-vW/mstsa.git
|
|
136
|
+
cd mstsa/packaging
|
|
137
|
+
pip install -e .
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Optional dependencies
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
pip install mstsa[qp] # nearest_reversible_mc (requires cvxopt)
|
|
144
|
+
pip install mstsa[mc_tests] # multiple_comparisons (requires statsmodels)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Quick start
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
import numpy as np
|
|
153
|
+
from mstsa import pmf, tpm_cond, h1, entropy_rate, aif, test_markov0, test_markov1
|
|
154
|
+
|
|
155
|
+
# Load or create a symbolic sequence
|
|
156
|
+
rng = np.random.default_rng(42)
|
|
157
|
+
x = rng.integers(0, 4, size=10000)
|
|
158
|
+
nc = 4 # number of symbols
|
|
159
|
+
|
|
160
|
+
# Symbol distribution and transition matrix
|
|
161
|
+
p = pmf(x, nc)
|
|
162
|
+
T = tpm_cond(x, nc)
|
|
163
|
+
|
|
164
|
+
# Shannon entropy and entropy rate
|
|
165
|
+
print(f"Shannon entropy: {h1(x, nc):.3f} bits")
|
|
166
|
+
er, ee = entropy_rate(x, nc, kmax=8)
|
|
167
|
+
print(f"Entropy rate: {er:.3f} bits/sample")
|
|
168
|
+
|
|
169
|
+
# Auto-information function
|
|
170
|
+
aif_vals = aif(x, nc, kmax=20)
|
|
171
|
+
|
|
172
|
+
# Markov order tests
|
|
173
|
+
p0 = test_markov0(x, nc, verbose=True)
|
|
174
|
+
p1 = test_markov1(x, nc, verbose=True)
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Citation
|
|
180
|
+
|
|
181
|
+
If you use `mstsa` in your research, please cite:
|
|
182
|
+
|
|
183
|
+
> von Wegner, F. (2025). mstsa: Microstate Time Series Analysis.
|
|
184
|
+
> *Journal of Open Source Software* (submitted).
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## License
|
|
189
|
+
|
|
190
|
+
MIT — see [LICENSE](LICENSE).
|
mstsa-0.3.0/README.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# mstsa — Microstate Time Series Analysis
|
|
2
|
+
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
[](https://www.python.org/)
|
|
5
|
+
|
|
6
|
+
`mstsa` is a Python package for information-theoretic and statistical analysis
|
|
7
|
+
of discrete symbolic time series, with a particular focus on EEG microstate
|
|
8
|
+
sequences.
|
|
9
|
+
|
|
10
|
+
The source code is available at [GitHub](https://github.com/Frederic-vW/mstsa).
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
### Symbol statistics
|
|
17
|
+
- Empirical probability mass function (`pmf`)
|
|
18
|
+
- Transition probability matrices — conditional (`tpm_cond`), joint
|
|
19
|
+
(`tpm_joint`), expected under independence (`tpm_joint_exp`)
|
|
20
|
+
- Sojourn-time (lifetime) distributions (`lifetime_histograms`,
|
|
21
|
+
`lifetimes_unordered`)
|
|
22
|
+
- Microstate duration, occurrence, and coverage (`dur_occ_cov`)
|
|
23
|
+
- Embedded jump process extraction (`embedded_process`)
|
|
24
|
+
|
|
25
|
+
### Information-theoretic measures
|
|
26
|
+
- Shannon entropy (`h1`), joint entropy (`h2`), *k*-gram entropy (`hk`)
|
|
27
|
+
- Rényi entropy (`renyi_entropy`), Tsallis entropy (`tsallis_entropy`)
|
|
28
|
+
- Entropy rate and excess entropy by linear regression (`entropy_rate`)
|
|
29
|
+
- Active information storage (`ais`)
|
|
30
|
+
- Auto-information function — empirical (`aif`) and Markov-predicted (`aif_mc`)
|
|
31
|
+
- Partial auto-information function (`paif`)
|
|
32
|
+
- Sample entropy for continuous signals (`sample_entropy_cont`,
|
|
33
|
+
`sample_entropy_fast_cont_py`) and discrete sequences (`sample_entropy_disc`,
|
|
34
|
+
`sample_entropy_fast_disc_py`)
|
|
35
|
+
- Lempel-Ziv complexity (`lz76`)
|
|
36
|
+
|
|
37
|
+
### Markov chain analysis
|
|
38
|
+
- First-order Markov chain surrogate generation (`mc_sample_path`)
|
|
39
|
+
- Theoretical entropy rate under Markov assumption (`entropy_rate_mc`, `entropy_rates_mc`)
|
|
40
|
+
- Theoretical auto-information function of a Markov chain (`aif_mc`)
|
|
41
|
+
- Expected sample entropy under a Markov model (`sample_entropy_mc`, `sample_entropies_mc`)
|
|
42
|
+
- Theoretical duration, occurrence, and coverage under a Markov model (`dur_occ_cov_mc`)
|
|
43
|
+
- Joint and trajectory probabilities under a Markov model (`p_joint_mc`, `p_ngram_mc`)
|
|
44
|
+
- Continuous-time Markov chain generator matrix (`generator_matrix`)
|
|
45
|
+
- Stationary distribution (`p_stationary`)
|
|
46
|
+
- Relaxation time / spectral gap (`relaxation_time`)
|
|
47
|
+
- Nearest reversible Markov chain (`nearest_reversible_mc`, requires `cvxopt`)
|
|
48
|
+
|
|
49
|
+
### Statistical tests (Kullback-Technometrics framework)
|
|
50
|
+
- Zero-order Markovianity / i.i.d. test (`test_markov0`)
|
|
51
|
+
- First-order Markovianity test (`test_markov1`)
|
|
52
|
+
- Second-order Markovianity test (`test_markov2`)
|
|
53
|
+
- Conditional homogeneity / stationarity (`test_cond_homogeneity`)
|
|
54
|
+
- Marginal homogeneity (`test_j_homogeneity`)
|
|
55
|
+
- Joint transition homogeneity (`test_jk_homogeneity`)
|
|
56
|
+
- Transition-matrix symmetry / detailed balance (`test_symmetry`)
|
|
57
|
+
- Geometric (exponential) sojourn-time test (`test_geometric_seq`, `test_geometric_dist`)
|
|
58
|
+
- Test against reference transition matrix (`test_transition_matrix`)
|
|
59
|
+
- Microstate syntax / transition test across subjects (`transition_syntax_test`)
|
|
60
|
+
|
|
61
|
+
### Other analyses
|
|
62
|
+
- Detrended fluctuation analysis (`dfa`) and rescaled-range analysis
|
|
63
|
+
(`rescaled_range`), with Hurst exponents of microstate indicator functions
|
|
64
|
+
(`hurst_exponents_dfa`, `hurst_exponents_rs`)
|
|
65
|
+
- Detailed balance statistics (`detailed_balance`, `detailed_balance_cond`,
|
|
66
|
+
`detailed_balance_joint`)
|
|
67
|
+
- Random walk construction from symbolic sequence (`randomwalk`, `partitions`)
|
|
68
|
+
- Power spectral densities of characteristic microstate functions (`spectra`)
|
|
69
|
+
- EEG complexity measures Ω, Σ, Φ, LC (`complexity_ospl`)
|
|
70
|
+
- Multiple-comparisons correction (`multiple_comparisons`)
|
|
71
|
+
- Microstate syntax analysis (`Microsynt`)
|
|
72
|
+
|
|
73
|
+
### Optional C extensions
|
|
74
|
+
For improved performance on entropy computations (`hk`), sample entropy, and
|
|
75
|
+
Lempel-Ziv complexity, `mstsa` builds optional CFFI-linked C extensions
|
|
76
|
+
(`_c_entropy`, `_se`, `_lz76`) automatically during installation, provided a
|
|
77
|
+
C compiler is available on the system (e.g. `gcc`/`build-essential` on
|
|
78
|
+
Linux, Xcode Command Line Tools on macOS, MSVC Build Tools on Windows). No
|
|
79
|
+
manual build step is required.
|
|
80
|
+
|
|
81
|
+
If a compiler is unavailable or a compiled extension otherwise fails to
|
|
82
|
+
import, `mstsa` falls back automatically to pure-Python / Numba
|
|
83
|
+
implementations and emits a `UserWarning` noting the slower fallback is in
|
|
84
|
+
use.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Installation
|
|
89
|
+
|
|
90
|
+
### From PyPI (once published)
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install mstsa
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### From source
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
git clone https://github.com/Frederic-vW/mstsa.git
|
|
100
|
+
cd mstsa/packaging
|
|
101
|
+
pip install -e .
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Optional dependencies
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
pip install mstsa[qp] # nearest_reversible_mc (requires cvxopt)
|
|
108
|
+
pip install mstsa[mc_tests] # multiple_comparisons (requires statsmodels)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Quick start
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
import numpy as np
|
|
117
|
+
from mstsa import pmf, tpm_cond, h1, entropy_rate, aif, test_markov0, test_markov1
|
|
118
|
+
|
|
119
|
+
# Load or create a symbolic sequence
|
|
120
|
+
rng = np.random.default_rng(42)
|
|
121
|
+
x = rng.integers(0, 4, size=10000)
|
|
122
|
+
nc = 4 # number of symbols
|
|
123
|
+
|
|
124
|
+
# Symbol distribution and transition matrix
|
|
125
|
+
p = pmf(x, nc)
|
|
126
|
+
T = tpm_cond(x, nc)
|
|
127
|
+
|
|
128
|
+
# Shannon entropy and entropy rate
|
|
129
|
+
print(f"Shannon entropy: {h1(x, nc):.3f} bits")
|
|
130
|
+
er, ee = entropy_rate(x, nc, kmax=8)
|
|
131
|
+
print(f"Entropy rate: {er:.3f} bits/sample")
|
|
132
|
+
|
|
133
|
+
# Auto-information function
|
|
134
|
+
aif_vals = aif(x, nc, kmax=20)
|
|
135
|
+
|
|
136
|
+
# Markov order tests
|
|
137
|
+
p0 = test_markov0(x, nc, verbose=True)
|
|
138
|
+
p1 = test_markov1(x, nc, verbose=True)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Citation
|
|
144
|
+
|
|
145
|
+
If you use `mstsa` in your research, please cite:
|
|
146
|
+
|
|
147
|
+
> von Wegner, F. (2025). mstsa: Microstate Time Series Analysis.
|
|
148
|
+
> *Journal of Open Source Software* (submitted).
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""mstsa: Microstate Time Series Analysis.
|
|
2
|
+
|
|
3
|
+
A Python package for information-theoretic and statistical analysis
|
|
4
|
+
of discrete symbolic time series, with a focus on EEG microstate sequences.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .mstsa import (
|
|
8
|
+
# Entropy
|
|
9
|
+
h1,
|
|
10
|
+
h2,
|
|
11
|
+
hk,
|
|
12
|
+
entropy_rate,
|
|
13
|
+
renyi_entropy,
|
|
14
|
+
tsallis_entropy,
|
|
15
|
+
# Information / auto-information
|
|
16
|
+
aif,
|
|
17
|
+
ais,
|
|
18
|
+
paif,
|
|
19
|
+
# Sample entropy (discrete)
|
|
20
|
+
sample_entropy_disc,
|
|
21
|
+
sample_entropy_fast_disc_py,
|
|
22
|
+
# Sequence utilities
|
|
23
|
+
lifetime_histograms,
|
|
24
|
+
lifetimes_unordered,
|
|
25
|
+
dur_occ_cov,
|
|
26
|
+
embedded_process,
|
|
27
|
+
randomwalk,
|
|
28
|
+
spectra,
|
|
29
|
+
dfa,
|
|
30
|
+
rescaled_range,
|
|
31
|
+
hurst_exponents_dfa,
|
|
32
|
+
hurst_exponents_rs,
|
|
33
|
+
lz76,
|
|
34
|
+
partitions,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
from .markov import (
|
|
38
|
+
# Entropy
|
|
39
|
+
entropy_rate_mc,
|
|
40
|
+
entropy_rates_mc,
|
|
41
|
+
# Information / auto-information
|
|
42
|
+
aif_mc,
|
|
43
|
+
# Sample entropy
|
|
44
|
+
sample_entropy_mc,
|
|
45
|
+
sample_entropies_mc,
|
|
46
|
+
# Markov chain
|
|
47
|
+
mc_sample_path,
|
|
48
|
+
dur_occ_cov_mc,
|
|
49
|
+
generator_matrix,
|
|
50
|
+
p_joint_mc,
|
|
51
|
+
p_stationary,
|
|
52
|
+
p_ngram_mc,
|
|
53
|
+
relaxation_time,
|
|
54
|
+
nearest_reversible_mc,
|
|
55
|
+
tpm_cond,
|
|
56
|
+
tpm_joint,
|
|
57
|
+
tpm_joint_exp,
|
|
58
|
+
# Detailed balance
|
|
59
|
+
detailed_balance,
|
|
60
|
+
detailed_balance_cond,
|
|
61
|
+
detailed_balance_joint,
|
|
62
|
+
# Sequence utilities
|
|
63
|
+
pmf,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
from .eeg import (
|
|
67
|
+
complexity_ospl,
|
|
68
|
+
# Sample entropy (continuous)
|
|
69
|
+
sample_entropy_cont,
|
|
70
|
+
sample_entropy_fast_cont_py,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
from .microsynt import Microsynt
|
|
74
|
+
|
|
75
|
+
from .stats import (
|
|
76
|
+
multiple_comparisons,
|
|
77
|
+
test_cond_homogeneity,
|
|
78
|
+
test_geometric_dist,
|
|
79
|
+
test_geometric_seq,
|
|
80
|
+
test_j_homogeneity,
|
|
81
|
+
test_jk_homogeneity,
|
|
82
|
+
test_markov0,
|
|
83
|
+
test_markov1,
|
|
84
|
+
test_markov2,
|
|
85
|
+
test_symmetry,
|
|
86
|
+
test_transition_matrix,
|
|
87
|
+
transition_syntax_test,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
__version__ = "0.3.0"
|
|
91
|
+
__author__ = "Frederic von Wegner"
|
|
92
|
+
__email__ = "fvw.github@gmail.com"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from cffi import FFI
|
|
3
|
+
|
|
4
|
+
ffi = FFI()
|
|
5
|
+
|
|
6
|
+
ffi.cdef("""
|
|
7
|
+
double c_entropy(int *x, size_t n, size_t m, size_t k);
|
|
8
|
+
""")
|
|
9
|
+
|
|
10
|
+
_src = os.path.join(os.path.dirname(__file__), "src", "c_entropy.c")
|
|
11
|
+
|
|
12
|
+
ffi.set_source(
|
|
13
|
+
"mstsa._c_entropy",
|
|
14
|
+
"""
|
|
15
|
+
double c_entropy(int *x, size_t n, size_t m, size_t k);
|
|
16
|
+
""",
|
|
17
|
+
sources=[_src],
|
|
18
|
+
libraries=["m"],
|
|
19
|
+
extra_compile_args=["-O3"],
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
if __name__ == "__main__":
|
|
23
|
+
ffi.compile(verbose=True)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from cffi import FFI
|
|
3
|
+
|
|
4
|
+
ffi = FFI()
|
|
5
|
+
|
|
6
|
+
ffi.cdef("""
|
|
7
|
+
int lz76(int *x, int n);
|
|
8
|
+
""")
|
|
9
|
+
|
|
10
|
+
_src = os.path.join(os.path.dirname(__file__), "src", "lz76.c")
|
|
11
|
+
|
|
12
|
+
ffi.set_source(
|
|
13
|
+
"mstsa._lz76",
|
|
14
|
+
"""
|
|
15
|
+
int lz76(int *x, int n);
|
|
16
|
+
""",
|
|
17
|
+
sources=[_src],
|
|
18
|
+
extra_compile_args=["-O3"],
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
if __name__ == "__main__":
|
|
22
|
+
ffi.compile(verbose=True)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from cffi import FFI
|
|
3
|
+
|
|
4
|
+
ffi = FFI()
|
|
5
|
+
|
|
6
|
+
ffi.cdef("""
|
|
7
|
+
double sample_entropy_cont(double *x, size_t n, size_t m, size_t tau, double r);
|
|
8
|
+
double sample_entropy_disc(long *x, size_t n, size_t m, size_t tau);
|
|
9
|
+
int sample_entropy_cont_fast(double *se, double *x, size_t n, size_t m, double r);
|
|
10
|
+
int sample_entropy_disc_fast(double *se, long *x, size_t n, size_t m);
|
|
11
|
+
""")
|
|
12
|
+
|
|
13
|
+
_src = os.path.join(os.path.dirname(__file__), "src", "se.c")
|
|
14
|
+
|
|
15
|
+
ffi.set_source(
|
|
16
|
+
"mstsa._se",
|
|
17
|
+
"""
|
|
18
|
+
double sample_entropy_cont(double *x, size_t n, size_t m, size_t tau, double r);
|
|
19
|
+
double sample_entropy_disc(long *x, size_t n, size_t m, size_t tau);
|
|
20
|
+
int sample_entropy_cont_fast(double *se, double *x, size_t n, size_t m, double r);
|
|
21
|
+
int sample_entropy_disc_fast(double *se, long *x, size_t n, size_t m);
|
|
22
|
+
""",
|
|
23
|
+
sources=[_src],
|
|
24
|
+
libraries=["m"],
|
|
25
|
+
extra_compile_args=["-O3"],
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
if __name__ == "__main__":
|
|
29
|
+
ffi.compile(verbose=True)
|