nnodely 1.3.0__tar.gz → 1.4.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.
Files changed (85) hide show
  1. {nnodely-1.3.0/nnodely.egg-info → nnodely-1.4.0}/PKG-INFO +36 -22
  2. {nnodely-1.3.0 → nnodely-1.4.0}/README.md +29 -16
  3. nnodely-1.4.0/nnodely/__init__.py +47 -0
  4. nnodely-1.4.0/nnodely/basic/__init__.py +0 -0
  5. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/basic}/loss.py +13 -6
  6. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/basic}/model.py +5 -13
  7. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/basic}/modeldef.py +93 -90
  8. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/basic}/optimizer.py +1 -1
  9. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/basic}/relation.py +23 -20
  10. {nnodely-1.3.0 → nnodely-1.4.0}/nnodely/exporter/__init__.py +1 -1
  11. nnodely-1.3.0/nnodely/exporter/exporter.py → nnodely-1.4.0/nnodely/exporter/emptyexporter.py +1 -1
  12. {nnodely-1.3.0 → nnodely-1.4.0}/nnodely/exporter/export.py +7 -7
  13. {nnodely-1.3.0 → nnodely-1.4.0}/nnodely/exporter/reporter.py +10 -10
  14. {nnodely-1.3.0 → nnodely-1.4.0}/nnodely/exporter/standardexporter.py +8 -6
  15. nnodely-1.4.0/nnodely/layers/__init__.py +0 -0
  16. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/layers}/activation.py +24 -23
  17. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/layers}/arithmetic.py +19 -17
  18. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/layers}/equationlearner.py +12 -9
  19. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/layers}/fir.py +11 -8
  20. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/layers}/fuzzify.py +10 -4
  21. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/layers}/input.py +18 -16
  22. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/layers}/interpolation.py +8 -4
  23. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/layers}/linear.py +9 -6
  24. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/layers}/localmodel.py +6 -3
  25. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/layers}/output.py +2 -2
  26. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/layers}/parameter.py +12 -5
  27. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/layers}/parametricfunction.py +13 -8
  28. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/layers}/part.py +50 -13
  29. nnodely-1.4.0/nnodely/layers/timeoperation.py +75 -0
  30. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/layers}/trigonometric.py +4 -4
  31. nnodely-1.4.0/nnodely/nnodely.py +144 -0
  32. nnodely-1.4.0/nnodely/operators/__init__.py +0 -0
  33. nnodely-1.4.0/nnodely/operators/exporter.py +402 -0
  34. nnodely-1.4.0/nnodely/operators/loader.py +348 -0
  35. nnodely-1.4.0/nnodely/operators/memory.py +47 -0
  36. nnodely-1.4.0/nnodely/operators/network.py +412 -0
  37. nnodely-1.4.0/nnodely/operators/trainer.py +815 -0
  38. nnodely-1.4.0/nnodely/operators/validator.py +218 -0
  39. nnodely-1.4.0/nnodely/support/__init__.py +0 -0
  40. nnodely-1.4.0/nnodely/support/fixstepsolver.py +26 -0
  41. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/support}/initializer.py +22 -22
  42. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/support}/utils.py +74 -5
  43. {nnodely-1.3.0 → nnodely-1.4.0}/nnodely/visualizer/mplnotebookvisualizer.py +14 -12
  44. nnodely-1.4.0/nnodely/visualizer/mplvisualizer.py +215 -0
  45. {nnodely-1.3.0 → nnodely-1.4.0}/nnodely/visualizer/textvisualizer.py +47 -47
  46. {nnodely-1.3.0 → nnodely-1.4.0}/nnodely/visualizer/visualizer.py +3 -3
  47. {nnodely-1.3.0 → nnodely-1.4.0/nnodely.egg-info}/PKG-INFO +36 -22
  48. {nnodely-1.3.0 → nnodely-1.4.0}/nnodely.egg-info/SOURCES.txt +37 -25
  49. {nnodely-1.3.0 → nnodely-1.4.0}/nnodely.egg-info/requires.txt +3 -5
  50. {nnodely-1.3.0 → nnodely-1.4.0}/pyproject.toml +9 -5
  51. {nnodely-1.3.0 → nnodely-1.4.0}/tests/test_dataset.py +268 -171
  52. nnodely-1.4.0/tests/test_documentation.py +25 -0
  53. {nnodely-1.3.0 → nnodely-1.4.0}/tests/test_export.py +9 -10
  54. {nnodely-1.3.0 → nnodely-1.4.0}/tests/test_export_recurrent.py +16 -19
  55. {nnodely-1.3.0 → nnodely-1.4.0}/tests/test_input_dimensions.py +91 -93
  56. {nnodely-1.3.0 → nnodely-1.4.0}/tests/test_json.py +6 -8
  57. nnodely-1.4.0/tests/test_losses.py +189 -0
  58. {nnodely-1.3.0 → nnodely-1.4.0}/tests/test_model_predict.py +145 -24
  59. {nnodely-1.3.0 → nnodely-1.4.0}/tests/test_model_predict_recurrent.py +131 -50
  60. {nnodely-1.3.0 → nnodely-1.4.0}/tests/test_network_element.py +49 -18
  61. {nnodely-1.3.0 → nnodely-1.4.0}/tests/test_parameters_of_train.py +32 -31
  62. {nnodely-1.3.0 → nnodely-1.4.0}/tests/test_results.py +20 -38
  63. {nnodely-1.3.0 → nnodely-1.4.0}/tests/test_train.py +116 -87
  64. {nnodely-1.3.0 → nnodely-1.4.0}/tests/test_train_recurrent.py +482 -378
  65. {nnodely-1.3.0 → nnodely-1.4.0}/tests/test_utils.py +2 -5
  66. {nnodely-1.3.0 → nnodely-1.4.0}/tests/test_visualizer.py +64 -38
  67. nnodely-1.3.0/nnodely/__init__.py +0 -45
  68. nnodely-1.3.0/nnodely/nnodely.py +0 -1996
  69. nnodely-1.3.0/nnodely/timeoperation.py +0 -46
  70. nnodely-1.3.0/nnodely/visualizer/mplvisualizer.py +0 -215
  71. nnodely-1.3.0/tests/test_losses.py +0 -174
  72. {nnodely-1.3.0 → nnodely-1.4.0}/LICENSE +0 -0
  73. {nnodely-1.3.0 → nnodely-1.4.0}/mplplots/__init__.py +0 -0
  74. {nnodely-1.3.0 → nnodely-1.4.0}/mplplots/plots.py +0 -0
  75. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/support}/earlystopping.py +0 -0
  76. {nnodely-1.3.0/nnodely → nnodely-1.4.0/nnodely/support}/logger.py +0 -0
  77. {nnodely-1.3.0 → nnodely-1.4.0}/nnodely/visualizer/__init__.py +0 -0
  78. {nnodely-1.3.0 → nnodely-1.4.0}/nnodely/visualizer/dynamicmpl/functionplot.py +0 -0
  79. {nnodely-1.3.0 → nnodely-1.4.0}/nnodely/visualizer/dynamicmpl/fuzzyplot.py +0 -0
  80. {nnodely-1.3.0 → nnodely-1.4.0}/nnodely/visualizer/dynamicmpl/resultsplot.py +0 -0
  81. {nnodely-1.3.0 → nnodely-1.4.0}/nnodely/visualizer/dynamicmpl/trainingplot.py +0 -0
  82. {nnodely-1.3.0 → nnodely-1.4.0}/nnodely.egg-info/dependency_links.txt +0 -0
  83. {nnodely-1.3.0 → nnodely-1.4.0}/nnodely.egg-info/top_level.txt +0 -0
  84. {nnodely-1.3.0 → nnodely-1.4.0}/setup.cfg +0 -0
  85. {nnodely-1.3.0 → nnodely-1.4.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: nnodely
3
- Version: 1.3.0
3
+ Version: 1.4.0
4
4
  Summary: Model-structured neural network framework for the modeling and control of physical systems
5
5
  Author-email: Gastone Pietro Rosati Papini <tonegas@gmail.com>
6
6
  License: MIT License
@@ -32,15 +32,16 @@ Classifier: Operating System :: OS Independent
32
32
  Requires-Python: <3.13,>=3.10
33
33
  Description-Content-Type: text/markdown
34
34
  License-File: LICENSE
35
- Requires-Dist: numpy==1.26.4; platform_machine == "x86_64"
36
- Requires-Dist: torch==2.2.2; platform_machine == "x86_64"
37
- Requires-Dist: numpy; platform_machine != "x86_64"
38
- Requires-Dist: torch; platform_machine != "x86_64"
35
+ Requires-Dist: numpy==1.26.4; platform_machine == "x86_64" and python_version == "3.10"
36
+ Requires-Dist: torch==2.2.2; platform_machine == "x86_64" and python_version == "3.10"
37
+ Requires-Dist: numpy
38
+ Requires-Dist: torch
39
39
  Requires-Dist: onnx
40
40
  Requires-Dist: pandas
41
41
  Requires-Dist: reportlab
42
42
  Requires-Dist: matplotlib
43
43
  Requires-Dist: onnxruntime
44
+ Dynamic: license-file
44
45
 
45
46
  <p align="center">
46
47
  <img src="https://raw.githubusercontent.com/tonegas/nnodely/main/imgs/logo_white_info.png" alt="logo" >
@@ -51,7 +52,7 @@ Requires-Dist: onnxruntime
51
52
  [![Coverage Status](https://readthedocs.org/projects/nnodely/badge/?version=latest&style=default)](https://nnodely.readthedocs.io/en/latest/)
52
53
 
53
54
  <a name="readme-top"></a>
54
- ## Model-structured neural network framework for the modeling and control of physical systems
55
+ # Model-structured neural network framework for the modeling and control of physical systems
55
56
 
56
57
  Modeling, control, and estimation of physical systems are fundamental to a wide range of engineering applications.
57
58
  However, integrating data-driven methods like neural networks into these domains presents significant challenges,
@@ -62,7 +63,7 @@ MSNNs merge the flexibility of neural networks with structures grounded in physi
62
63
  providing a powerful tool for representing and managing complex physical systems. Moreover, a MSNN thanks to the reduced
63
64
  number of parameters needs fewer data for training and can be used in real-time applications.
64
65
 
65
- ### Why use nnodely
66
+ ## Why use nnodely
66
67
 
67
68
  The framework's goal is to allow the users fast modeling and control of a any mechanical systems using
68
69
  a hybrind approach between neural networks and physical models.
@@ -92,13 +93,13 @@ a Pytorch (nnodely independent) and ONNX export.
92
93
  <a href="#settingstarted">Getting Started</a>
93
94
  </li>
94
95
  <li>
95
- <a href="#basicfunctionalities">Basic Functionalities</a>
96
+ <a href="#basicfunctionalities">Basic Example</a>
96
97
  <ul>
97
- <li><a href="#structuredneuralmodel">Build the structured neural model</a></li>
98
- <li><a href="#neuralizemodel">Neuralize the structured neural model</a></li>
98
+ <li><a href="#structuredneuralmodel">Build the neural model</a></li>
99
+ <li><a href="#neuralizemodel">Neuralize the neural model</a></li>
99
100
  <li><a href="#loaddataset">Load the dataset</a></li>
100
- <li><a href="#trainmodel">Train the structured neural network</a></li>
101
- <li><a href="#testmodel">Test the structured neural model</a></li>
101
+ <li><a href="#trainmodel">Train the neural model</a></li>
102
+ <li><a href="#testmodel">Test the neural model</a></li>
102
103
  </ul>
103
104
  </li>
104
105
  <li>
@@ -109,15 +110,14 @@ a Pytorch (nnodely independent) and ONNX export.
109
110
  <li><a href="#examplesfolder">examples folder</a></li>
110
111
  </ul>
111
112
  </li>
112
- <li>
113
- <a href="#license">License</a>
114
- </li>
113
+ <li><a href="#license">License</a></li>
114
+ <li><a href="#references">References</a></li>
115
115
  </ol>
116
116
  </details>
117
117
 
118
118
  <!-- GETTING STARTED -->
119
119
  <a name="settingstarted"></a>
120
- ### Getting Started
120
+ ## Getting Started
121
121
  You can install the nnodely framework from PyPI via:
122
122
  ```sh
123
123
  pip install nnodely
@@ -191,7 +191,7 @@ Our formulation is more general and can take into account the noise of the measu
191
191
  The estimator can also be seen as the composition of the force contributions due to the position and velocity of the mass plus the contribution of external forces.
192
192
 
193
193
  <a name="neuralizemodel"></a>
194
- ### Neuralize the structured neural model
194
+ ### Neuralize the neural model
195
195
  Let's now try to train our observer using the data we have.
196
196
  We perform:
197
197
  ```python
@@ -233,7 +233,7 @@ mass_spring_damper.loadData(name='mass_spring_dataset', source=data_folder, form
233
233
  Finally, the dataset is loaded. **nnodely** loads all the files that are in a source folder.
234
234
 
235
235
  <a name="trainmodel"></a>
236
- ### Train the structured neural network
236
+ ### Train the neural network
237
237
  Using the dataset created the training is performed on the model.
238
238
 
239
239
  ```python
@@ -241,7 +241,7 @@ mass_spring_damper.trainModel()
241
241
  ```
242
242
 
243
243
  <a name="testmodel"></a>
244
- ### Test the structured neural model
244
+ ### Test the neural model
245
245
  In order to test the results we need to create a input, in this case is defined by:
246
246
  1. `x` with 5 sample because the sample time is 0.2 and the window of `x`is 1 second.
247
247
  2. `F` is one sample because only the last sample is needed.
@@ -309,7 +309,7 @@ This operation is presented in [[1]](#1).
309
309
  3. __localmodel.py__ this file contains the logic for build a local model. This operation is presented in [[1]](#1), [[3]](#3), [[4]](#4) and [[5]](#5).
310
310
  4. __parametricfunction.py__ are the user custom function. The function can use the pytorch syntax. A parametric function is presented in [[3]](#3), [[4]](#4), [[5]](#5).
311
311
  5. __equationlearner.py__ contains the logic for the equation learner. The equation learner is used for learn a relation input outpur following a list of activation functions. The first implementation is presented in [[6]](#6).
312
- 6. __timeoperation.py__ contains the time operation functions. The time operation are used for extract a time window from a signal.
312
+ 6. __timeoperation.py__ contains the time operation functions. The time operation are used for extract a time window from a signal. The derivative operation can be used to implement Physics-informed neural network [[7]](#7) Sobolev learning [[8]](#8).
313
313
 
314
314
  <a name="testsfolder"></a>
315
315
  ### Tests Folder
@@ -329,6 +329,7 @@ This project is released under the license [License: MIT](https://opensource.org
329
329
 
330
330
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
331
331
 
332
+ <a name="references"></a>
332
333
  ## References
333
334
  <a id="1">[1]</a>
334
335
  Mauro Da Lio, Daniele Bortoluzzi, Gastone Pietro Rosati Papini. (2019).
@@ -359,4 +360,17 @@ and [[code extended]](https://github.com/tonegas/nnodely-applications/blob/main/
359
360
  <a id="6">[6]</a>
360
361
  Hector Perez-Villeda, Justus Piater, Matteo Saveriano. (2023).
361
362
  Learning and extrapolation of robotic skills using task-parameterized equation learner networks.
362
- Robotics and Autonomous Systems. https://doi.org/10.1016/j.robot.2022.104309
363
+ Robotics and Autonomous Systems. https://doi.org/10.1016/j.robot.2022.104309 (look the [[code]](https://github.com/tonegas/nnodely-applications/blob/main/equation_learner/equation_learner.ipynb))
364
+
365
+ <a id="7">[7]</a>
366
+ M. Raissi. P. Perdikaris b, G.E. Karniadakis a. (2019).
367
+ Physics-informed neural networks: A deep learning framework for solving forward and inverse problems involving nonlinear partial differential equations
368
+ Journal of Computational Physics. https://doi.org/10.1016/j.jcp.2018.10.045 (look the [[example Burger's equation]](https://github.com/tonegas/nnodely-applications/blob/main/pinn/pinn_Burgers_equation.ipynb))
369
+
370
+ <a id="8">[8]</a>
371
+ Wojciech Marian Czarnecki, Simon Osindero, Max Jaderberg, Grzegorz Świrszcz, Razvan Pascanu. (2017).
372
+ Sobolev Training for Neural Networks.
373
+ arXiv. https://doi.org/10.48550/arXiv.1706.04859 (look the [[code]](https://github.com/tonegas/nnodely-applications/blob/main/sobolev/Sobolev_learning.ipynb))
374
+
375
+
376
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
@@ -7,7 +7,7 @@
7
7
  [![Coverage Status](https://readthedocs.org/projects/nnodely/badge/?version=latest&style=default)](https://nnodely.readthedocs.io/en/latest/)
8
8
 
9
9
  <a name="readme-top"></a>
10
- ## Model-structured neural network framework for the modeling and control of physical systems
10
+ # Model-structured neural network framework for the modeling and control of physical systems
11
11
 
12
12
  Modeling, control, and estimation of physical systems are fundamental to a wide range of engineering applications.
13
13
  However, integrating data-driven methods like neural networks into these domains presents significant challenges,
@@ -18,7 +18,7 @@ MSNNs merge the flexibility of neural networks with structures grounded in physi
18
18
  providing a powerful tool for representing and managing complex physical systems. Moreover, a MSNN thanks to the reduced
19
19
  number of parameters needs fewer data for training and can be used in real-time applications.
20
20
 
21
- ### Why use nnodely
21
+ ## Why use nnodely
22
22
 
23
23
  The framework's goal is to allow the users fast modeling and control of a any mechanical systems using
24
24
  a hybrind approach between neural networks and physical models.
@@ -48,13 +48,13 @@ a Pytorch (nnodely independent) and ONNX export.
48
48
  <a href="#settingstarted">Getting Started</a>
49
49
  </li>
50
50
  <li>
51
- <a href="#basicfunctionalities">Basic Functionalities</a>
51
+ <a href="#basicfunctionalities">Basic Example</a>
52
52
  <ul>
53
- <li><a href="#structuredneuralmodel">Build the structured neural model</a></li>
54
- <li><a href="#neuralizemodel">Neuralize the structured neural model</a></li>
53
+ <li><a href="#structuredneuralmodel">Build the neural model</a></li>
54
+ <li><a href="#neuralizemodel">Neuralize the neural model</a></li>
55
55
  <li><a href="#loaddataset">Load the dataset</a></li>
56
- <li><a href="#trainmodel">Train the structured neural network</a></li>
57
- <li><a href="#testmodel">Test the structured neural model</a></li>
56
+ <li><a href="#trainmodel">Train the neural model</a></li>
57
+ <li><a href="#testmodel">Test the neural model</a></li>
58
58
  </ul>
59
59
  </li>
60
60
  <li>
@@ -65,15 +65,14 @@ a Pytorch (nnodely independent) and ONNX export.
65
65
  <li><a href="#examplesfolder">examples folder</a></li>
66
66
  </ul>
67
67
  </li>
68
- <li>
69
- <a href="#license">License</a>
70
- </li>
68
+ <li><a href="#license">License</a></li>
69
+ <li><a href="#references">References</a></li>
71
70
  </ol>
72
71
  </details>
73
72
 
74
73
  <!-- GETTING STARTED -->
75
74
  <a name="settingstarted"></a>
76
- ### Getting Started
75
+ ## Getting Started
77
76
  You can install the nnodely framework from PyPI via:
78
77
  ```sh
79
78
  pip install nnodely
@@ -147,7 +146,7 @@ Our formulation is more general and can take into account the noise of the measu
147
146
  The estimator can also be seen as the composition of the force contributions due to the position and velocity of the mass plus the contribution of external forces.
148
147
 
149
148
  <a name="neuralizemodel"></a>
150
- ### Neuralize the structured neural model
149
+ ### Neuralize the neural model
151
150
  Let's now try to train our observer using the data we have.
152
151
  We perform:
153
152
  ```python
@@ -189,7 +188,7 @@ mass_spring_damper.loadData(name='mass_spring_dataset', source=data_folder, form
189
188
  Finally, the dataset is loaded. **nnodely** loads all the files that are in a source folder.
190
189
 
191
190
  <a name="trainmodel"></a>
192
- ### Train the structured neural network
191
+ ### Train the neural network
193
192
  Using the dataset created the training is performed on the model.
194
193
 
195
194
  ```python
@@ -197,7 +196,7 @@ mass_spring_damper.trainModel()
197
196
  ```
198
197
 
199
198
  <a name="testmodel"></a>
200
- ### Test the structured neural model
199
+ ### Test the neural model
201
200
  In order to test the results we need to create a input, in this case is defined by:
202
201
  1. `x` with 5 sample because the sample time is 0.2 and the window of `x`is 1 second.
203
202
  2. `F` is one sample because only the last sample is needed.
@@ -265,7 +264,7 @@ This operation is presented in [[1]](#1).
265
264
  3. __localmodel.py__ this file contains the logic for build a local model. This operation is presented in [[1]](#1), [[3]](#3), [[4]](#4) and [[5]](#5).
266
265
  4. __parametricfunction.py__ are the user custom function. The function can use the pytorch syntax. A parametric function is presented in [[3]](#3), [[4]](#4), [[5]](#5).
267
266
  5. __equationlearner.py__ contains the logic for the equation learner. The equation learner is used for learn a relation input outpur following a list of activation functions. The first implementation is presented in [[6]](#6).
268
- 6. __timeoperation.py__ contains the time operation functions. The time operation are used for extract a time window from a signal.
267
+ 6. __timeoperation.py__ contains the time operation functions. The time operation are used for extract a time window from a signal. The derivative operation can be used to implement Physics-informed neural network [[7]](#7) Sobolev learning [[8]](#8).
269
268
 
270
269
  <a name="testsfolder"></a>
271
270
  ### Tests Folder
@@ -285,6 +284,7 @@ This project is released under the license [License: MIT](https://opensource.org
285
284
 
286
285
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
287
286
 
287
+ <a name="references"></a>
288
288
  ## References
289
289
  <a id="1">[1]</a>
290
290
  Mauro Da Lio, Daniele Bortoluzzi, Gastone Pietro Rosati Papini. (2019).
@@ -315,4 +315,17 @@ and [[code extended]](https://github.com/tonegas/nnodely-applications/blob/main/
315
315
  <a id="6">[6]</a>
316
316
  Hector Perez-Villeda, Justus Piater, Matteo Saveriano. (2023).
317
317
  Learning and extrapolation of robotic skills using task-parameterized equation learner networks.
318
- Robotics and Autonomous Systems. https://doi.org/10.1016/j.robot.2022.104309
318
+ Robotics and Autonomous Systems. https://doi.org/10.1016/j.robot.2022.104309 (look the [[code]](https://github.com/tonegas/nnodely-applications/blob/main/equation_learner/equation_learner.ipynb))
319
+
320
+ <a id="7">[7]</a>
321
+ M. Raissi. P. Perdikaris b, G.E. Karniadakis a. (2019).
322
+ Physics-informed neural networks: A deep learning framework for solving forward and inverse problems involving nonlinear partial differential equations
323
+ Journal of Computational Physics. https://doi.org/10.1016/j.jcp.2018.10.045 (look the [[example Burger's equation]](https://github.com/tonegas/nnodely-applications/blob/main/pinn/pinn_Burgers_equation.ipynb))
324
+
325
+ <a id="8">[8]</a>
326
+ Wojciech Marian Czarnecki, Simon Osindero, Max Jaderberg, Grzegorz Świrszcz, Razvan Pascanu. (2017).
327
+ Sobolev Training for Neural Networks.
328
+ arXiv. https://doi.org/10.48550/arXiv.1706.04859 (look the [[code]](https://github.com/tonegas/nnodely-applications/blob/main/sobolev/Sobolev_learning.ipynb))
329
+
330
+
331
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
@@ -0,0 +1,47 @@
1
+
2
+ __version__ = '1.4.0'
3
+
4
+ import sys
5
+ major, minor = sys.version_info.major, sys.version_info.minor
6
+
7
+ import logging
8
+ LOG_LEVEL = logging.INFO
9
+
10
+ if major < 3:
11
+ sys.exit("Sorry, Python 2 is not supported. You need Python >= 3.10 for "+__package__+".")
12
+ elif minor < 9:
13
+ sys.exit("Sorry, You need Python >= 3.10 for "+__package__+".")
14
+ else:
15
+ print(f'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'+
16
+ f' {__package__}_v{__version__} '.center(20, '-')+
17
+ f'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<')
18
+
19
+ # Network input, outputs and parameters
20
+ from nnodely.layers.input import Input, State, Connect, ClosedLoop
21
+ from nnodely.layers.parameter import Parameter, Constant, SampleTime
22
+ from nnodely.layers.output import Output
23
+
24
+ # Network elements
25
+ from nnodely.layers.activation import Relu, ELU, Softmax, Sigmoid, Identity
26
+ from nnodely.layers.fir import Fir
27
+ from nnodely.layers.linear import Linear
28
+ from nnodely.layers.arithmetic import Add, Sum, Sub, Mul, Div, Pow, Neg
29
+ from nnodely.layers.trigonometric import Sin, Cos, Tan, Cosh, Tanh, Sech
30
+ from nnodely.layers.parametricfunction import ParamFun
31
+ from nnodely.layers.fuzzify import Fuzzify
32
+ from nnodely.layers.part import Part, Select, Concatenate, SamplePart, SampleSelect, TimePart, TimeConcatenate
33
+ from nnodely.layers.localmodel import LocalModel
34
+ from nnodely.layers.equationlearner import EquationLearner
35
+ from nnodely.layers.timeoperation import Integrate, Derivate
36
+ from nnodely.layers.interpolation import Interpolation
37
+
38
+ # Main nnodely classes
39
+ from nnodely.nnodely import nnodely, Modely, clearNames
40
+ from nnodely.visualizer import Visualizer, TextVisualizer, MPLVisualizer, MPLNotebookVisualizer
41
+ from nnodely.exporter import StandardExporter
42
+
43
+ # Basic nnodely
44
+ from nnodely.basic.optimizer import Optimizer, SGD, Adam
45
+
46
+ # Support functions
47
+ from nnodely.support.initializer import init_negexp, init_lin, init_constant, init_exp
File without changes
@@ -1,8 +1,8 @@
1
1
  import torch.nn as nn
2
2
  import torch
3
- from nnodely.utils import check
3
+ from nnodely.support.utils import check
4
4
 
5
- available_losses = ['mse', 'rmse', 'mae']
5
+ available_losses = ['mse', 'rmse', 'mae', 'cross_entropy']
6
6
 
7
7
  # class CustomRMSE(nn.Module):
8
8
  # def __init__(self):
@@ -15,15 +15,22 @@ available_losses = ['mse', 'rmse', 'mae']
15
15
  # return self.mse(inA, inB)
16
16
 
17
17
  class CustomLoss(nn.Module):
18
- def __init__(self, loss_type='mse'):
18
+ def __init__(self, loss_type='mse', **kwargs):
19
19
  super(CustomLoss, self).__init__()
20
20
  check(loss_type in available_losses, TypeError, f'The \"{loss_type}\" loss is not available. Possible losses are: {available_losses}.')
21
21
  self.loss_type = loss_type
22
- self.loss = nn.MSELoss()
23
- if self.loss_type == 'mae':
24
- self.loss = nn.L1Loss()
22
+ self.loss = nn.MSELoss(**kwargs)
23
+ if callable(loss_type):
24
+ self.loss = loss_type
25
+ elif self.loss_type == 'mae':
26
+ self.loss = nn.L1Loss(**kwargs)
27
+ elif self.loss_type == 'cross_entropy':
28
+ self.loss = nn.CrossEntropyLoss(**kwargs)
25
29
 
26
30
  def forward(self, inA, inB):
31
+ if self.loss_type == 'cross_entropy':
32
+ inB = inB.squeeze().float() if inA.shape == inB.shape else inB.squeeze().long()
33
+ inA = inA.squeeze()
27
34
  res = self.loss(inA,inB)
28
35
  if self.loss_type == 'rmse':
29
36
  res = torch.sqrt(res)
@@ -1,6 +1,6 @@
1
1
  from itertools import product
2
- from nnodely.utils import TORCH_DTYPE
3
- from nnodely import initializer
2
+ from nnodely.support.utils import TORCH_DTYPE
3
+ from nnodely.support import initializer
4
4
  import numpy as np
5
5
 
6
6
  import torch.nn as nn
@@ -34,14 +34,6 @@ class Model(nn.Module):
34
34
  self.input_n_samples = {key:value['ntot'] for key, value in (model_def['Inputs']|model_def['States']).items()}
35
35
  self.minimizers_keys = [self.minimizers[key]['A'] for key in self.minimizers] + [self.minimizers[key]['B'] for key in self.minimizers]
36
36
 
37
- #print('inputs: ',self.inputs)
38
- #print('outputs: ',self.outputs)
39
- #print('relations: ',self.relations)
40
- #print('params: ',self.params)
41
- #print('constants: ',self.constants)
42
- #print('sample_time: ',self.sample_time)
43
- #print('states: ',self.states)
44
-
45
37
  ## Build the network
46
38
  self.all_parameters = {}
47
39
  self.all_constants = {}
@@ -149,7 +141,7 @@ class Model(nn.Module):
149
141
  self.network_output_predictions = set(self.outputs.values())
150
142
 
151
143
  ## list of network minimization outputs
152
- self.network_output_minimizers = []
144
+ self.network_output_minimizers = []
153
145
  for _,value in self.minimizers.items():
154
146
  self.network_output_minimizers.append(self.outputs[value['A']]) if value['A'] in self.outputs.keys() else self.network_output_minimizers.append(value['A'])
155
147
  self.network_output_minimizers.append(self.outputs[value['B']]) if value['B'] in self.outputs.keys() else self.network_output_minimizers.append(value['B'])
@@ -178,7 +170,7 @@ class Model(nn.Module):
178
170
  layer_inputs.append(self.all_constants[key])
179
171
  elif key in available_states: ## relation that takes a state
180
172
  layer_inputs.append(kwargs[key])
181
- elif key in available_inputs: ## relation that takes inputs
173
+ elif key in available_inputs: ## relation that takes inputs
182
174
  layer_inputs.append(kwargs[key])
183
175
  elif key in self.all_parameters.keys(): ## relation that takes parameters
184
176
  layer_inputs.append(self.all_parameters[key])
@@ -205,7 +197,7 @@ class Model(nn.Module):
205
197
  minimize_dict = {}
206
198
  for key in self.minimizers_keys:
207
199
  minimize_dict[key] = result_dict[self.outputs[key]] if key in self.outputs.keys() else result_dict[key]
208
-
200
+
209
201
  return output_dict, minimize_dict, closed_loop_update_dict, connect_update_dict
210
202
 
211
203