fastccm 0.2.3a1__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.
- fastccm-0.2.3a1/LICENSE +21 -0
- fastccm-0.2.3a1/MANIFEST.in +3 -0
- fastccm-0.2.3a1/PKG-INFO +184 -0
- fastccm-0.2.3a1/README.md +144 -0
- fastccm-0.2.3a1/pyproject.toml +31 -0
- fastccm-0.2.3a1/setup.cfg +4 -0
- fastccm-0.2.3a1/src/FastCCM.egg-info/PKG-INFO +184 -0
- fastccm-0.2.3a1/src/FastCCM.egg-info/SOURCES.txt +23 -0
- fastccm-0.2.3a1/src/FastCCM.egg-info/dependency_links.txt +1 -0
- fastccm-0.2.3a1/src/FastCCM.egg-info/requires.txt +5 -0
- fastccm-0.2.3a1/src/FastCCM.egg-info/top_level.txt +1 -0
- fastccm-0.2.3a1/src/fastccm/__init__.py +30 -0
- fastccm-0.2.3a1/src/fastccm/_version.py +1 -0
- fastccm-0.2.3a1/src/fastccm/ccm.py +826 -0
- fastccm-0.2.3a1/src/fastccm/ccm_utils.py +607 -0
- fastccm-0.2.3a1/src/fastccm/data/__init__.py +11 -0
- fastccm-0.2.3a1/src/fastccm/data/data_loader.py +61 -0
- fastccm-0.2.3a1/src/fastccm/utils/__init__.py +19 -0
- fastccm-0.2.3a1/src/fastccm/utils/metrics.py +122 -0
- fastccm-0.2.3a1/src/fastccm/utils/utils.py +291 -0
fastccm-0.2.3a1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Iaroslav Korobov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
fastccm-0.2.3a1/PKG-INFO
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastccm
|
|
3
|
+
Version: 0.2.3a1
|
|
4
|
+
Summary: A package for optimized Convergent Cross Mapping using PyTorch.
|
|
5
|
+
Author: Iaroslav Korobov
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Iaroslav Korobov
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/z7743/FastCCM
|
|
29
|
+
Project-URL: Issues, https://github.com/z7743/FastCCM/issues
|
|
30
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
31
|
+
Requires-Python: >=3.9
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
License-File: LICENSE
|
|
34
|
+
Requires-Dist: numpy>=1.23
|
|
35
|
+
Requires-Dist: scipy>=1.10
|
|
36
|
+
Requires-Dist: scikit-learn>=1.3
|
|
37
|
+
Requires-Dist: matplotlib>=3.5
|
|
38
|
+
Requires-Dist: pandas>=1.5
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
# FastCCM
|
|
42
|
+
PyTorch-based implementation of Convergent Cross Mapping (CCM) optimized for calculating pairwise CCM matrices.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
**Requirements**: Python ≥ 3.9, pip.
|
|
47
|
+
|
|
48
|
+
**CPU-only:**
|
|
49
|
+
```bash
|
|
50
|
+
pip install --upgrade pip
|
|
51
|
+
pip install torch==2.3.1 --index-url https://download.pytorch.org/whl/cpu
|
|
52
|
+
pip install "fastccm @ git+https://github.com/z7743/FastCCM.git@v0.2.2"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**CUDA:**
|
|
56
|
+
```bash
|
|
57
|
+
pip install --upgrade pip
|
|
58
|
+
pip install torch==2.3.1 --index-url https://download.pytorch.org/whl/cu121
|
|
59
|
+
pip install "fastccm @ git+https://github.com/z7743/FastCCM.git@v0.2.2"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**macOS (CPU/MPS):**
|
|
63
|
+
```bash
|
|
64
|
+
pip install --upgrade pip
|
|
65
|
+
pip install torch==2.3.1
|
|
66
|
+
pip install "fastccm @ git+https://github.com/z7743/FastCCM.git@v0.2.2"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Quick start
|
|
70
|
+
|
|
71
|
+
This example demonstrates how to use the FastCCM package for performing Convergent Cross Mapping (CCM).
|
|
72
|
+
|
|
73
|
+
1. Import Required Libraries
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from fastccm import PairwiseCCM, utils
|
|
77
|
+
from fastccm.data import get_truncated_rossler_lorenz_rand
|
|
78
|
+
import numpy as np
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
2. Initialize the CCM Object
|
|
82
|
+
|
|
83
|
+
Specify the device to use (e.g., "cpu" or "cuda"):
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
ccm = PairwiseCCM(device="cpu")
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
3. Generate Data
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
# Generate a joint Rossler-Lorenz data
|
|
93
|
+
X = get_truncated_rossler_lorenz_rand(400, 20000, alpha=6, C=2, seed=0)
|
|
94
|
+
|
|
95
|
+
Rossler_emb = utils.embed(X[:, 0], E = 7, tau = 4) # see find_optimal_embedding_params
|
|
96
|
+
Lorenz_emb = utils.embed(X[:, 3], E = 8, tau = 9)
|
|
97
|
+
|
|
98
|
+
print(f"Rossler embedding shape: {Rossler_emb.shape}")
|
|
99
|
+
print(f"Lorenz embedding shape: {Lorenz_emb.shape}")
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+

|
|
103
|
+
|
|
104
|
+
### Calculate cross-mapping prediction
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
# Rossler cross-mapping Lorenz
|
|
108
|
+
result_rossler_xmap_lorenz = ccm.score_matrix(
|
|
109
|
+
X_emb=Rossler_emb,
|
|
110
|
+
Y_emb=Lorenz_emb,
|
|
111
|
+
library_size=None, # use maximum points
|
|
112
|
+
sample_size=300, # use 300 random points to estimate the score
|
|
113
|
+
exclusion_window=50,
|
|
114
|
+
tp=0,
|
|
115
|
+
method="simplex",
|
|
116
|
+
seed=0
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
# Lorenz cross-mapping Rossler
|
|
120
|
+
result_lorenz_xmap_rossler = ccm.score_matrix(
|
|
121
|
+
X_emb=Lorenz_emb,
|
|
122
|
+
Y_emb=Rossler_emb,
|
|
123
|
+
library_size=None,
|
|
124
|
+
sample_size=300,
|
|
125
|
+
exclusion_window=50,
|
|
126
|
+
tp=0,
|
|
127
|
+
method="simplex",
|
|
128
|
+
seed=0
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
print(f"Rossler xmap Lorenz. Shape: {result_rossler_xmap_lorenz.shape}, score: {result_rossler_xmap_lorenz[-1,0,0]:.3f}")
|
|
132
|
+
print(f"Lorenz xmap Rossler. Shape: {result_lorenz_xmap_rossler.shape}, score: {result_lorenz_xmap_rossler[-1,0,0]:.3f}")
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Test convergence
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from fastccm import ccm_utils
|
|
140
|
+
|
|
141
|
+
conv_test_res = ccm_utils.Functions("cpu").convergence_test(
|
|
142
|
+
X_emb=Rossler_emb,
|
|
143
|
+
Y_emb=Lorenz_emb,
|
|
144
|
+
library_sizes=[160, 320, 640, 1250, 2500, 5000, 10000, 20000],
|
|
145
|
+
sample_size=1000,
|
|
146
|
+
exclusion_window=50,
|
|
147
|
+
tp=0,
|
|
148
|
+
method="simplex",
|
|
149
|
+
trials=20,
|
|
150
|
+
seed=0
|
|
151
|
+
)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Plot the convergence test results:
|
|
155
|
+
```python
|
|
156
|
+
ccm_utils.Visualizer().plot_convergence_test(conv_test_res)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+

|
|
160
|
+
|
|
161
|
+
### Find optimal time-delay embedding parameters
|
|
162
|
+
```python
|
|
163
|
+
|
|
164
|
+
optimal_E_tau_res = ccm_utils.Functions("cpu").find_optimal_embedding_params(
|
|
165
|
+
X[:,3],
|
|
166
|
+
library_size=4000,
|
|
167
|
+
sample_size=300,
|
|
168
|
+
exclusion_window=50,
|
|
169
|
+
E_range=np.arange(2,30),
|
|
170
|
+
tau_range=np.arange(1,30),
|
|
171
|
+
tp_max=50,
|
|
172
|
+
method="simplex",
|
|
173
|
+
seed=0
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
print(f"Optimal E: {optimal_E_tau_res['optimal_E']}, optimal_tau: {optimal_E_tau_res['optimal_tau']}")
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Plot the results
|
|
180
|
+
```python
|
|
181
|
+
ccm_utils.Visualizer().visualize_optimal_e_tau(optimal_E_tau_res)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+

|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# FastCCM
|
|
2
|
+
PyTorch-based implementation of Convergent Cross Mapping (CCM) optimized for calculating pairwise CCM matrices.
|
|
3
|
+
|
|
4
|
+
## Installation
|
|
5
|
+
|
|
6
|
+
**Requirements**: Python ≥ 3.9, pip.
|
|
7
|
+
|
|
8
|
+
**CPU-only:**
|
|
9
|
+
```bash
|
|
10
|
+
pip install --upgrade pip
|
|
11
|
+
pip install torch==2.3.1 --index-url https://download.pytorch.org/whl/cpu
|
|
12
|
+
pip install "fastccm @ git+https://github.com/z7743/FastCCM.git@v0.2.2"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**CUDA:**
|
|
16
|
+
```bash
|
|
17
|
+
pip install --upgrade pip
|
|
18
|
+
pip install torch==2.3.1 --index-url https://download.pytorch.org/whl/cu121
|
|
19
|
+
pip install "fastccm @ git+https://github.com/z7743/FastCCM.git@v0.2.2"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**macOS (CPU/MPS):**
|
|
23
|
+
```bash
|
|
24
|
+
pip install --upgrade pip
|
|
25
|
+
pip install torch==2.3.1
|
|
26
|
+
pip install "fastccm @ git+https://github.com/z7743/FastCCM.git@v0.2.2"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick start
|
|
30
|
+
|
|
31
|
+
This example demonstrates how to use the FastCCM package for performing Convergent Cross Mapping (CCM).
|
|
32
|
+
|
|
33
|
+
1. Import Required Libraries
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from fastccm import PairwiseCCM, utils
|
|
37
|
+
from fastccm.data import get_truncated_rossler_lorenz_rand
|
|
38
|
+
import numpy as np
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
2. Initialize the CCM Object
|
|
42
|
+
|
|
43
|
+
Specify the device to use (e.g., "cpu" or "cuda"):
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
ccm = PairwiseCCM(device="cpu")
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
3. Generate Data
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
# Generate a joint Rossler-Lorenz data
|
|
53
|
+
X = get_truncated_rossler_lorenz_rand(400, 20000, alpha=6, C=2, seed=0)
|
|
54
|
+
|
|
55
|
+
Rossler_emb = utils.embed(X[:, 0], E = 7, tau = 4) # see find_optimal_embedding_params
|
|
56
|
+
Lorenz_emb = utils.embed(X[:, 3], E = 8, tau = 9)
|
|
57
|
+
|
|
58
|
+
print(f"Rossler embedding shape: {Rossler_emb.shape}")
|
|
59
|
+
print(f"Lorenz embedding shape: {Lorenz_emb.shape}")
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+

|
|
63
|
+
|
|
64
|
+
### Calculate cross-mapping prediction
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
# Rossler cross-mapping Lorenz
|
|
68
|
+
result_rossler_xmap_lorenz = ccm.score_matrix(
|
|
69
|
+
X_emb=Rossler_emb,
|
|
70
|
+
Y_emb=Lorenz_emb,
|
|
71
|
+
library_size=None, # use maximum points
|
|
72
|
+
sample_size=300, # use 300 random points to estimate the score
|
|
73
|
+
exclusion_window=50,
|
|
74
|
+
tp=0,
|
|
75
|
+
method="simplex",
|
|
76
|
+
seed=0
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
# Lorenz cross-mapping Rossler
|
|
80
|
+
result_lorenz_xmap_rossler = ccm.score_matrix(
|
|
81
|
+
X_emb=Lorenz_emb,
|
|
82
|
+
Y_emb=Rossler_emb,
|
|
83
|
+
library_size=None,
|
|
84
|
+
sample_size=300,
|
|
85
|
+
exclusion_window=50,
|
|
86
|
+
tp=0,
|
|
87
|
+
method="simplex",
|
|
88
|
+
seed=0
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
print(f"Rossler xmap Lorenz. Shape: {result_rossler_xmap_lorenz.shape}, score: {result_rossler_xmap_lorenz[-1,0,0]:.3f}")
|
|
92
|
+
print(f"Lorenz xmap Rossler. Shape: {result_lorenz_xmap_rossler.shape}, score: {result_lorenz_xmap_rossler[-1,0,0]:.3f}")
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Test convergence
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from fastccm import ccm_utils
|
|
100
|
+
|
|
101
|
+
conv_test_res = ccm_utils.Functions("cpu").convergence_test(
|
|
102
|
+
X_emb=Rossler_emb,
|
|
103
|
+
Y_emb=Lorenz_emb,
|
|
104
|
+
library_sizes=[160, 320, 640, 1250, 2500, 5000, 10000, 20000],
|
|
105
|
+
sample_size=1000,
|
|
106
|
+
exclusion_window=50,
|
|
107
|
+
tp=0,
|
|
108
|
+
method="simplex",
|
|
109
|
+
trials=20,
|
|
110
|
+
seed=0
|
|
111
|
+
)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Plot the convergence test results:
|
|
115
|
+
```python
|
|
116
|
+
ccm_utils.Visualizer().plot_convergence_test(conv_test_res)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+

|
|
120
|
+
|
|
121
|
+
### Find optimal time-delay embedding parameters
|
|
122
|
+
```python
|
|
123
|
+
|
|
124
|
+
optimal_E_tau_res = ccm_utils.Functions("cpu").find_optimal_embedding_params(
|
|
125
|
+
X[:,3],
|
|
126
|
+
library_size=4000,
|
|
127
|
+
sample_size=300,
|
|
128
|
+
exclusion_window=50,
|
|
129
|
+
E_range=np.arange(2,30),
|
|
130
|
+
tau_range=np.arange(1,30),
|
|
131
|
+
tp_max=50,
|
|
132
|
+
method="simplex",
|
|
133
|
+
seed=0
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
print(f"Optimal E: {optimal_E_tau_res['optimal_E']}, optimal_tau: {optimal_E_tau_res['optimal_tau']}")
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Plot the results
|
|
140
|
+
```python
|
|
141
|
+
ccm_utils.Visualizer().visualize_optimal_e_tau(optimal_E_tau_res)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+

|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=69", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "fastccm"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "A package for optimized Convergent Cross Mapping using PyTorch."
|
|
9
|
+
readme = { file = "README.md", content-type = "text/markdown" }
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
classifiers = ["License :: OSI Approved :: MIT License"]
|
|
13
|
+
authors = [{ name = "Iaroslav Korobov" }]
|
|
14
|
+
|
|
15
|
+
dependencies = [
|
|
16
|
+
"numpy>=1.23",
|
|
17
|
+
"scipy>=1.10",
|
|
18
|
+
"scikit-learn>=1.3",
|
|
19
|
+
"matplotlib>=3.5",
|
|
20
|
+
"pandas>=1.5",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
Homepage = "https://github.com/z7743/FastCCM"
|
|
25
|
+
Issues = "https://github.com/z7743/FastCCM/issues"
|
|
26
|
+
|
|
27
|
+
[tool.setuptools.dynamic]
|
|
28
|
+
version = { attr = "fastccm._version.__version__" }
|
|
29
|
+
|
|
30
|
+
[tool.setuptools.packages.find]
|
|
31
|
+
where = ["src"]
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastccm
|
|
3
|
+
Version: 0.2.3a1
|
|
4
|
+
Summary: A package for optimized Convergent Cross Mapping using PyTorch.
|
|
5
|
+
Author: Iaroslav Korobov
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Iaroslav Korobov
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/z7743/FastCCM
|
|
29
|
+
Project-URL: Issues, https://github.com/z7743/FastCCM/issues
|
|
30
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
31
|
+
Requires-Python: >=3.9
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
License-File: LICENSE
|
|
34
|
+
Requires-Dist: numpy>=1.23
|
|
35
|
+
Requires-Dist: scipy>=1.10
|
|
36
|
+
Requires-Dist: scikit-learn>=1.3
|
|
37
|
+
Requires-Dist: matplotlib>=3.5
|
|
38
|
+
Requires-Dist: pandas>=1.5
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
# FastCCM
|
|
42
|
+
PyTorch-based implementation of Convergent Cross Mapping (CCM) optimized for calculating pairwise CCM matrices.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
**Requirements**: Python ≥ 3.9, pip.
|
|
47
|
+
|
|
48
|
+
**CPU-only:**
|
|
49
|
+
```bash
|
|
50
|
+
pip install --upgrade pip
|
|
51
|
+
pip install torch==2.3.1 --index-url https://download.pytorch.org/whl/cpu
|
|
52
|
+
pip install "fastccm @ git+https://github.com/z7743/FastCCM.git@v0.2.2"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**CUDA:**
|
|
56
|
+
```bash
|
|
57
|
+
pip install --upgrade pip
|
|
58
|
+
pip install torch==2.3.1 --index-url https://download.pytorch.org/whl/cu121
|
|
59
|
+
pip install "fastccm @ git+https://github.com/z7743/FastCCM.git@v0.2.2"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**macOS (CPU/MPS):**
|
|
63
|
+
```bash
|
|
64
|
+
pip install --upgrade pip
|
|
65
|
+
pip install torch==2.3.1
|
|
66
|
+
pip install "fastccm @ git+https://github.com/z7743/FastCCM.git@v0.2.2"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Quick start
|
|
70
|
+
|
|
71
|
+
This example demonstrates how to use the FastCCM package for performing Convergent Cross Mapping (CCM).
|
|
72
|
+
|
|
73
|
+
1. Import Required Libraries
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from fastccm import PairwiseCCM, utils
|
|
77
|
+
from fastccm.data import get_truncated_rossler_lorenz_rand
|
|
78
|
+
import numpy as np
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
2. Initialize the CCM Object
|
|
82
|
+
|
|
83
|
+
Specify the device to use (e.g., "cpu" or "cuda"):
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
ccm = PairwiseCCM(device="cpu")
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
3. Generate Data
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
# Generate a joint Rossler-Lorenz data
|
|
93
|
+
X = get_truncated_rossler_lorenz_rand(400, 20000, alpha=6, C=2, seed=0)
|
|
94
|
+
|
|
95
|
+
Rossler_emb = utils.embed(X[:, 0], E = 7, tau = 4) # see find_optimal_embedding_params
|
|
96
|
+
Lorenz_emb = utils.embed(X[:, 3], E = 8, tau = 9)
|
|
97
|
+
|
|
98
|
+
print(f"Rossler embedding shape: {Rossler_emb.shape}")
|
|
99
|
+
print(f"Lorenz embedding shape: {Lorenz_emb.shape}")
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+

|
|
103
|
+
|
|
104
|
+
### Calculate cross-mapping prediction
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
# Rossler cross-mapping Lorenz
|
|
108
|
+
result_rossler_xmap_lorenz = ccm.score_matrix(
|
|
109
|
+
X_emb=Rossler_emb,
|
|
110
|
+
Y_emb=Lorenz_emb,
|
|
111
|
+
library_size=None, # use maximum points
|
|
112
|
+
sample_size=300, # use 300 random points to estimate the score
|
|
113
|
+
exclusion_window=50,
|
|
114
|
+
tp=0,
|
|
115
|
+
method="simplex",
|
|
116
|
+
seed=0
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
# Lorenz cross-mapping Rossler
|
|
120
|
+
result_lorenz_xmap_rossler = ccm.score_matrix(
|
|
121
|
+
X_emb=Lorenz_emb,
|
|
122
|
+
Y_emb=Rossler_emb,
|
|
123
|
+
library_size=None,
|
|
124
|
+
sample_size=300,
|
|
125
|
+
exclusion_window=50,
|
|
126
|
+
tp=0,
|
|
127
|
+
method="simplex",
|
|
128
|
+
seed=0
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
print(f"Rossler xmap Lorenz. Shape: {result_rossler_xmap_lorenz.shape}, score: {result_rossler_xmap_lorenz[-1,0,0]:.3f}")
|
|
132
|
+
print(f"Lorenz xmap Rossler. Shape: {result_lorenz_xmap_rossler.shape}, score: {result_lorenz_xmap_rossler[-1,0,0]:.3f}")
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Test convergence
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from fastccm import ccm_utils
|
|
140
|
+
|
|
141
|
+
conv_test_res = ccm_utils.Functions("cpu").convergence_test(
|
|
142
|
+
X_emb=Rossler_emb,
|
|
143
|
+
Y_emb=Lorenz_emb,
|
|
144
|
+
library_sizes=[160, 320, 640, 1250, 2500, 5000, 10000, 20000],
|
|
145
|
+
sample_size=1000,
|
|
146
|
+
exclusion_window=50,
|
|
147
|
+
tp=0,
|
|
148
|
+
method="simplex",
|
|
149
|
+
trials=20,
|
|
150
|
+
seed=0
|
|
151
|
+
)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Plot the convergence test results:
|
|
155
|
+
```python
|
|
156
|
+
ccm_utils.Visualizer().plot_convergence_test(conv_test_res)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+

|
|
160
|
+
|
|
161
|
+
### Find optimal time-delay embedding parameters
|
|
162
|
+
```python
|
|
163
|
+
|
|
164
|
+
optimal_E_tau_res = ccm_utils.Functions("cpu").find_optimal_embedding_params(
|
|
165
|
+
X[:,3],
|
|
166
|
+
library_size=4000,
|
|
167
|
+
sample_size=300,
|
|
168
|
+
exclusion_window=50,
|
|
169
|
+
E_range=np.arange(2,30),
|
|
170
|
+
tau_range=np.arange(1,30),
|
|
171
|
+
tp_max=50,
|
|
172
|
+
method="simplex",
|
|
173
|
+
seed=0
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
print(f"Optimal E: {optimal_E_tau_res['optimal_E']}, optimal_tau: {optimal_E_tau_res['optimal_tau']}")
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Plot the results
|
|
180
|
+
```python
|
|
181
|
+
ccm_utils.Visualizer().visualize_optimal_e_tau(optimal_E_tau_res)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+

|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
src/FastCCM.egg-info/PKG-INFO
|
|
6
|
+
src/FastCCM.egg-info/SOURCES.txt
|
|
7
|
+
src/FastCCM.egg-info/dependency_links.txt
|
|
8
|
+
src/FastCCM.egg-info/requires.txt
|
|
9
|
+
src/FastCCM.egg-info/top_level.txt
|
|
10
|
+
src/fastccm/__init__.py
|
|
11
|
+
src/fastccm/_version.py
|
|
12
|
+
src/fastccm/ccm.py
|
|
13
|
+
src/fastccm/ccm_utils.py
|
|
14
|
+
src/fastccm.egg-info/PKG-INFO
|
|
15
|
+
src/fastccm.egg-info/SOURCES.txt
|
|
16
|
+
src/fastccm.egg-info/dependency_links.txt
|
|
17
|
+
src/fastccm.egg-info/requires.txt
|
|
18
|
+
src/fastccm.egg-info/top_level.txt
|
|
19
|
+
src/fastccm/data/__init__.py
|
|
20
|
+
src/fastccm/data/data_loader.py
|
|
21
|
+
src/fastccm/utils/__init__.py
|
|
22
|
+
src/fastccm/utils/metrics.py
|
|
23
|
+
src/fastccm/utils/utils.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fastccm
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# src/fastccm/__init__.py
|
|
2
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
from ._version import __version__
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
__version__ = version("FastCCM")
|
|
8
|
+
except PackageNotFoundError:
|
|
9
|
+
__version__ = "0.0.0"
|
|
10
|
+
|
|
11
|
+
from . import data as data
|
|
12
|
+
from . import utils as utils
|
|
13
|
+
|
|
14
|
+
__all__ = ("__version__", "PairwiseCCM", "Visualizer", "Functions", "data", "utils")
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from .ccm import PairwiseCCM as _PairwiseCCM
|
|
18
|
+
from .ccm_utils import Visualizer as _Visualizer, Functions as _Functions
|
|
19
|
+
|
|
20
|
+
def __getattr__(name: str):
|
|
21
|
+
if name == "PairwiseCCM":
|
|
22
|
+
from .ccm import PairwiseCCM
|
|
23
|
+
return PairwiseCCM
|
|
24
|
+
if name == "Visualizer":
|
|
25
|
+
from .ccm_utils import Visualizer
|
|
26
|
+
return Visualizer
|
|
27
|
+
if name == "Functions":
|
|
28
|
+
from .ccm_utils import Functions
|
|
29
|
+
return Functions
|
|
30
|
+
raise AttributeError(f"module 'fastccm' has no attribute {name!r}")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.3a1"
|