nnodely 1.5.2__tar.gz → 1.5.5.dev1__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 (109) hide show
  1. nnodely-1.5.5.dev1/PKG-INFO +297 -0
  2. nnodely-1.5.5.dev1/README.md +272 -0
  3. nnodely-1.5.5.dev1/pyproject.toml +44 -0
  4. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/__init__.py +83 -31
  5. nnodely-1.5.5.dev1/src/nnodely/basic/loss.py +36 -0
  6. nnodely-1.5.5.dev1/src/nnodely/basic/model.py +324 -0
  7. nnodely-1.5.5.dev1/src/nnodely/basic/modeldef.py +345 -0
  8. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/basic/optimizer.py +42 -26
  9. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/basic/relation.py +166 -70
  10. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/exporter/emptyexporter.py +13 -11
  11. nnodely-1.5.5.dev1/src/nnodely/exporter/export.py +532 -0
  12. nnodely-1.5.5.dev1/src/nnodely/exporter/reporter.py +81 -0
  13. nnodely-1.5.5.dev1/src/nnodely/exporter/standardexporter.py +196 -0
  14. nnodely-1.5.5.dev1/src/nnodely/layers/activation.py +240 -0
  15. nnodely-1.5.5.dev1/src/nnodely/layers/arithmetic.py +407 -0
  16. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/layers/equationlearner.py +81 -44
  17. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/layers/fir.py +111 -65
  18. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/layers/fuzzify.py +151 -84
  19. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/layers/input.py +149 -85
  20. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/layers/interpolation.py +55 -25
  21. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/layers/linear.py +107 -56
  22. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/layers/localmodel.py +39 -47
  23. nnodely-1.5.5.dev1/src/nnodely/layers/neuralODE.py +122 -0
  24. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/layers/output.py +9 -6
  25. nnodely-1.5.5.dev1/src/nnodely/layers/parameter.py +266 -0
  26. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/layers/parametricfunction.py +209 -102
  27. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/layers/part.py +252 -162
  28. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/layers/rungekutta.py +30 -28
  29. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/layers/timeoperation.py +55 -19
  30. nnodely-1.5.5.dev1/src/nnodely/layers/trigonometric.py +275 -0
  31. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/nnodely.py +110 -83
  32. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/operators/composer.py +225 -133
  33. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/operators/exporter.py +149 -132
  34. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/operators/loader.py +165 -108
  35. nnodely-1.5.5.dev1/src/nnodely/operators/network.py +711 -0
  36. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/operators/trainer.py +311 -157
  37. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/operators/validator.py +214 -97
  38. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/support/earlystopping.py +28 -16
  39. nnodely-1.5.5.dev1/src/nnodely/support/fixstepsolver.py +48 -0
  40. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/support/initializer.py +60 -21
  41. nnodely-1.5.5.dev1/src/nnodely/support/jsonutils.py +678 -0
  42. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/support/logger.py +31 -20
  43. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/support/mathutils.py +9 -2
  44. nnodely-1.5.5.dev1/src/nnodely/support/odeint/__init__.py +0 -0
  45. nnodely-1.5.5.dev1/src/nnodely/support/odeint/adjoint.py +406 -0
  46. nnodely-1.5.5.dev1/src/nnodely/support/odeint/dopri5.py +60 -0
  47. nnodely-1.5.5.dev1/src/nnodely/support/odeint/fixed_grid.py +18 -0
  48. nnodely-1.5.5.dev1/src/nnodely/support/odeint/my_odeint.py +158 -0
  49. nnodely-1.5.5.dev1/src/nnodely/support/odeint/rk_solvers.py +547 -0
  50. nnodely-1.5.5.dev1/src/nnodely/support/odeint/solvers.py +233 -0
  51. nnodely-1.5.5.dev1/src/nnodely/support/odeint/utils.py +279 -0
  52. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/support/utils.py +48 -19
  53. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/visualizer/__init__.py +1 -1
  54. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/visualizer/dynamicmpl/functionplot.py +11 -11
  55. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/visualizer/dynamicmpl/fuzzyplot.py +8 -7
  56. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/visualizer/dynamicmpl/resultsplot.py +8 -7
  57. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/visualizer/dynamicmpl/trainingplot.py +10 -7
  58. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/visualizer/emptyvisualizer.py +7 -5
  59. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/visualizer/mplnotebookvisualizer.py +63 -34
  60. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/visualizer/mplvisualizer.py +152 -74
  61. nnodely-1.5.5.dev1/src/nnodely/visualizer/textvisualizer.py +493 -0
  62. nnodely-1.5.2/PKG-INFO +0 -406
  63. nnodely-1.5.2/README.md +0 -360
  64. nnodely-1.5.2/mplplots/__init__.py +0 -1
  65. nnodely-1.5.2/mplplots/plots.py +0 -188
  66. nnodely-1.5.2/nnodely/basic/loss.py +0 -27
  67. nnodely-1.5.2/nnodely/basic/model.py +0 -220
  68. nnodely-1.5.2/nnodely/basic/modeldef.py +0 -230
  69. nnodely-1.5.2/nnodely/exporter/export.py +0 -396
  70. nnodely-1.5.2/nnodely/exporter/reporter.py +0 -55
  71. nnodely-1.5.2/nnodely/exporter/standardexporter.py +0 -117
  72. nnodely-1.5.2/nnodely/layers/activation.py +0 -195
  73. nnodely-1.5.2/nnodely/layers/arithmetic.py +0 -336
  74. nnodely-1.5.2/nnodely/layers/parameter.py +0 -245
  75. nnodely-1.5.2/nnodely/layers/trigonometric.py +0 -207
  76. nnodely-1.5.2/nnodely/operators/network.py +0 -421
  77. nnodely-1.5.2/nnodely/support/fixstepsolver.py +0 -35
  78. nnodely-1.5.2/nnodely/support/jsonutils.py +0 -459
  79. nnodely-1.5.2/nnodely/visualizer/textvisualizer.py +0 -319
  80. nnodely-1.5.2/nnodely.egg-info/PKG-INFO +0 -406
  81. nnodely-1.5.2/nnodely.egg-info/SOURCES.txt +0 -81
  82. nnodely-1.5.2/nnodely.egg-info/dependency_links.txt +0 -1
  83. nnodely-1.5.2/nnodely.egg-info/requires.txt +0 -14
  84. nnodely-1.5.2/nnodely.egg-info/top_level.txt +0 -2
  85. nnodely-1.5.2/pyproject.toml +0 -49
  86. nnodely-1.5.2/setup.cfg +0 -4
  87. nnodely-1.5.2/setup.py +0 -27
  88. nnodely-1.5.2/tests/test_dataset.py +0 -974
  89. nnodely-1.5.2/tests/test_documentation.py +0 -25
  90. nnodely-1.5.2/tests/test_export.py +0 -344
  91. nnodely-1.5.2/tests/test_export_recurrent.py +0 -1062
  92. nnodely-1.5.2/tests/test_input_dimensions.py +0 -438
  93. nnodely-1.5.2/tests/test_json.py +0 -741
  94. nnodely-1.5.2/tests/test_losses.py +0 -190
  95. nnodely-1.5.2/tests/test_model_predict.py +0 -1947
  96. nnodely-1.5.2/tests/test_model_predict_recurrent.py +0 -1595
  97. nnodely-1.5.2/tests/test_network_element.py +0 -516
  98. nnodely-1.5.2/tests/test_parameters_of_train.py +0 -1208
  99. nnodely-1.5.2/tests/test_results.py +0 -317
  100. nnodely-1.5.2/tests/test_train.py +0 -315
  101. nnodely-1.5.2/tests/test_train_recurrent.py +0 -1785
  102. nnodely-1.5.2/tests/test_utils.py +0 -25
  103. nnodely-1.5.2/tests/test_visualizer.py +0 -271
  104. {nnodely-1.5.2 → nnodely-1.5.5.dev1}/LICENSE +0 -0
  105. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/basic/__init__.py +0 -0
  106. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/exporter/__init__.py +0 -0
  107. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/layers/__init__.py +0 -0
  108. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/operators/__init__.py +0 -0
  109. {nnodely-1.5.2 → nnodely-1.5.5.dev1/src}/nnodely/support/__init__.py +0 -0
@@ -0,0 +1,297 @@
1
+ Metadata-Version: 2.4
2
+ Name: nnodely
3
+ Version: 1.5.5.dev1
4
+ Summary: Model-structured neural network framework for the modeling and control of physical systems
5
+ Author: Gastone Pietro Rosati Papini
6
+ Author-email: Gastone Pietro Rosati Papini <tonegas@gmail.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Dist: numpy==1.26.4 ; python_full_version == '3.10.*' and platform_machine == 'x86_64'
12
+ Requires-Dist: torch==2.2.2 ; python_full_version == '3.10.*' and platform_machine == 'x86_64'
13
+ Requires-Dist: torch==2.6.0 ; python_full_version != '3.10.*' or platform_machine != 'x86_64'
14
+ Requires-Dist: numpy
15
+ Requires-Dist: onnx
16
+ Requires-Dist: pandas
17
+ Requires-Dist: reportlab
18
+ Requires-Dist: matplotlib
19
+ Requires-Dist: onnxruntime
20
+ Requires-Dist: graphviz
21
+ Requires-Python: >=3.10, <3.14
22
+ Project-URL: Homepage, https://github.com/tonegas/nnodely
23
+ Project-URL: Repository, https://github.com/tonegas/nnodely
24
+ Description-Content-Type: text/markdown
25
+
26
+ <a name="readme-top"></a>
27
+ <p align="center">
28
+ <img src="https://raw.githubusercontent.com/tonegas/nnodely/main/imgs/logo_white_info.png" alt="logo" >
29
+ </p>
30
+
31
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
32
+ [![codecov](https://codecov.io/github/tonegas/nnodely/graph/badge.svg?token=8V6P2PSYT4)](https://codecov.io/github/tonegas/nnodely)
33
+ [![Documentation](https://readthedocs.org/projects/nnodely/badge/?version=main&style=default)](https://nnodely.readthedocs.io/)
34
+ [![PyPI](https://img.shields.io/pypi/v/nnodely?color=blue&label=PyPI%20Package)](https://pypi.org/project/nnodely/)
35
+
36
+ # Neural Network Framework for Modelling, Control, and Estimation of Physical Systems
37
+
38
+ Modeling, control, and estimation of physical systems are central to many engineering disciplines. While data-driven methods like neural networks offer powerful tools, they often struggle to **incorporate prior domain knowledge**, limiting their interpretability, generalizability, and safety.
39
+
40
+ To bridge this gap, we present ***nnodely*** (where "nn" can be read as "m," forming *Modely*) — a framework that facilitates the creation and deployment of **Model-Structured Neural Networks** (**MS-NNs**).
41
+ MS-NNs combine the learning capabilities of neural networks with structural **priors** grounded in **physics, control, and estimation theory**, enabling:
42
+
43
+ - **Reduced training data** requirements
44
+ - **Generalization** to unseen scenarios
45
+ - **Real-time** deployment in real-world applications
46
+
47
+ In short:
48
+
49
+ nnodely is not a replacement for a general purpose deep learning frameworks — it is a **structured layer on top of them**, purpose-built for physical systems.
50
+
51
+ <br>
52
+ <p align="center">
53
+ 📖 <a href="https://nnodely.readthedocs.io/"><b>Documentation</b></a> •
54
+ 🔬 <a href="./case-studies/"><b>Case Studies</b></a> •
55
+ 🚀 <a href="https://github.com/tonegas/nnodely-applications"><b>Other Applications</b></a>
56
+ </p>
57
+
58
+ <!-- > [!NOTE]
59
+ > **Full documentation** of the code is available at the following [link](https://nnodely.readthedocs.io/en/docs-update/)
60
+
61
+ > Some **examples of applications** of nnodely in different fields are collected in the following open-source repository: [nnodely-applications](https://github.com/tonegas/nnodely-applications) -->
62
+
63
+ <h2>Table of Contents</h2>
64
+ <ol>
65
+ <li><a href="#gettingstarted">Getting Started</a></li>
66
+ <ul>
67
+ <li><a href="#installation">Installation</a></li>
68
+ <li><a href="#helloworld">Hello, World!</a></li>
69
+ </ul>
70
+ <li><a href="#folderstructure">Structure of the Repository</a></li>
71
+ <li><a href="#contribute">How to contribute</a></li>
72
+ <li><a href="#license">License</a></li>
73
+ <li><a href="#references">References</a></li>
74
+ </ol>
75
+
76
+
77
+ <a name="gettingstarted"></a>
78
+ ## Getting Started
79
+
80
+ <a name="installation"></a>
81
+ ### Installation
82
+
83
+ You can install nnodely from PyPI via:
84
+
85
+ ```sh
86
+ pip install nnodely
87
+ ```
88
+
89
+ Alternatively, you can build it from source by first cloning the repository and installing the requirements and the nnodely library:
90
+
91
+ ```sh
92
+ git clone https://github.com/tonegas/nnodely.git
93
+ cd nnodely
94
+ pip install -r requirements.txt
95
+ pip install .
96
+ ```
97
+ <a name="helloworld"></a>
98
+ ### Hello, World!
99
+ To check if `nnodely` is installed correctly try running the following script.
100
+
101
+ ```python
102
+ from nnodely import Input, Output, nnodely, Parameter
103
+
104
+ x = Input("x")
105
+ l = x.last()
106
+ o = (Parameter('A')*l.sw([-2,-1])+Parameter('B')*l).closedLoop(x)
107
+ f = Output("fib",o)
108
+ model = nnodely()
109
+ model.addModel("Fibonacci",f)
110
+ model.addMinimize("target", l.sw([-2,-1])+l, f)
111
+ model.neuralizeModel(1)
112
+ model.loadData("data",{ "x" : list(range(100)) } )
113
+ model.trainModel(prediction_samples = 2, lr = 0.5, num_of_epochs = 500)
114
+ model.exportPythonModel(models = "Fibonacci")
115
+ print(model({ "x" : [1] },prediction_samples = 20,num_of_samples = 20))
116
+ ```
117
+ In the example, the neural network is trained to mimic the Fibonacci series.
118
+ Finally, a native pytorch network is exported in a file.
119
+
120
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
121
+
122
+ <a name="folderstructure"></a>
123
+ ## Structure of the Repository
124
+
125
+ ```bash
126
+ nnodely/ # root directory
127
+ ├── nnodely/ # source code
128
+ │ ├── basic/ # core low-level classes
129
+ │ ├── exporter/ # model export utilities
130
+ │ ├── layers/ # supported layers
131
+ │ ├── operators/ # core operators
132
+ │ ├── support/ # utility functions
133
+ │ └── visualizer/ # visualization tools
134
+ ├── case-studies/ # main case studies
135
+ ├── docs/ # documentation
136
+ ├── tests/ # unit and integration tests
137
+ ├── imgs/ # images used in the documentation
138
+ └── mplplots/ # utilities for MatPlotLib
139
+ ```
140
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
141
+
142
+ <details>
143
+ <summary>More info about repository structure</summary>
144
+ <a name="nnodelyfolder"></a>
145
+
146
+ ### nnodely Folder
147
+ This folder contains all the nnodely library files with relative references.
148
+
149
+ The `nnodely` main class defined in __nnodely.py__, it contains all the main properties of the nnodely object and it derives from five main operators, cointained in the folder `operators/`:
150
+ 1. __composer.py__ contains all the functions to build the networks: `addModel`, `neuralizeModel`, `addConnection`, `addClosedLoop` etc..
151
+ 2. __loader.py__ contains the function for managing the dataset, the main function is `dataLoad`.
152
+ 3. __trainer.py__ contains the function for training the network as the `trainModel`.
153
+ 4. __exporter.py__ contains all the function for import and export: `saveModel`, `loadModel`, `exportONNX` etc..
154
+ 5. __validator.py__ contains all the function for validate the model and the `resultsAnalysis`.
155
+ 6. All the operators derive from `Network` defined in __network.py__, that contains the shared support functions for all the operators.
156
+
157
+ The folder `basic/` contains the main classes for the low level functionalities:
158
+ 1. __model.py__ containts the pytorch template model for the structured network.
159
+ 2. __modeldef.py__ containts the operation for work with the json model definition.
160
+ 3. __loss.py__ contains the loss functions.
161
+ 4. __optimizer.py__ contains the optimizer calss.
162
+ 6. __relation.py__ contains all the main classes from which all the layers are derived.
163
+
164
+ The other folders are:
165
+ 1. `exporter/` that contains the classes for the export functions.
166
+ 2. `support/` for the support functions.
167
+ 3. `visualizer/` that contains all the classes related to the visualization.
168
+ 4. And finally the `layers/` folder.
169
+
170
+ The `layers/` folder contains all the layers that can be used in the MSNN.
171
+ In particular, the model structured NN is defined by `Inputs`, `Outputs` and `Parameters`:
172
+ 1. __input.py__ contains the Input class used for create an input for the network.
173
+ 2. __output.py__ contains the Output class used for create an output for the network.
174
+ 3. __parameter.py__ contains the logic for create a generic parameters and constants.
175
+
176
+ The main basic layers without parameters are:
177
+ 1. __activation.py__ this file contains all the activation functions. The activation are mainly based on the pytorch functions.
178
+ 2. __arithmetic.py__ this file contains the aritmetic functions as: +, -, /, *., **.
179
+ 3. __trigonometric.py__ this file contains all the trigonometric functions.
180
+ 4. __part.py__ are used for selecting part of the data.
181
+ 5. __fuzzify.py__ contains the operation for the fuzzification of a variable,
182
+ commonly used in the local model as activation function as in [[1]](#1) with rectangular activation functions or in [[3]](#3), [[4]](#4) and [[5]](#5) with triangular activation function activation functions.
183
+ Using fuzzification it is also possible create a channel coding as presented in [[2]](#2).
184
+
185
+ The main basic layers with parameters are:
186
+ 1. __fir.py__ this file contains the finite impulse response filter function. It is a linear operation on the time dimension (second dimension).
187
+ This filter was introduced in [[1]](#1).
188
+ 2. __linear.py__ this file contains the linear function. Typical Linear operation `W*x+b` operated on the space dimension (third dimension).
189
+ This operation is presented in [[1]](#1).
190
+ 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).
191
+ 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).
192
+ 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).
193
+ 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).
194
+
195
+ <a name="casestudiesfolder"></a>
196
+ ### Case Studies Folder
197
+ In the case studies folder you can find the main case studies cited in the paper.
198
+ Each case study is a jupyter notebook that explains the main functionalities of the library.
199
+
200
+ <a name="docsfolder"></a>
201
+ ### Docs Folder
202
+ This folder contains all files used to automatically generate the documentation.
203
+
204
+ <a name="testsfolder"></a>
205
+ ### Tests Folder
206
+ This folder contains the unit tests of the library. Each file tests a specific functionality.
207
+
208
+ <a name="mplfolder"></a>
209
+ ### Matplotlib Folder
210
+ This folder contains the utilities for Matplotlib.
211
+
212
+ <a name="imgfolder"></a>
213
+ ### Images Folder
214
+ This folder contains the images used in the documentation.
215
+
216
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
217
+ </details>
218
+
219
+ <a name="contribute"></a>
220
+ ## How to Contribute
221
+
222
+ To contribute to the nnodely framework, you can:
223
+
224
+ - Open a pull request if you have a new feature or bug fix.
225
+ - Open an issue if you have a question or suggestion.
226
+
227
+ We welcome contributions and collaborations.
228
+
229
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
230
+
231
+ <a name="license"></a>
232
+ ## License
233
+ This project is released under the license [License: MIT](https://opensource.org/licenses/MIT).
234
+
235
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
236
+
237
+ <a name="references"></a>
238
+ ## References
239
+
240
+ <a id="1">[1]</a>
241
+ Mauro Da Lio, Daniele Bortoluzzi, Gastone Pietro Rosati Papini. (2019).
242
+ Modelling longitudinal vehicle dynamics with neural networks.
243
+ Vehicle System Dynamics. https://doi.org/10.1080/00423114.2019.1638947 (look the [[code]](https://github.com/tonegas/nnodely-applications/blob/main/vehicle/model_longit_vehicle_dynamics/model_longit_vehicle_dynamics.py))
244
+
245
+ <a id="2">[2]</a>
246
+ Alice Plebe, Mauro Da Lio, Daniele Bortoluzzi. (2019).
247
+ On Reliable Neural Network Sensorimotor Control in Autonomous Vehicles.
248
+ IEEE Transaction on Intelligent Transportation System. https://doi.org/10.1109/TITS.2019.2896375
249
+
250
+ <a id="3">[3]</a>
251
+ Mauro Da Lio, Riccardo Donà, Gastone Pietro Rosati Papini, Francesco Biral, Henrik Svensson. (2020).
252
+ A Mental Simulation Approach for Learning Neural-Network Predictive Control (in Self-Driving Cars).
253
+ IEEE Access. https://doi.org/10.1109/ACCESS.2020.3032780 (look the [[code]](https://github.com/tonegas/nnodely-applications/blob/main/vehicle/model_lateral_vehicle_dynamics/model_lateral_vehicle_dynamics.ipynb))
254
+
255
+ <a id="4">[4]</a>
256
+ Edoardo Pagot, Mattia Piccinini, Enrico Bertolazzi, Francesco Biral. (2023).
257
+ Fast Planning and Tracking of Complex Autonomous Parking Maneuvers With Optimal Control and Pseudo-Neural Networks.
258
+ IEEE Access. https://doi.org/10.1109/ACCESS.2023.3330431 (look the [[code]](https://github.com/tonegas/nnodely-applications/blob/main/vehicle/control_steer_car_parking/control_steer_car_parking.ipynb))
259
+
260
+ <a id="5">[5]</a>
261
+ Mattia Piccinini, Sebastiano Taddei, Matteo Larcher, Mattia Piazza, Francesco Biral. (2023).
262
+ A Physics-Driven Artificial Agent for Online Time-Optimal Vehicle Motion Planning and Control.
263
+ IEEE Access. https://doi.org/10.1109/ACCESS.2023.3274836 (look [[code basic]](https://github.com/tonegas/nnodely-applications/blob/main/vehicle/control_steer_artificial_race_driver/control_steer_artificial_race_driver.ipynb)
264
+ and [[code extended]](https://github.com/tonegas/nnodely-applications/blob/main/vehicle/control_steer_artificial_race_driver_extended/control_steer_artificial_race_driver_extended.ipynb))
265
+
266
+ <a id="6">[6]</a>
267
+ Hector Perez-Villeda, Justus Piater, Matteo Saveriano. (2023).
268
+ Learning and extrapolation of robotic skills using task-parameterized equation learner networks.
269
+ 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))
270
+
271
+ <a id="7">[7]</a>
272
+ M. Raissi. P. Perdikaris b, G.E. Karniadakis a. (2019).
273
+ Physics-informed neural networks: A deep learning framework for solving forward and inverse problems involving nonlinear partial differential equations
274
+ 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))
275
+
276
+ <a id="8">[8]</a>
277
+ Wojciech Marian Czarnecki, Simon Osindero, Max Jaderberg, Grzegorz Świrszcz, Razvan Pascanu. (2017).
278
+ Sobolev Training for Neural Networks.
279
+ arXiv. https://doi.org/10.48550/arXiv.1706.04859 (look the [[code]](https://github.com/tonegas/nnodely-applications/blob/main/sobolev/Sobolev_learning.ipynb))
280
+
281
+ <a id="9">[9]</a>
282
+ Mattia Piccinini, Matteo Zumerle, Johannes Betz, Gastone Pietro Rosati Papini. (2025).
283
+ A Road Friction-Aware Anti-Lock Braking System Based on Model-Structured Neural Networks.
284
+ IEEE Open Journal of Intelligent Transportation Systems. https://doi.org/10.1109/OJITS.2025.3563347 (look at the [[code]](https://github.com/tonegas/nnodely-applications/tree/main/vehicle/road_friction_aware_ABS))
285
+
286
+ <a id="10">[10]</a>
287
+ Mauro Da Lio, Mattia Piccinini, Francesco Biral. (2023).
288
+ Robust and Sample-Efficient Estimation of Vehicle Lateral Velocity Using Neural Networks With Explainable Structure Informed by Kinematic Principles.
289
+ IEEE Transactions on Intelligent Transportation Systems. https://doi.org/10.1109/TITS.2023.3303776
290
+
291
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
292
+ <!--
293
+ <a name="cite-us"></a>
294
+ ## Cite Us
295
+
296
+ > TODO: Possiamo aggiungere DOI di repo con zenodo e mettere la citazione di quello [guida](https://docs.github.com/en/repositories/archiving-a-github-repository/referencing-and-citing-content)
297
+ -->
@@ -0,0 +1,272 @@
1
+ <a name="readme-top"></a>
2
+ <p align="center">
3
+ <img src="https://raw.githubusercontent.com/tonegas/nnodely/main/imgs/logo_white_info.png" alt="logo" >
4
+ </p>
5
+
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
+ [![codecov](https://codecov.io/github/tonegas/nnodely/graph/badge.svg?token=8V6P2PSYT4)](https://codecov.io/github/tonegas/nnodely)
8
+ [![Documentation](https://readthedocs.org/projects/nnodely/badge/?version=main&style=default)](https://nnodely.readthedocs.io/)
9
+ [![PyPI](https://img.shields.io/pypi/v/nnodely?color=blue&label=PyPI%20Package)](https://pypi.org/project/nnodely/)
10
+
11
+ # Neural Network Framework for Modelling, Control, and Estimation of Physical Systems
12
+
13
+ Modeling, control, and estimation of physical systems are central to many engineering disciplines. While data-driven methods like neural networks offer powerful tools, they often struggle to **incorporate prior domain knowledge**, limiting their interpretability, generalizability, and safety.
14
+
15
+ To bridge this gap, we present ***nnodely*** (where "nn" can be read as "m," forming *Modely*) — a framework that facilitates the creation and deployment of **Model-Structured Neural Networks** (**MS-NNs**).
16
+ MS-NNs combine the learning capabilities of neural networks with structural **priors** grounded in **physics, control, and estimation theory**, enabling:
17
+
18
+ - **Reduced training data** requirements
19
+ - **Generalization** to unseen scenarios
20
+ - **Real-time** deployment in real-world applications
21
+
22
+ In short:
23
+
24
+ nnodely is not a replacement for a general purpose deep learning frameworks — it is a **structured layer on top of them**, purpose-built for physical systems.
25
+
26
+ <br>
27
+ <p align="center">
28
+ 📖 <a href="https://nnodely.readthedocs.io/"><b>Documentation</b></a> •
29
+ 🔬 <a href="./case-studies/"><b>Case Studies</b></a> •
30
+ 🚀 <a href="https://github.com/tonegas/nnodely-applications"><b>Other Applications</b></a>
31
+ </p>
32
+
33
+ <!-- > [!NOTE]
34
+ > **Full documentation** of the code is available at the following [link](https://nnodely.readthedocs.io/en/docs-update/)
35
+
36
+ > Some **examples of applications** of nnodely in different fields are collected in the following open-source repository: [nnodely-applications](https://github.com/tonegas/nnodely-applications) -->
37
+
38
+ <h2>Table of Contents</h2>
39
+ <ol>
40
+ <li><a href="#gettingstarted">Getting Started</a></li>
41
+ <ul>
42
+ <li><a href="#installation">Installation</a></li>
43
+ <li><a href="#helloworld">Hello, World!</a></li>
44
+ </ul>
45
+ <li><a href="#folderstructure">Structure of the Repository</a></li>
46
+ <li><a href="#contribute">How to contribute</a></li>
47
+ <li><a href="#license">License</a></li>
48
+ <li><a href="#references">References</a></li>
49
+ </ol>
50
+
51
+
52
+ <a name="gettingstarted"></a>
53
+ ## Getting Started
54
+
55
+ <a name="installation"></a>
56
+ ### Installation
57
+
58
+ You can install nnodely from PyPI via:
59
+
60
+ ```sh
61
+ pip install nnodely
62
+ ```
63
+
64
+ Alternatively, you can build it from source by first cloning the repository and installing the requirements and the nnodely library:
65
+
66
+ ```sh
67
+ git clone https://github.com/tonegas/nnodely.git
68
+ cd nnodely
69
+ pip install -r requirements.txt
70
+ pip install .
71
+ ```
72
+ <a name="helloworld"></a>
73
+ ### Hello, World!
74
+ To check if `nnodely` is installed correctly try running the following script.
75
+
76
+ ```python
77
+ from nnodely import Input, Output, nnodely, Parameter
78
+
79
+ x = Input("x")
80
+ l = x.last()
81
+ o = (Parameter('A')*l.sw([-2,-1])+Parameter('B')*l).closedLoop(x)
82
+ f = Output("fib",o)
83
+ model = nnodely()
84
+ model.addModel("Fibonacci",f)
85
+ model.addMinimize("target", l.sw([-2,-1])+l, f)
86
+ model.neuralizeModel(1)
87
+ model.loadData("data",{ "x" : list(range(100)) } )
88
+ model.trainModel(prediction_samples = 2, lr = 0.5, num_of_epochs = 500)
89
+ model.exportPythonModel(models = "Fibonacci")
90
+ print(model({ "x" : [1] },prediction_samples = 20,num_of_samples = 20))
91
+ ```
92
+ In the example, the neural network is trained to mimic the Fibonacci series.
93
+ Finally, a native pytorch network is exported in a file.
94
+
95
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
96
+
97
+ <a name="folderstructure"></a>
98
+ ## Structure of the Repository
99
+
100
+ ```bash
101
+ nnodely/ # root directory
102
+ ├── nnodely/ # source code
103
+ │ ├── basic/ # core low-level classes
104
+ │ ├── exporter/ # model export utilities
105
+ │ ├── layers/ # supported layers
106
+ │ ├── operators/ # core operators
107
+ │ ├── support/ # utility functions
108
+ │ └── visualizer/ # visualization tools
109
+ ├── case-studies/ # main case studies
110
+ ├── docs/ # documentation
111
+ ├── tests/ # unit and integration tests
112
+ ├── imgs/ # images used in the documentation
113
+ └── mplplots/ # utilities for MatPlotLib
114
+ ```
115
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
116
+
117
+ <details>
118
+ <summary>More info about repository structure</summary>
119
+ <a name="nnodelyfolder"></a>
120
+
121
+ ### nnodely Folder
122
+ This folder contains all the nnodely library files with relative references.
123
+
124
+ The `nnodely` main class defined in __nnodely.py__, it contains all the main properties of the nnodely object and it derives from five main operators, cointained in the folder `operators/`:
125
+ 1. __composer.py__ contains all the functions to build the networks: `addModel`, `neuralizeModel`, `addConnection`, `addClosedLoop` etc..
126
+ 2. __loader.py__ contains the function for managing the dataset, the main function is `dataLoad`.
127
+ 3. __trainer.py__ contains the function for training the network as the `trainModel`.
128
+ 4. __exporter.py__ contains all the function for import and export: `saveModel`, `loadModel`, `exportONNX` etc..
129
+ 5. __validator.py__ contains all the function for validate the model and the `resultsAnalysis`.
130
+ 6. All the operators derive from `Network` defined in __network.py__, that contains the shared support functions for all the operators.
131
+
132
+ The folder `basic/` contains the main classes for the low level functionalities:
133
+ 1. __model.py__ containts the pytorch template model for the structured network.
134
+ 2. __modeldef.py__ containts the operation for work with the json model definition.
135
+ 3. __loss.py__ contains the loss functions.
136
+ 4. __optimizer.py__ contains the optimizer calss.
137
+ 6. __relation.py__ contains all the main classes from which all the layers are derived.
138
+
139
+ The other folders are:
140
+ 1. `exporter/` that contains the classes for the export functions.
141
+ 2. `support/` for the support functions.
142
+ 3. `visualizer/` that contains all the classes related to the visualization.
143
+ 4. And finally the `layers/` folder.
144
+
145
+ The `layers/` folder contains all the layers that can be used in the MSNN.
146
+ In particular, the model structured NN is defined by `Inputs`, `Outputs` and `Parameters`:
147
+ 1. __input.py__ contains the Input class used for create an input for the network.
148
+ 2. __output.py__ contains the Output class used for create an output for the network.
149
+ 3. __parameter.py__ contains the logic for create a generic parameters and constants.
150
+
151
+ The main basic layers without parameters are:
152
+ 1. __activation.py__ this file contains all the activation functions. The activation are mainly based on the pytorch functions.
153
+ 2. __arithmetic.py__ this file contains the aritmetic functions as: +, -, /, *., **.
154
+ 3. __trigonometric.py__ this file contains all the trigonometric functions.
155
+ 4. __part.py__ are used for selecting part of the data.
156
+ 5. __fuzzify.py__ contains the operation for the fuzzification of a variable,
157
+ commonly used in the local model as activation function as in [[1]](#1) with rectangular activation functions or in [[3]](#3), [[4]](#4) and [[5]](#5) with triangular activation function activation functions.
158
+ Using fuzzification it is also possible create a channel coding as presented in [[2]](#2).
159
+
160
+ The main basic layers with parameters are:
161
+ 1. __fir.py__ this file contains the finite impulse response filter function. It is a linear operation on the time dimension (second dimension).
162
+ This filter was introduced in [[1]](#1).
163
+ 2. __linear.py__ this file contains the linear function. Typical Linear operation `W*x+b` operated on the space dimension (third dimension).
164
+ This operation is presented in [[1]](#1).
165
+ 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).
166
+ 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).
167
+ 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).
168
+ 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).
169
+
170
+ <a name="casestudiesfolder"></a>
171
+ ### Case Studies Folder
172
+ In the case studies folder you can find the main case studies cited in the paper.
173
+ Each case study is a jupyter notebook that explains the main functionalities of the library.
174
+
175
+ <a name="docsfolder"></a>
176
+ ### Docs Folder
177
+ This folder contains all files used to automatically generate the documentation.
178
+
179
+ <a name="testsfolder"></a>
180
+ ### Tests Folder
181
+ This folder contains the unit tests of the library. Each file tests a specific functionality.
182
+
183
+ <a name="mplfolder"></a>
184
+ ### Matplotlib Folder
185
+ This folder contains the utilities for Matplotlib.
186
+
187
+ <a name="imgfolder"></a>
188
+ ### Images Folder
189
+ This folder contains the images used in the documentation.
190
+
191
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
192
+ </details>
193
+
194
+ <a name="contribute"></a>
195
+ ## How to Contribute
196
+
197
+ To contribute to the nnodely framework, you can:
198
+
199
+ - Open a pull request if you have a new feature or bug fix.
200
+ - Open an issue if you have a question or suggestion.
201
+
202
+ We welcome contributions and collaborations.
203
+
204
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
205
+
206
+ <a name="license"></a>
207
+ ## License
208
+ This project is released under the license [License: MIT](https://opensource.org/licenses/MIT).
209
+
210
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
211
+
212
+ <a name="references"></a>
213
+ ## References
214
+
215
+ <a id="1">[1]</a>
216
+ Mauro Da Lio, Daniele Bortoluzzi, Gastone Pietro Rosati Papini. (2019).
217
+ Modelling longitudinal vehicle dynamics with neural networks.
218
+ Vehicle System Dynamics. https://doi.org/10.1080/00423114.2019.1638947 (look the [[code]](https://github.com/tonegas/nnodely-applications/blob/main/vehicle/model_longit_vehicle_dynamics/model_longit_vehicle_dynamics.py))
219
+
220
+ <a id="2">[2]</a>
221
+ Alice Plebe, Mauro Da Lio, Daniele Bortoluzzi. (2019).
222
+ On Reliable Neural Network Sensorimotor Control in Autonomous Vehicles.
223
+ IEEE Transaction on Intelligent Transportation System. https://doi.org/10.1109/TITS.2019.2896375
224
+
225
+ <a id="3">[3]</a>
226
+ Mauro Da Lio, Riccardo Donà, Gastone Pietro Rosati Papini, Francesco Biral, Henrik Svensson. (2020).
227
+ A Mental Simulation Approach for Learning Neural-Network Predictive Control (in Self-Driving Cars).
228
+ IEEE Access. https://doi.org/10.1109/ACCESS.2020.3032780 (look the [[code]](https://github.com/tonegas/nnodely-applications/blob/main/vehicle/model_lateral_vehicle_dynamics/model_lateral_vehicle_dynamics.ipynb))
229
+
230
+ <a id="4">[4]</a>
231
+ Edoardo Pagot, Mattia Piccinini, Enrico Bertolazzi, Francesco Biral. (2023).
232
+ Fast Planning and Tracking of Complex Autonomous Parking Maneuvers With Optimal Control and Pseudo-Neural Networks.
233
+ IEEE Access. https://doi.org/10.1109/ACCESS.2023.3330431 (look the [[code]](https://github.com/tonegas/nnodely-applications/blob/main/vehicle/control_steer_car_parking/control_steer_car_parking.ipynb))
234
+
235
+ <a id="5">[5]</a>
236
+ Mattia Piccinini, Sebastiano Taddei, Matteo Larcher, Mattia Piazza, Francesco Biral. (2023).
237
+ A Physics-Driven Artificial Agent for Online Time-Optimal Vehicle Motion Planning and Control.
238
+ IEEE Access. https://doi.org/10.1109/ACCESS.2023.3274836 (look [[code basic]](https://github.com/tonegas/nnodely-applications/blob/main/vehicle/control_steer_artificial_race_driver/control_steer_artificial_race_driver.ipynb)
239
+ and [[code extended]](https://github.com/tonegas/nnodely-applications/blob/main/vehicle/control_steer_artificial_race_driver_extended/control_steer_artificial_race_driver_extended.ipynb))
240
+
241
+ <a id="6">[6]</a>
242
+ Hector Perez-Villeda, Justus Piater, Matteo Saveriano. (2023).
243
+ Learning and extrapolation of robotic skills using task-parameterized equation learner networks.
244
+ 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))
245
+
246
+ <a id="7">[7]</a>
247
+ M. Raissi. P. Perdikaris b, G.E. Karniadakis a. (2019).
248
+ Physics-informed neural networks: A deep learning framework for solving forward and inverse problems involving nonlinear partial differential equations
249
+ 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))
250
+
251
+ <a id="8">[8]</a>
252
+ Wojciech Marian Czarnecki, Simon Osindero, Max Jaderberg, Grzegorz Świrszcz, Razvan Pascanu. (2017).
253
+ Sobolev Training for Neural Networks.
254
+ arXiv. https://doi.org/10.48550/arXiv.1706.04859 (look the [[code]](https://github.com/tonegas/nnodely-applications/blob/main/sobolev/Sobolev_learning.ipynb))
255
+
256
+ <a id="9">[9]</a>
257
+ Mattia Piccinini, Matteo Zumerle, Johannes Betz, Gastone Pietro Rosati Papini. (2025).
258
+ A Road Friction-Aware Anti-Lock Braking System Based on Model-Structured Neural Networks.
259
+ IEEE Open Journal of Intelligent Transportation Systems. https://doi.org/10.1109/OJITS.2025.3563347 (look at the [[code]](https://github.com/tonegas/nnodely-applications/tree/main/vehicle/road_friction_aware_ABS))
260
+
261
+ <a id="10">[10]</a>
262
+ Mauro Da Lio, Mattia Piccinini, Francesco Biral. (2023).
263
+ Robust and Sample-Efficient Estimation of Vehicle Lateral Velocity Using Neural Networks With Explainable Structure Informed by Kinematic Principles.
264
+ IEEE Transactions on Intelligent Transportation Systems. https://doi.org/10.1109/TITS.2023.3303776
265
+
266
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
267
+ <!--
268
+ <a name="cite-us"></a>
269
+ ## Cite Us
270
+
271
+ > TODO: Possiamo aggiungere DOI di repo con zenodo e mettere la citazione di quello [guida](https://docs.github.com/en/repositories/archiving-a-github-repository/referencing-and-citing-content)
272
+ -->
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.11.6,<0.12.0"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "nnodely"
7
+ version = "1.5.5.dev1"
8
+ description = "Model-structured neural network framework for the modeling and control of physical systems"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10,<3.14"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [
14
+ { name = "Gastone Pietro Rosati Papini", email = "tonegas@gmail.com" },
15
+ ]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Operating System :: OS Independent",
19
+ ]
20
+ dependencies = [
21
+ "numpy == 1.26.4; platform_machine == 'x86_64' and python_version == '3.10'",
22
+ "torch == 2.2.2; platform_machine == 'x86_64' and python_version == '3.10'",
23
+ "torch == 2.6.0; platform_machine != 'x86_64' or python_version != '3.10'",
24
+ "numpy",
25
+ "onnx",
26
+ "pandas",
27
+ "reportlab",
28
+ "matplotlib",
29
+ "onnxruntime",
30
+ "graphviz",
31
+ ]
32
+
33
+ [project.urls]
34
+ "Homepage" = "https://github.com/tonegas/nnodely"
35
+ "Repository" = "https://github.com/tonegas/nnodely"
36
+
37
+ [dependency-groups]
38
+ dev = ["pre-commit>=4.5.1", "pytest-cov>=7.1.0", "ruff>=0.15.10"]
39
+
40
+ [[tool.uv.index]]
41
+ name = "testpypi"
42
+ url = "https://test.pypi.org/simple/"
43
+ publish-url = "https://test.pypi.org/legacy/"
44
+ explicit = true