FluctuationAnalysisTools 1.7.0__tar.gz → 1.8.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.
- fluctuationanalysistools-1.8.0/.gitattributes +1 -0
- fluctuationanalysistools-1.8.0/.pre-commit-config.yaml +29 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/CHANGELOG.md +14 -5
- fluctuationanalysistools-1.8.0/CONTRIBUTION.md +47 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/FluctuationAnalysisTools.egg-info/PKG-INFO +64 -11
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/FluctuationAnalysisTools.egg-info/SOURCES.txt +9 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/LICENSE.txt +2 -2
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/PKG-INFO +64 -11
- fluctuationanalysistools-1.8.0/README.md +104 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/_version.py +2 -2
- fluctuationanalysistools-1.8.0/StatTools/analysis/nonequidistant/__init__.py +1 -0
- fluctuationanalysistools-1.8.0/StatTools/analysis/nonequidistant/dfa.py +111 -0
- fluctuationanalysistools-1.8.0/StatTools/generators/kasdin_generator.py +71 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/generators/lbfbm_generator.py +16 -11
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/pyproject.toml +1 -0
- fluctuationanalysistools-1.8.0/research/data_recovery.ipynb +4921 -0
- fluctuationanalysistools-1.8.0/tests/test_filter.py +109 -0
- fluctuationanalysistools-1.8.0/tests/test_kasdin_generator.py +56 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/tests/test_lbfbm_generator.py +4 -4
- fluctuationanalysistools-1.8.0/tests/test_ne_dfa.py +98 -0
- fluctuationanalysistools-1.7.0/README.md +0 -51
- fluctuationanalysistools-1.7.0/tests/test_filter.py +0 -96
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/.github/workflows/run-tests.yml +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/.github/workflows/test-and-release.yml +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/.gitignore +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/DFA.cpp +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/FluctuationAnalysisTools.egg-info/dependency_links.txt +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/FluctuationAnalysisTools.egg-info/top_level.txt +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/MANIFEST.in +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/Gamma.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/__init__.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/analysis/__init__.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/analysis/dfa.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/analysis/dpcca.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/analysis/dpcca_as_class.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/analysis/fa.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/analysis/movmean.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/analysis/qss.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/auxiliary.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/generators/__init__.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/generators/base_filter.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/generators/cholesky_transform.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/generators/fbm.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools/generators/field_generator.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/StatTools_C_API.cpp +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/requirements.txt +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/research/lbfbm_generator.ipynb +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/setup.cfg +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/setup.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/tests/test_dfa.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/tests/test_dpcca.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/tests/test_fa.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/tests/test_filtered_array.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/tests_manual/cholesky_with_R.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/tests_manual/dfa_test.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/tests_manual/dpcca_pipe.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/tests_manual/dpcca_test.py +0 -0
- {fluctuationanalysistools-1.7.0 → fluctuationanalysistools-1.8.0}/tests_manual/test_buffer.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*.ipynb linguist-vendored
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# See https://pre-commit.com for more information
|
|
2
|
+
# See https://pre-commit.com/hooks.html for more hooks
|
|
3
|
+
repos:
|
|
4
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
5
|
+
rev: v3.2.0
|
|
6
|
+
hooks:
|
|
7
|
+
- id: trailing-whitespace
|
|
8
|
+
- id: end-of-file-fixer
|
|
9
|
+
- id: check-yaml
|
|
10
|
+
- id: check-added-large-files
|
|
11
|
+
- id: check-case-conflict
|
|
12
|
+
- id: check-json
|
|
13
|
+
- id: detect-private-key
|
|
14
|
+
- repo: https://github.com/pycqa/isort
|
|
15
|
+
rev: 6.0.0
|
|
16
|
+
hooks:
|
|
17
|
+
- id: isort
|
|
18
|
+
name: isort (python)
|
|
19
|
+
stages: [pre-commit, pre-merge-commit, pre-push, manual]
|
|
20
|
+
require_serial: true
|
|
21
|
+
language: python
|
|
22
|
+
types_or: [cython, pyi, python]
|
|
23
|
+
args: ["--profile", "black", '--filter-files']
|
|
24
|
+
minimum_pre_commit_version: '3.2.0'
|
|
25
|
+
- repo: https://github.com/psf/black-pre-commit-mirror
|
|
26
|
+
rev: 25.1.0
|
|
27
|
+
hooks:
|
|
28
|
+
- id: black
|
|
29
|
+
language_version: python3.10
|
|
@@ -1,24 +1,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.7.1
|
|
4
|
+
|
|
5
|
+
* [GH-23](https://github.com/Digiratory/StatTools/issues/23) feat: add Kasdin generator. fix: change first arg in lfilter in LBFBm generator.
|
|
6
|
+
* [GH-15](https://github.com/Digiratory/StatTools/issues/15) feat&fix: LBFBm generator update: generate with input value and return an increment instead of the absolute value of the signal.
|
|
7
|
+
* [GH-25](https://github.com/Digiratory/StatTools/issues/25) feat: Detrended Fluctuation Analysis (DFA) for a nonequidistant dataset.
|
|
8
|
+
|
|
9
|
+
## 1.7.0
|
|
10
|
+
|
|
2
11
|
* [GH-5](https://github.com/Digiratory/StatTools/issues/5) feat: add LBFBm generator, that generates a sequence based on the Hurst exponent.
|
|
3
12
|
* [PR-8](https://github.com/Digiratory/StatTools/pull/8) refactor: rework filter-based generator.
|
|
4
13
|
* [PR-8](https://github.com/Digiratory/StatTools/pull/8) tests: add new tests for DFA and generators.
|
|
5
14
|
* [GH-10](https://github.com/Digiratory/StatTools/issues/10) build: enable wheel building with setuptools-scm.
|
|
6
15
|
* [GH-10](https://github.com/Digiratory/StatTools/issues/10) doc: enchance pyproject.toml with urls for repository, issues, and changelog.
|
|
7
16
|
|
|
8
|
-
|
|
17
|
+
## 1.6.1
|
|
9
18
|
|
|
10
19
|
* [PR-3](https://github.com/Digiratory/StatTools/pull/3) feat: add conventional FA
|
|
11
20
|
|
|
12
|
-
|
|
21
|
+
## 1.6.0
|
|
13
22
|
|
|
14
23
|
* [GH-1](https://github.com/Digiratory/StatTools/issues/1) Add argument `n_integral=1` in `StatTools.analysis.dpcca.dpcca` to provide possibility to control integretion in the beggining of the dpcca(dfa) analysis pipeline.
|
|
15
24
|
* fix: failure is processes == 1 and 1d array
|
|
16
25
|
* fix: remove normalization from dpcca processing
|
|
17
26
|
|
|
18
|
-
|
|
27
|
+
## 1.0.1 - 1.0.9
|
|
19
28
|
|
|
20
29
|
* Minor updates
|
|
21
30
|
|
|
22
|
-
|
|
31
|
+
## 1.1.0
|
|
23
32
|
|
|
24
33
|
* Added C-compiled modules
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Contribution Guidelines
|
|
2
|
+
|
|
3
|
+
## Pre-Commit Usage
|
|
4
|
+
|
|
5
|
+
Before making any changes to the repository, please follow these steps:
|
|
6
|
+
|
|
7
|
+
1. Create a branch (if you have permissions) or fork the Repository: If you haven't already, fork this repository by clicking the "Fork" button in the top right corner of the GitHub page.
|
|
8
|
+
2. Clone the Forked Repository: Clone your forked repository to your local machine using the following command:
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
git clone https://github.com/your-username/StatTools.git
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**Note:** this step is optional if you are working on a branch that already exists in the repository and you are a member with write permissions:
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
3. Install Dependencies: Install any dependencies required for this project by running the following command in the cloned directory:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install -e .
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
4. Set Up Pre-Commit Hooks: Run the following commands to set up pre-commit hooks, which will check your code for errors and formatting before allowing you to commit:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pre-commit install
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
5. Make Changes: Make the necessary changes to the repository.
|
|
31
|
+
6. Test Your Code: Test your code by running any relevant tests or scripts.
|
|
32
|
+
7. Commit Your Changes: Commit your changes using git add . and git commit -m "Your Commit Message".
|
|
33
|
+
8. Push to GitHub: Push your committed changes to your forked repository on GitHub.
|
|
34
|
+
9. Create a pull request from [a fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork) or from your branch.
|
|
35
|
+
|
|
36
|
+
## Commit Messages
|
|
37
|
+
|
|
38
|
+
* Use the present tense when describing changes (e.g., "Add new feature" instead of "Added new feature").
|
|
39
|
+
* Be descriptive and concise, but avoid excessive detail.
|
|
40
|
+
* Follow the 50 character limit for the first line of the commit message.
|
|
41
|
+
|
|
42
|
+
## Issues and Bugs
|
|
43
|
+
|
|
44
|
+
* If you encounter any issues or bugs while contributing to this project, please create an issue on GitHub.
|
|
45
|
+
* Provide as much information as possible about the problem, including any relevant code snippets or steps to reproduce.
|
|
46
|
+
|
|
47
|
+
By following these guidelines, we can ensure that our contributions are high-quality and easy for others to understand.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: FluctuationAnalysisTools
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.8.0
|
|
4
4
|
Summary: This library allows to create and process long-term dependent datasets.
|
|
5
5
|
Author-email: Aleksandr Sinitca <amsinitca@etu.ru>, Alexandr Kuzmenko <alexander.k.spb@gmail.com>, Asya Lyanova <ailianova@etu.ru>
|
|
6
6
|
Maintainer-email: Aleksandr Sinitca <amsinitca@etu.ru>
|
|
@@ -13,19 +13,28 @@ License-File: LICENSE.txt
|
|
|
13
13
|
Dynamic: license-file
|
|
14
14
|
|
|
15
15
|
# StatTools
|
|
16
|
+
|
|
16
17
|
This library allows to create and process long-term dependent datasets.
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+

|
|
20
|
+

|
|
21
|
+

|
|
22
|
+

|
|
23
|
+
|
|
24
|
+
## Installation
|
|
23
25
|
|
|
24
26
|
You can install FluctuationAnalysisTools from [PyPI](https://pypi.org/project/FluctuationAnalysisTools/).
|
|
25
27
|
|
|
26
|
-
```
|
|
28
|
+
```bash
|
|
27
29
|
pip install FluctuationAnalysisTools
|
|
28
30
|
```
|
|
31
|
+
|
|
32
|
+
Or you can clone the repository and build it using the command
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install .
|
|
36
|
+
```
|
|
37
|
+
|
|
29
38
|
## Basis usage
|
|
30
39
|
|
|
31
40
|
1. To create a simple dataset with given Hurst parameter:
|
|
@@ -35,7 +44,7 @@ from StatTools.filters import FilteredArray
|
|
|
35
44
|
|
|
36
45
|
h = 0.8 # choose Hurst parameter
|
|
37
46
|
total_vectors = 1000 # total number of vectors in output
|
|
38
|
-
vectors_length = 1440 # each vector's length
|
|
47
|
+
vectors_length = 1440 # each vector's length
|
|
39
48
|
t = 8 # threads in use during computation
|
|
40
49
|
|
|
41
50
|
correlated_vectors = Filter(h, vectors_length).generate(n_vectors=total_vectors,
|
|
@@ -43,7 +52,9 @@ correlated_vectors = Filter(h, vectors_length).generate(n_vectors=total_vectors,
|
|
|
43
52
|
```
|
|
44
53
|
|
|
45
54
|
### Generators
|
|
55
|
+
|
|
46
56
|
1. Example of sequence generation based on the Hurst exponent.
|
|
57
|
+
|
|
47
58
|
```python
|
|
48
59
|
from StatTools.generators.hurst_generator import LBFBmGenerator
|
|
49
60
|
h = 0.8 # choose Hurst parameter
|
|
@@ -52,12 +63,54 @@ base = 1.2 # the basis for the filter optimization algorithm
|
|
|
52
63
|
target_len = 4000 # number of generation iterations
|
|
53
64
|
|
|
54
65
|
generator = LBFBmGenerator(h, filter_len, base)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
signal = []
|
|
67
|
+
for value in islice(generator, target_len):
|
|
68
|
+
signal.append(value)
|
|
58
69
|
```
|
|
70
|
+
|
|
59
71
|
For more information and generator validation, see [lbfbm_generator.ipynb](/research/lbfbm_generator.ipynb).
|
|
60
72
|
|
|
73
|
+
It is also possible to use the method of generating increments with a given H using `KasdinGenerator`.
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from StatTools.generators.kasdin_generator import KasdinGenerator
|
|
77
|
+
h = 0.8 # choose Hurst parameter
|
|
78
|
+
target_len = 4000 # number of generation iterations
|
|
79
|
+
|
|
80
|
+
generator = KasdinGenerator(h, length=target_len)
|
|
81
|
+
|
|
82
|
+
# the first option
|
|
83
|
+
signal = generator.get_full_sequence()
|
|
84
|
+
|
|
85
|
+
# the second option
|
|
86
|
+
signal_list = []
|
|
87
|
+
for sample in generator:
|
|
88
|
+
signal_list.append(sample)
|
|
89
|
+
```
|
|
90
|
+
For more information see Kasdin, N. J. (1995). Discrete simulation of colored noise and stochastic processes and 1/f/sup /spl alpha// power law noise generation. doi:10.1109/5.381848.
|
|
91
|
+
|
|
92
|
+
### Fluctuational Analysis
|
|
93
|
+
|
|
94
|
+
1. Example of Detrended Fluctuational Analysis (DFA)
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from StatTools.generators.base_filter import Filter
|
|
98
|
+
from StatTools.analysis.dfa import DFA
|
|
99
|
+
|
|
100
|
+
h = 0.7 # choose Hurst parameter
|
|
101
|
+
length = 6000 # vector's length
|
|
102
|
+
target_std = 1.0
|
|
103
|
+
target_mean = 0.0
|
|
104
|
+
|
|
105
|
+
generator = Filter(h, length, set_mean=target_mean, set_std=target_std)
|
|
106
|
+
trajectory = generator.generate(n_vectors=1)
|
|
107
|
+
|
|
108
|
+
actual_mean = np.mean(trajectory)
|
|
109
|
+
actual_std = np.std(trajectory, ddof=1)
|
|
110
|
+
actual_h = DFA(trajectory).find_h()
|
|
111
|
+
print(actual_h) # Should print a value close to 0.7
|
|
112
|
+
```
|
|
113
|
+
|
|
61
114
|
## Contributors
|
|
62
115
|
|
|
63
116
|
* [Alexandr Kuzmenko](https://github.com/alexandr-1k)
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
.gitattributes
|
|
1
2
|
.gitignore
|
|
3
|
+
.pre-commit-config.yaml
|
|
2
4
|
CHANGELOG.md
|
|
5
|
+
CONTRIBUTION.md
|
|
3
6
|
DFA.cpp
|
|
4
7
|
LICENSE.txt
|
|
5
8
|
MANIFEST.in
|
|
@@ -27,19 +30,25 @@ StatTools/analysis/dpcca_as_class.py
|
|
|
27
30
|
StatTools/analysis/fa.py
|
|
28
31
|
StatTools/analysis/movmean.py
|
|
29
32
|
StatTools/analysis/qss.py
|
|
33
|
+
StatTools/analysis/nonequidistant/__init__.py
|
|
34
|
+
StatTools/analysis/nonequidistant/dfa.py
|
|
30
35
|
StatTools/generators/__init__.py
|
|
31
36
|
StatTools/generators/base_filter.py
|
|
32
37
|
StatTools/generators/cholesky_transform.py
|
|
33
38
|
StatTools/generators/fbm.py
|
|
34
39
|
StatTools/generators/field_generator.py
|
|
40
|
+
StatTools/generators/kasdin_generator.py
|
|
35
41
|
StatTools/generators/lbfbm_generator.py
|
|
42
|
+
research/data_recovery.ipynb
|
|
36
43
|
research/lbfbm_generator.ipynb
|
|
37
44
|
tests/test_dfa.py
|
|
38
45
|
tests/test_dpcca.py
|
|
39
46
|
tests/test_fa.py
|
|
40
47
|
tests/test_filter.py
|
|
41
48
|
tests/test_filtered_array.py
|
|
49
|
+
tests/test_kasdin_generator.py
|
|
42
50
|
tests/test_lbfbm_generator.py
|
|
51
|
+
tests/test_ne_dfa.py
|
|
43
52
|
tests_manual/cholesky_with_R.py
|
|
44
53
|
tests_manual/dfa_test.py
|
|
45
54
|
tests_manual/dpcca_pipe.py
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright(с) 2025 All contributors.
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
|
5
5
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
6
|
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: FluctuationAnalysisTools
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.8.0
|
|
4
4
|
Summary: This library allows to create and process long-term dependent datasets.
|
|
5
5
|
Author-email: Aleksandr Sinitca <amsinitca@etu.ru>, Alexandr Kuzmenko <alexander.k.spb@gmail.com>, Asya Lyanova <ailianova@etu.ru>
|
|
6
6
|
Maintainer-email: Aleksandr Sinitca <amsinitca@etu.ru>
|
|
@@ -13,19 +13,28 @@ License-File: LICENSE.txt
|
|
|
13
13
|
Dynamic: license-file
|
|
14
14
|
|
|
15
15
|
# StatTools
|
|
16
|
+
|
|
16
17
|
This library allows to create and process long-term dependent datasets.
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+

|
|
20
|
+

|
|
21
|
+

|
|
22
|
+

|
|
23
|
+
|
|
24
|
+
## Installation
|
|
23
25
|
|
|
24
26
|
You can install FluctuationAnalysisTools from [PyPI](https://pypi.org/project/FluctuationAnalysisTools/).
|
|
25
27
|
|
|
26
|
-
```
|
|
28
|
+
```bash
|
|
27
29
|
pip install FluctuationAnalysisTools
|
|
28
30
|
```
|
|
31
|
+
|
|
32
|
+
Or you can clone the repository and build it using the command
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install .
|
|
36
|
+
```
|
|
37
|
+
|
|
29
38
|
## Basis usage
|
|
30
39
|
|
|
31
40
|
1. To create a simple dataset with given Hurst parameter:
|
|
@@ -35,7 +44,7 @@ from StatTools.filters import FilteredArray
|
|
|
35
44
|
|
|
36
45
|
h = 0.8 # choose Hurst parameter
|
|
37
46
|
total_vectors = 1000 # total number of vectors in output
|
|
38
|
-
vectors_length = 1440 # each vector's length
|
|
47
|
+
vectors_length = 1440 # each vector's length
|
|
39
48
|
t = 8 # threads in use during computation
|
|
40
49
|
|
|
41
50
|
correlated_vectors = Filter(h, vectors_length).generate(n_vectors=total_vectors,
|
|
@@ -43,7 +52,9 @@ correlated_vectors = Filter(h, vectors_length).generate(n_vectors=total_vectors,
|
|
|
43
52
|
```
|
|
44
53
|
|
|
45
54
|
### Generators
|
|
55
|
+
|
|
46
56
|
1. Example of sequence generation based on the Hurst exponent.
|
|
57
|
+
|
|
47
58
|
```python
|
|
48
59
|
from StatTools.generators.hurst_generator import LBFBmGenerator
|
|
49
60
|
h = 0.8 # choose Hurst parameter
|
|
@@ -52,12 +63,54 @@ base = 1.2 # the basis for the filter optimization algorithm
|
|
|
52
63
|
target_len = 4000 # number of generation iterations
|
|
53
64
|
|
|
54
65
|
generator = LBFBmGenerator(h, filter_len, base)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
signal = []
|
|
67
|
+
for value in islice(generator, target_len):
|
|
68
|
+
signal.append(value)
|
|
58
69
|
```
|
|
70
|
+
|
|
59
71
|
For more information and generator validation, see [lbfbm_generator.ipynb](/research/lbfbm_generator.ipynb).
|
|
60
72
|
|
|
73
|
+
It is also possible to use the method of generating increments with a given H using `KasdinGenerator`.
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from StatTools.generators.kasdin_generator import KasdinGenerator
|
|
77
|
+
h = 0.8 # choose Hurst parameter
|
|
78
|
+
target_len = 4000 # number of generation iterations
|
|
79
|
+
|
|
80
|
+
generator = KasdinGenerator(h, length=target_len)
|
|
81
|
+
|
|
82
|
+
# the first option
|
|
83
|
+
signal = generator.get_full_sequence()
|
|
84
|
+
|
|
85
|
+
# the second option
|
|
86
|
+
signal_list = []
|
|
87
|
+
for sample in generator:
|
|
88
|
+
signal_list.append(sample)
|
|
89
|
+
```
|
|
90
|
+
For more information see Kasdin, N. J. (1995). Discrete simulation of colored noise and stochastic processes and 1/f/sup /spl alpha// power law noise generation. doi:10.1109/5.381848.
|
|
91
|
+
|
|
92
|
+
### Fluctuational Analysis
|
|
93
|
+
|
|
94
|
+
1. Example of Detrended Fluctuational Analysis (DFA)
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from StatTools.generators.base_filter import Filter
|
|
98
|
+
from StatTools.analysis.dfa import DFA
|
|
99
|
+
|
|
100
|
+
h = 0.7 # choose Hurst parameter
|
|
101
|
+
length = 6000 # vector's length
|
|
102
|
+
target_std = 1.0
|
|
103
|
+
target_mean = 0.0
|
|
104
|
+
|
|
105
|
+
generator = Filter(h, length, set_mean=target_mean, set_std=target_std)
|
|
106
|
+
trajectory = generator.generate(n_vectors=1)
|
|
107
|
+
|
|
108
|
+
actual_mean = np.mean(trajectory)
|
|
109
|
+
actual_std = np.std(trajectory, ddof=1)
|
|
110
|
+
actual_h = DFA(trajectory).find_h()
|
|
111
|
+
print(actual_h) # Should print a value close to 0.7
|
|
112
|
+
```
|
|
113
|
+
|
|
61
114
|
## Contributors
|
|
62
115
|
|
|
63
116
|
* [Alexandr Kuzmenko](https://github.com/alexandr-1k)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# StatTools
|
|
2
|
+
|
|
3
|
+
This library allows to create and process long-term dependent datasets.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
You can install FluctuationAnalysisTools from [PyPI](https://pypi.org/project/FluctuationAnalysisTools/).
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install FluctuationAnalysisTools
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Or you can clone the repository and build it using the command
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install .
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Basis usage
|
|
25
|
+
|
|
26
|
+
1. To create a simple dataset with given Hurst parameter:
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from StatTools.filters import FilteredArray
|
|
30
|
+
|
|
31
|
+
h = 0.8 # choose Hurst parameter
|
|
32
|
+
total_vectors = 1000 # total number of vectors in output
|
|
33
|
+
vectors_length = 1440 # each vector's length
|
|
34
|
+
t = 8 # threads in use during computation
|
|
35
|
+
|
|
36
|
+
correlated_vectors = Filter(h, vectors_length).generate(n_vectors=total_vectors,
|
|
37
|
+
threads=t, progress_bar=True)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Generators
|
|
41
|
+
|
|
42
|
+
1. Example of sequence generation based on the Hurst exponent.
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from StatTools.generators.hurst_generator import LBFBmGenerator
|
|
46
|
+
h = 0.8 # choose Hurst parameter
|
|
47
|
+
filter_len = 40 # length of the optimized filter
|
|
48
|
+
base = 1.2 # the basis for the filter optimization algorithm
|
|
49
|
+
target_len = 4000 # number of generation iterations
|
|
50
|
+
|
|
51
|
+
generator = LBFBmGenerator(h, filter_len, base)
|
|
52
|
+
signal = []
|
|
53
|
+
for value in islice(generator, target_len):
|
|
54
|
+
signal.append(value)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For more information and generator validation, see [lbfbm_generator.ipynb](/research/lbfbm_generator.ipynb).
|
|
58
|
+
|
|
59
|
+
It is also possible to use the method of generating increments with a given H using `KasdinGenerator`.
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from StatTools.generators.kasdin_generator import KasdinGenerator
|
|
63
|
+
h = 0.8 # choose Hurst parameter
|
|
64
|
+
target_len = 4000 # number of generation iterations
|
|
65
|
+
|
|
66
|
+
generator = KasdinGenerator(h, length=target_len)
|
|
67
|
+
|
|
68
|
+
# the first option
|
|
69
|
+
signal = generator.get_full_sequence()
|
|
70
|
+
|
|
71
|
+
# the second option
|
|
72
|
+
signal_list = []
|
|
73
|
+
for sample in generator:
|
|
74
|
+
signal_list.append(sample)
|
|
75
|
+
```
|
|
76
|
+
For more information see Kasdin, N. J. (1995). Discrete simulation of colored noise and stochastic processes and 1/f/sup /spl alpha// power law noise generation. doi:10.1109/5.381848.
|
|
77
|
+
|
|
78
|
+
### Fluctuational Analysis
|
|
79
|
+
|
|
80
|
+
1. Example of Detrended Fluctuational Analysis (DFA)
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from StatTools.generators.base_filter import Filter
|
|
84
|
+
from StatTools.analysis.dfa import DFA
|
|
85
|
+
|
|
86
|
+
h = 0.7 # choose Hurst parameter
|
|
87
|
+
length = 6000 # vector's length
|
|
88
|
+
target_std = 1.0
|
|
89
|
+
target_mean = 0.0
|
|
90
|
+
|
|
91
|
+
generator = Filter(h, length, set_mean=target_mean, set_std=target_std)
|
|
92
|
+
trajectory = generator.generate(n_vectors=1)
|
|
93
|
+
|
|
94
|
+
actual_mean = np.mean(trajectory)
|
|
95
|
+
actual_std = np.std(trajectory, ddof=1)
|
|
96
|
+
actual_h = DFA(trajectory).find_h()
|
|
97
|
+
print(actual_h) # Should print a value close to 0.7
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Contributors
|
|
101
|
+
|
|
102
|
+
* [Alexandr Kuzmenko](https://github.com/alexandr-1k)
|
|
103
|
+
* [Aleksandr Sinitca](https://github.com/Sinitca-Aleksandr)
|
|
104
|
+
* [Asya Lyanova](https://github.com/pipipyau)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .dfa import dfa
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import itertools
|
|
2
|
+
from multiprocessing import Pool
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import pandas as pd
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def __dfa_polyfit_core(windowed: pd.Series, order: int) -> float:
|
|
9
|
+
# Drop windows that contains less than needed for approximation
|
|
10
|
+
# TODO: probably better to drop windows that contains less than some amount of non perfectly fitted points?
|
|
11
|
+
if len(windowed.index) < order + 1:
|
|
12
|
+
return []
|
|
13
|
+
times = windowed.index.map(lambda x: x.value).to_numpy()
|
|
14
|
+
z = np.polyfit(times, windowed.to_numpy(), order)
|
|
15
|
+
current_trend = np.polyval(z, times)
|
|
16
|
+
detrended_window = windowed - current_trend
|
|
17
|
+
return list(detrended_window.values)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def __dfa_scale_core(
|
|
21
|
+
dataset: pd.Series,
|
|
22
|
+
scale: pd.Timedelta,
|
|
23
|
+
step: pd.Timedelta,
|
|
24
|
+
order: int,
|
|
25
|
+
num_process=None,
|
|
26
|
+
) -> float:
|
|
27
|
+
residuals = []
|
|
28
|
+
start_time = dataset.index[0]
|
|
29
|
+
start_times = []
|
|
30
|
+
|
|
31
|
+
if step is None:
|
|
32
|
+
start_times = list(dataset[: dataset.index[-1] - scale].index)
|
|
33
|
+
else:
|
|
34
|
+
while start_time < dataset.index[-1] - scale:
|
|
35
|
+
start_time += step
|
|
36
|
+
start_times.append(start_time)
|
|
37
|
+
|
|
38
|
+
if len(start_times) == 0:
|
|
39
|
+
print(f"No valid windows with scale {scale} found.")
|
|
40
|
+
return np.nan
|
|
41
|
+
|
|
42
|
+
if num_process is None:
|
|
43
|
+
for start_time in start_times:
|
|
44
|
+
residuals.extend(
|
|
45
|
+
__dfa_polyfit_core(dataset[start_time : start_time + scale], order)
|
|
46
|
+
)
|
|
47
|
+
else:
|
|
48
|
+
assert num_process > 0, "Invalid value for 'process'"
|
|
49
|
+
num_process = min(num_process, len(start_times))
|
|
50
|
+
with Pool(num_process) as p:
|
|
51
|
+
residuals = list(
|
|
52
|
+
itertools.chain(
|
|
53
|
+
*list(
|
|
54
|
+
p.starmap(
|
|
55
|
+
__dfa_polyfit_core,
|
|
56
|
+
[
|
|
57
|
+
(dataset[start_time : start_time + scale].copy(), order)
|
|
58
|
+
for start_time in start_times
|
|
59
|
+
],
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
residuals = np.array(residuals)
|
|
65
|
+
F_2 = np.mean(residuals**2)
|
|
66
|
+
return F_2
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def dfa(
|
|
70
|
+
data: pd.Series,
|
|
71
|
+
scales: list[pd.Timedelta],
|
|
72
|
+
step: float = None,
|
|
73
|
+
order: int = 2,
|
|
74
|
+
num_process=None,
|
|
75
|
+
) -> pd.Series:
|
|
76
|
+
"""Calculate the Detrended Fluctuation Analysis (DFA)
|
|
77
|
+
for a given nonequidistant dataset.
|
|
78
|
+
|
|
79
|
+
The timeseries for the analysis should coutains a measurement of the value, but not increments, as usualy
|
|
80
|
+
used for fluctuation analysis.
|
|
81
|
+
|
|
82
|
+
WARNING: Current implementation can be unstable for h<1,
|
|
83
|
+
if the data contains a lot of gaps in the data (~25% of the equivalent equidistant data).
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
data (pd.Series): The input data to analyze.
|
|
87
|
+
The index of the Series must be timeseries.
|
|
88
|
+
scales (list[pd.Timedelta]): A list of scales to use for the DFA analysis.
|
|
89
|
+
Each scale should be a timedelta object representing the time interval.
|
|
90
|
+
step (int): The step size to use for the DFA analysis.
|
|
91
|
+
This is used to determine the number of windows to use for each scale.
|
|
92
|
+
order (int, optional): The polynomial order used for detrending. Defaults to 2.
|
|
93
|
+
num_process (int): The number of processes to use for parallel computation. Defaults to None.
|
|
94
|
+
If None, the computation will be done sequentially.
|
|
95
|
+
Returns:
|
|
96
|
+
pd.Series: A series containing the DFA values, i.e., the squared Fluctuation Function.
|
|
97
|
+
"""
|
|
98
|
+
# Ensure the index is a valid timeseries
|
|
99
|
+
if not isinstance(data.index, pd.DatetimeIndex):
|
|
100
|
+
raise ValueError("The index of the Series must be a valid timeseries")
|
|
101
|
+
|
|
102
|
+
FF_2 = []
|
|
103
|
+
|
|
104
|
+
for scale in scales:
|
|
105
|
+
if step is not None:
|
|
106
|
+
step_scale = step * scale
|
|
107
|
+
else:
|
|
108
|
+
step_scale = None
|
|
109
|
+
FF_2.append(__dfa_scale_core(data, scale, step_scale, order, num_process))
|
|
110
|
+
|
|
111
|
+
return pd.Series(FF_2, index=scales)
|