pyCLINE 0.1.9__py3-none-any.whl → 0.1.10__py3-none-any.whl
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.
- pyCLINE/example.py +1 -1
- pyCLINE/recovery_methods/nn_training.py +12 -2
- pycline-0.1.10.dist-info/METADATA +112 -0
- pycline-0.1.10.dist-info/RECORD +12 -0
- {pycline-0.1.9.dist-info → pycline-0.1.10.dist-info}/WHEEL +1 -1
- pycline-0.1.9.dist-info/METADATA +0 -41
- pycline-0.1.9.dist-info/RECORD +0 -12
- {pycline-0.1.9.dist-info → pycline-0.1.10.dist-info}/licenses/LICENSE +0 -0
- {pycline-0.1.9.dist-info → pycline-0.1.10.dist-info}/top_level.txt +0 -0
pyCLINE/example.py
CHANGED
@@ -30,7 +30,7 @@ def example(example_model, plot):
|
|
30
30
|
"""
|
31
31
|
|
32
32
|
#provide name of model to run example
|
33
|
-
if example_model is None:
|
33
|
+
if example_model is None or example_model not in ['FHN', 'Bicubic', 'GeneExpression', 'DelayOscillator']:
|
34
34
|
raise ValueError("Error: example_model is None: please provide a model name (FHN, Bicubic, GeneExpression, DelayOscillator).")
|
35
35
|
|
36
36
|
# check if data already exists
|
@@ -68,7 +68,7 @@ def init_weights(m):
|
|
68
68
|
nn.init.zeros_(m.bias)
|
69
69
|
|
70
70
|
def configure_FFNN_model(Nin, Nout, Nlayers, Nnodes, activation=nn.SiLU, optimizer_name='Adam', lr=1e-4,
|
71
|
-
loss_fn=nn.MSELoss, summary=False):
|
71
|
+
loss_fn=nn.MSELoss, summary=False, load_state_dict=None):
|
72
72
|
"""
|
73
73
|
Configure the Feedforward Neural Network (FFNN) model.
|
74
74
|
|
@@ -82,6 +82,7 @@ def configure_FFNN_model(Nin, Nout, Nlayers, Nnodes, activation=nn.SiLU, optimi
|
|
82
82
|
lr (float, optional): Learning rate for training. Defaults to 1e-4.
|
83
83
|
loss_fn (torch loss function module, optional): Loss function for training. Defaults to nn.MSELoss.
|
84
84
|
summary (bool, optional): If model summary should be generated. Defaults to False.
|
85
|
+
load_state_dict (dict, optional): Load state dict for the model. Defaults to None. Can be string to a torch.state_dict path or a state_dict dictionary.
|
85
86
|
|
86
87
|
Returns:
|
87
88
|
model (torch model): setup FFNN model
|
@@ -118,6 +119,14 @@ def configure_FFNN_model(Nin, Nout, Nlayers, Nnodes, activation=nn.SiLU, optimi
|
|
118
119
|
elif optimizer_name == 'Adadelta':
|
119
120
|
optimizer = optim.Adadelta(model.parameters(), lr=lr)
|
120
121
|
|
122
|
+
if load_state_dict is not None:
|
123
|
+
if load_state_dict is str:
|
124
|
+
model.load_state_dict(torch.load(load_state_dict))
|
125
|
+
elif hasattr(load_state_dict, 'keys') and len(load_state_dict.keys())>0: # torch.nn.module.state_dict() has no dtype
|
126
|
+
model.load_state_dict(load_state_dict)
|
127
|
+
else:
|
128
|
+
raise NeuralNetworkSetupError('load_state_dict', load_state_dict, 'load_state_dict has to be str or dict.')
|
129
|
+
|
121
130
|
loss_fn = loss_fn()
|
122
131
|
|
123
132
|
if summary:
|
@@ -195,6 +204,7 @@ def train_FFNN_model(model, optimizer, loss_fn, input_train, target_train, input
|
|
195
204
|
test_loss (float): testing loss
|
196
205
|
predictions (list): predictions of nullcline structure over all epochs
|
197
206
|
lc_predictions (list): limit cycle predictions over all epochs
|
207
|
+
model (torch model): trained FFNN model
|
198
208
|
"""
|
199
209
|
#Error handling
|
200
210
|
if input_train.shape[0] == 0:
|
@@ -359,7 +369,7 @@ def train_FFNN_model(model, optimizer, loss_fn, input_train, target_train, input
|
|
359
369
|
test_loss /= len(test_loader.dataset)
|
360
370
|
predictions_evolution=np.array(predictions)
|
361
371
|
lc_predictions = np.array(lc_predictions)
|
362
|
-
return train_losses, val_losses, test_loss, predictions_evolution, lc_predictions
|
372
|
+
return train_losses, val_losses, test_loss, predictions_evolution, lc_predictions, model
|
363
373
|
|
364
374
|
def nullcline_prediction(model, Nsteps, device='cpu', method=None,min_val=0.0, max_val=1.0):
|
365
375
|
"""
|
@@ -0,0 +1,112 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: pyCLINE
|
3
|
+
Version: 0.1.10
|
4
|
+
Summary: This package is the Python implementation of the CLINE method
|
5
|
+
Author-email: Bartosz Prokop <bartosz.prokop@kuleuven.be>, Nikita Frolov <nikita.frolov@kuleuven.be>, Lendert Gelens <lendert.gelens@kuleuven.be>
|
6
|
+
Project-URL: Homepage, https://pycline-ec8369.pages.gitlab.kuleuven.be/
|
7
|
+
Project-URL: Issues, https://gitlab.kuleuven.be/gelenslab/publications/pycline/-/issues
|
8
|
+
Keywords: model,model identification,nullcline,data-driven,machine learning,deep learning,torch,dynamics,oscillator,nonlinear dynamics,complex systems
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
11
|
+
Classifier: Operating System :: OS Independent
|
12
|
+
Requires-Python: >=3.10
|
13
|
+
Description-Content-Type: text/markdown
|
14
|
+
License-File: LICENSE
|
15
|
+
Requires-Dist: matplotlib>=3.6.2
|
16
|
+
Requires-Dist: numpy<1.25.0,>=1.24.1
|
17
|
+
Requires-Dist: pandas~=1.5.2
|
18
|
+
Requires-Dist: torch>=2.4.1
|
19
|
+
Requires-Dist: tqdm>=4.66.1
|
20
|
+
Requires-Dist: jitcdde>=1.8.1
|
21
|
+
Requires-Dist: scipy>=1.9.3
|
22
|
+
Dynamic: license-file
|
23
|
+
|
24
|
+
# PyCLINE - python package for CLINE
|
25
|
+
|
26
|
+
The `pyCLINE` package is the python package based on the CLINE (**C**omputational **L**earning and **I**dentification of **N**ullclin**E**s).
|
27
|
+
It can be downloaded from PyPI with pip by using
|
28
|
+
|
29
|
+
pip install pyCLINE
|
30
|
+
|
31
|
+
The package allows to recreate all data, models and results shown in [Prokop, Billen, Frolov and Gelens (2025)](https://arxiv.org/abs/2503.16240), and to apply CLINE to other data sets.
|
32
|
+
In order to generate data used in [Prokop, Billen, Frolov and Gelens (2025)](https://arxiv.org/abs/2503.16240), a set of different models is being provided under `pyCLINE.model`.
|
33
|
+
Data from these models can be generated using `pyCLINE.generate_data()`.
|
34
|
+
For setting up the data prepartion and adjacent training a neural network, the submodule `pyCLINE.recovery_methods` is used.
|
35
|
+
The submodule contains the module for data_preparation `pyCLINE.recovery_methods.data_preparation` and for neural network training `pyCLINE.recovery_methods.nn_training`.
|
36
|
+
|
37
|
+
For a better understanding, `pyCLINE` also contains the module `pyCLINE.example` which provides four examples also found in [Prokop, Billen, Frolov and Gelens (2025)](https://arxiv.org/abs/2503.16240) with step by step instructions on how to setup a CLINE pipeline.
|
38
|
+
|
39
|
+
Documentation of the package can be found hosted on [Gitlab pages](https://pycline-ec8369.pages.gitlab.kuleuven.be).
|
40
|
+
|
41
|
+
The structure of `pyCLINE` is shown here:
|
42
|
+
<!--  -->
|
43
|
+
<div style="text-align: center;">
|
44
|
+
<img src='pycline_structure.png' style="width: 70%;" />
|
45
|
+
</div>
|
46
|
+
|
47
|
+
# Example of use
|
48
|
+
|
49
|
+
As mentioned before, in order to run several examples, the module `example` can be called
|
50
|
+
|
51
|
+
```python
|
52
|
+
import pyCLINE
|
53
|
+
|
54
|
+
pyCLINE.example(*example name*)
|
55
|
+
```
|
56
|
+
|
57
|
+
where example names are `FHN` (FitzHugh-Nagumo model), `Bicubic` (Bicubic model), `GeneExpression` (Gene expression) or `DelayOscillator` (Delay oscillator model) which are introduced in the manuscript.
|
58
|
+
|
59
|
+
Additionally, below you can find the example for the use of the FitzHugh-Nagumo (FHN) model without the use of `pyCLINE.example`.
|
60
|
+
After installing the package, we import `pyCLINE` as well as `torch.nn` to be able to configure the activation function for the neural network training.
|
61
|
+
Additionally, we load `pandas` to be able to load generated test data sets.
|
62
|
+
|
63
|
+
```python
|
64
|
+
import pyCLINE
|
65
|
+
import torch.nn as nn
|
66
|
+
import pandas
|
67
|
+
```
|
68
|
+
|
69
|
+
Firstly, we start by generating the FHN data set, which we then can load as a Pandas Dataframe back into the file from the created data directory:
|
70
|
+
|
71
|
+
```python
|
72
|
+
pyCLINE.generate_data.FHN(dt=0.1, N=1000000, epsilons=[0.3], n_intiaL_conditions=1)
|
73
|
+
df = pd.read_csv('data/synthetic/FHN_eps=0.3_a=0.0)
|
74
|
+
```
|
75
|
+
|
76
|
+
This prepared Dataframe consists of many simulations from randomly selected initial conditions, but we just want to use a single one and reset the index of the dataframe.
|
77
|
+
|
78
|
+
```python
|
79
|
+
df_sim = df[(df['sim']==1)].copy()
|
80
|
+
df_sim.reset_index(drop=True, inplace=True)
|
81
|
+
```
|
82
|
+
|
83
|
+
This step can be skipped when using a single simulation with your data when you only have a single time series.
|
84
|
+
After this we can prepare the data for training, where we declare the column names with a set of parameters used to normalize the data:
|
85
|
+
|
86
|
+
```python
|
87
|
+
df_sim, df_coef = pyCLINE.recovery_methods.data_preparation.prepare_data(df_sim, vars=['u', 'v'], time='time', tmin=10, scheme='derivative', value_min=0.0, value_max=1.0)
|
88
|
+
```
|
89
|
+
|
90
|
+
We then can define the variables that will be used as input and output/target variables of the neural network, and split the datasets into training, test and validation:
|
91
|
+
|
92
|
+
```python
|
93
|
+
input_train, target_train, input_test, target_test, input_val, target_val = pyCLINE.recovery_methods.data_preparation.shuffle_and_split(df_sim, input_vars = input_vars, target_var = target_vars, optimal_thresholding=False)
|
94
|
+
```
|
95
|
+
|
96
|
+
With the prepared data, we can set up the model and train it:
|
97
|
+
|
98
|
+
```python
|
99
|
+
#set up
|
100
|
+
nn_model, optimizer, loss_fn = recovery_methods.nn_training.configure_FFNN_model(Nin=len(input_vars), Nout=len(target_vars),Nlayers=3, Nnodes=64, summary=True, lr=1e-4, activation=nn.SiLU)
|
101
|
+
|
102
|
+
#training
|
103
|
+
training_loss, val_loss, test_loss, predictions_evolution, lc_predictions = recovery_methods.nn_training.train_FFNN_model(model=nn_model, optimizer=optimizer, loss_fn=loss_fn, input_train=input_train,target_train=target_train,input_test=input_test, target_test=target_test, validation_data=(input_val, target_val), epochs=3000, batch_size=64, device='cpu',save_evolution=True,method='derivative', minimal_value=val_min,maximal_value=val_max)
|
104
|
+
```
|
105
|
+
|
106
|
+
The result of the training are the losses and the predictions of the limit cycle (`lc_predictions`) and nullcline predictions (`predictions_evolution`) over the set amount of epochs, which can be used to visualize the outcome of the nullcline predictions.
|
107
|
+
|
108
|
+
# Contributing to pyCLINE
|
109
|
+
|
110
|
+
If you want to contribute to the `pyCLINE` package, you can do it so here on Gitlab by creating a feature either for bug reports or suggestions.
|
111
|
+
|
112
|
+
If you have already written code to fix bugs or add extensions then feel free to creat a pull request, however before putting substantial effort into major code changes please open an issue to discuss it.
|
@@ -0,0 +1,12 @@
|
|
1
|
+
pyCLINE/__init__.py,sha256=Z38oxkRTnb_EiU31_03Ba2bUKs1S2PEajMMGtlUOlf8,726
|
2
|
+
pyCLINE/example.py,sha256=RkQumpOXpkBxn8Zdx1AhQh1GAMWzPzvqc7N2ljPPQC8,8380
|
3
|
+
pyCLINE/generate_data.py,sha256=mQd5e-qyRv3iDecrYrPELOkR_JtMwxBaC_hBzf7Ddho,3642
|
4
|
+
pyCLINE/model.py,sha256=Qq5sQd7bXmI7efoN_IidWjfHAB--ZskEzGDkZYKsE38,35337
|
5
|
+
pyCLINE/recovery_methods/__init__.py,sha256=MQ9ZF_SVZNBJkZ0cyM5zXimiug9yu42lHBCnOMYw080,488
|
6
|
+
pyCLINE/recovery_methods/data_preparation.py,sha256=4XDV-Rc0NpA3f10NlRRhGV7IfhSbZBeepySAMgaxcuo,19690
|
7
|
+
pyCLINE/recovery_methods/nn_training.py,sha256=jRiiG-EBRr_O8bdEpxvQRJ4rVPtbJePWR1260q5ETPI,21049
|
8
|
+
pycline-0.1.10.dist-info/licenses/LICENSE,sha256=6XV86fklwr93DuwtgX05Jg3n25_0c726oBhoSMn1aoc,1245
|
9
|
+
pycline-0.1.10.dist-info/METADATA,sha256=7r-G4JR8NXhKYkKLaWhPyBj8Pynj90bXd3JoWKiEJ_Y,6320
|
10
|
+
pycline-0.1.10.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
11
|
+
pycline-0.1.10.dist-info/top_level.txt,sha256=w0zzQfaPH2RNTWfJ_lsPf-EbkvT6m3quM69exCTMBvU,8
|
12
|
+
pycline-0.1.10.dist-info/RECORD,,
|
pycline-0.1.9.dist-info/METADATA
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: pyCLINE
|
3
|
-
Version: 0.1.9
|
4
|
-
Summary: This package is the Python implementation of the CLINE method
|
5
|
-
Author-email: Bartosz Prokop <bartosz.prokop@kuleuven.be>, Nikita Frolov <nikita.frolov@kuleuven.be>, Lendert Gelens <lendert.gelens@kuleuven.be>
|
6
|
-
Project-URL: Homepage, https://pycline-ec8369.pages.gitlab.kuleuven.be/
|
7
|
-
Project-URL: Issues, https://gitlab.kuleuven.be/gelenslab/publications/pycline/-/issues
|
8
|
-
Keywords: model,model identification,nullcline,data-driven,machine learning,deep learning,torch,dynamics,oscillator,nonlinear dynamics,complex systems
|
9
|
-
Classifier: Development Status :: 3 - Alpha
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
11
|
-
Classifier: Operating System :: OS Independent
|
12
|
-
Requires-Python: >=3.10
|
13
|
-
Description-Content-Type: text/markdown
|
14
|
-
License-File: LICENSE
|
15
|
-
Requires-Dist: matplotlib>=3.6.2
|
16
|
-
Requires-Dist: numpy<1.25.0,>=1.24.1
|
17
|
-
Requires-Dist: pandas~=1.5.2
|
18
|
-
Requires-Dist: torch>=2.4.1
|
19
|
-
Requires-Dist: tqdm>=4.66.1
|
20
|
-
Requires-Dist: jitcdde>=1.8.1
|
21
|
-
Requires-Dist: scipy>=1.9.3
|
22
|
-
Dynamic: license-file
|
23
|
-
|
24
|
-
# PyCLINE - python package for CLINE
|
25
|
-
|
26
|
-
The `pyCLINE` package is the python package based on the CLINE (**C**omputational **L**earning and **I**dentification of **N**ullclin**E**s).
|
27
|
-
It can be downloaded from PyPI with pip by using
|
28
|
-
|
29
|
-
pip install pyCLINE
|
30
|
-
|
31
|
-
The package allows to recreate all data, models and results shown in [Prokop, Billen, Frolov and Gelens (2025)](https://arxiv.org/abs/2503.16240), and to apply CLINE to other data sets.
|
32
|
-
In order to generate data used in [Prokop, Billen, Frolov and Gelens (2025)](https://arxiv.org/abs/2503.16240), a set of different models is being provided under `pyCLINE.model`.
|
33
|
-
Data from these models can be generated using `pyCLINE.generate_data()`.
|
34
|
-
For setting up the data prepartion and adjacent training a neural network, the submodule `pyCLINE.recovery_methods` is used.
|
35
|
-
The submodule contains the module for data_preparation `pyCLINE.recovery_methods.data_preparation` and for neural network training `pyCLINE.recovery_methods.nn_training`.
|
36
|
-
|
37
|
-
For a better understanding, `pyCLINE` also contains the module `pyCLINE.example` which provides four examples also found in XXX with step by step instructions on how to setup a CLINE pipeline.
|
38
|
-
|
39
|
-
The structure of `pyCLINE` is shown here:
|
40
|
-
|
41
|
-

|
pycline-0.1.9.dist-info/RECORD
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
pyCLINE/__init__.py,sha256=Z38oxkRTnb_EiU31_03Ba2bUKs1S2PEajMMGtlUOlf8,726
|
2
|
-
pyCLINE/example.py,sha256=pU-5tT7MA3qlygbsa-_CsjfZRUH5A66mJV7-lDMMP6c,8300
|
3
|
-
pyCLINE/generate_data.py,sha256=mQd5e-qyRv3iDecrYrPELOkR_JtMwxBaC_hBzf7Ddho,3642
|
4
|
-
pyCLINE/model.py,sha256=Qq5sQd7bXmI7efoN_IidWjfHAB--ZskEzGDkZYKsE38,35337
|
5
|
-
pyCLINE/recovery_methods/__init__.py,sha256=MQ9ZF_SVZNBJkZ0cyM5zXimiug9yu42lHBCnOMYw080,488
|
6
|
-
pyCLINE/recovery_methods/data_preparation.py,sha256=4XDV-Rc0NpA3f10NlRRhGV7IfhSbZBeepySAMgaxcuo,19690
|
7
|
-
pyCLINE/recovery_methods/nn_training.py,sha256=i8OeY72UcdGYmI_cloKnK2uqvaxLGUtMqT56-MgFVx8,20357
|
8
|
-
pycline-0.1.9.dist-info/licenses/LICENSE,sha256=6XV86fklwr93DuwtgX05Jg3n25_0c726oBhoSMn1aoc,1245
|
9
|
-
pycline-0.1.9.dist-info/METADATA,sha256=mUvdZBk_aLpbxMPNKHdBzWWnYkN4hEr5zEElQ4OwM1M,2362
|
10
|
-
pycline-0.1.9.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
|
11
|
-
pycline-0.1.9.dist-info/top_level.txt,sha256=w0zzQfaPH2RNTWfJ_lsPf-EbkvT6m3quM69exCTMBvU,8
|
12
|
-
pycline-0.1.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|