# Neural Networks with CasADi
**csnn** is a package for creating symbolic neural networks in [CasADi](https://web.casadi.org) in a [PyTorch](https://pytorch.org/)-like API style.
[](https://badge.fury.io/py/csnn)
[](https://github.com/FilippoAiraldi/casadi-neural-nets/blob/master/LICENSE)

[](https://github.com/FilippoAiraldi/casadi-neural-nets/actions/workflows/ci.yml)
[](https://www.pepy.tech/projects/csnn)
[](https://codeclimate.com/github/FilippoAiraldi/casadi-neural-nets/maintainability)
[](https://codeclimate.com/github/FilippoAiraldi/casadi-neural-nets/test_coverage)
[](https://github.com/psf/black)
---
## Introduction
The package allows the creation of neural networks with the symbolic language offered by [CasADi](https://web.casadi.org). This is done in a similar way to [PyTorch](https://pytorch.org/). For example, the following code allows us to create an MLP with a hidden layer:
```python
import casadi as cs
from csnn import set_sym_type, Linear, Sequential, ReLU
set_sym_type("SX") # can set either MX or SX
net = Sequential[cs.SX]((
Linear(4, 32),
ReLU(),
Linear(32, 1),
ReLU()
))
batch = 2
input = cs.SX.sym("in", batch, 4)
output = net(input)
assert output.shape == (batch, 1)
```
---
## Implemented Modules
So far, the following modules that are available in PyTorch have been implemented:
- Containers
* Module
* Sequential
- Activation functions
* GELU
* SELU
* LeakyReLU
* ReLU
* Sigmoid
* Softplus
* Tanh
- Linear layers
* Linear
- Recurrent layers
* RNNCell
* RNN
- Dropout layers
* Dropout
* Dropout1d
Additionally, the library provides the implementation for the following convex neural networks (see `csnn.convex`):
- FicNN
- PwqNN
- PsdNN
---
## Installation
To install the package, run
```bash
pip install csnn
```
**csnn** has the following dependencies
- [CasADi](https://web.casadi.org)
For playing around with the source code instead, run
```bash
git clone https://github.com/FilippoAiraldi/casadi-neural-nets.git
```
---
## License
The repository is provided under the MIT License. See the LICENSE file included with this repository.
---
## Author
[Filippo Airaldi](https://www.tudelft.nl/staff/f.airaldi/), PhD Candidate [f.airaldi@tudelft.nl | filippoairaldi@gmail.com]
> [Delft Center for Systems and Control](https://www.tudelft.nl/en/3me/about/departments/delft-center-for-systems-and-control/) in [Delft University of Technology](https://www.tudelft.nl/en/)
Copyright (c) 2023 Filippo Airaldi.
Copyright notice: Technische Universiteit Delft hereby disclaims all copyright interest in the program “csnn” (Nueral Networks with CasADi) written by the Author(s). Prof. Dr. Ir. Fred van Keulen, Dean of 3mE.
Raw data
{
"_id": null,
"home_page": null,
"name": "csnn",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "casadi, nonlinear-optimization, neural-networks",
"author": null,
"author_email": "Filippo Airaldi <filippoairaldi@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/fc/bd/5b513c463659aea6ae3af46fdbe030e537b0ee54e9096a877b92063d9ec7/csnn-1.0.6.tar.gz",
"platform": null,
"description": "# Neural Networks with CasADi\r\n\r\n**csnn** is a package for creating symbolic neural networks in [CasADi](https://web.casadi.org) in a [PyTorch](https://pytorch.org/)-like API style.\r\n\r\n[](https://badge.fury.io/py/csnn)\r\n[](https://github.com/FilippoAiraldi/casadi-neural-nets/blob/master/LICENSE)\r\n\r\n\r\n[](https://github.com/FilippoAiraldi/casadi-neural-nets/actions/workflows/ci.yml)\r\n[](https://www.pepy.tech/projects/csnn)\r\n[](https://codeclimate.com/github/FilippoAiraldi/casadi-neural-nets/maintainability)\r\n[](https://codeclimate.com/github/FilippoAiraldi/casadi-neural-nets/test_coverage)\r\n[](https://github.com/psf/black)\r\n\r\n---\r\n\r\n## Introduction\r\n\r\nThe package allows the creation of neural networks with the symbolic language offered by [CasADi](https://web.casadi.org). This is done in a similar way to [PyTorch](https://pytorch.org/). For example, the following code allows us to create an MLP with a hidden layer:\r\n\r\n```python\r\nimport casadi as cs\r\nfrom csnn import set_sym_type, Linear, Sequential, ReLU\r\n\r\nset_sym_type(\"SX\") # can set either MX or SX\r\n\r\nnet = Sequential[cs.SX]((\r\n Linear(4, 32),\r\n ReLU(),\r\n Linear(32, 1),\r\n ReLU()\r\n))\r\n\r\nbatch = 2\r\ninput = cs.SX.sym(\"in\", batch, 4)\r\noutput = net(input)\r\nassert output.shape == (batch, 1)\r\n```\r\n\r\n---\r\n\r\n## Implemented Modules\r\n\r\nSo far, the following modules that are available in PyTorch have been implemented:\r\n\r\n- Containers\r\n * Module\r\n * Sequential\r\n- Activation functions\r\n * GELU\r\n * SELU\r\n * LeakyReLU\r\n * ReLU\r\n * Sigmoid\r\n * Softplus\r\n * Tanh\r\n- Linear layers\r\n * Linear\r\n- Recurrent layers\r\n * RNNCell\r\n * RNN\r\n- Dropout layers\r\n * Dropout\r\n * Dropout1d\r\n\r\nAdditionally, the library provides the implementation for the following convex neural networks (see `csnn.convex`):\r\n\r\n- FicNN\r\n- PwqNN\r\n- PsdNN\r\n\r\n---\r\n\r\n## Installation\r\n\r\nTo install the package, run\r\n\r\n```bash\r\npip install csnn\r\n```\r\n\r\n**csnn** has the following dependencies\r\n\r\n- [CasADi](https://web.casadi.org)\r\n\r\nFor playing around with the source code instead, run\r\n\r\n```bash\r\ngit clone https://github.com/FilippoAiraldi/casadi-neural-nets.git\r\n```\r\n\r\n---\r\n\r\n## License\r\n\r\nThe repository is provided under the MIT License. See the LICENSE file included with this repository.\r\n\r\n---\r\n\r\n## Author\r\n\r\n[Filippo Airaldi](https://www.tudelft.nl/staff/f.airaldi/), PhD Candidate [f.airaldi@tudelft.nl | filippoairaldi@gmail.com]\r\n\r\n> [Delft Center for Systems and Control](https://www.tudelft.nl/en/3me/about/departments/delft-center-for-systems-and-control/) in [Delft University of Technology](https://www.tudelft.nl/en/)\r\n\r\nCopyright (c) 2023 Filippo Airaldi.\r\n\r\nCopyright notice: Technische Universiteit Delft hereby disclaims all copyright interest in the program \u201ccsnn\u201d (Nueral Networks with CasADi) written by the Author(s). Prof. Dr. Ir. Fred van Keulen, Dean of 3mE.\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Neural Networks with CasADi",
"version": "1.0.6",
"project_urls": {
"Bug Tracker": "https://github.com/FilippoAiraldi/casadi-neural-nets/issues",
"Homepage": "https://github.com/FilippoAiraldi/casadi-neural-nets"
},
"split_keywords": [
"casadi",
" nonlinear-optimization",
" neural-networks"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "b5f3cb99e12540a7a0f6ce255a123ea715da5294a6b2278f648da50f05412947",
"md5": "0f66e7f2ba492b3d7b3485679af02832",
"sha256": "2b21046e7538545d3fc78958a5df60639c2751962b22e5035862b58bfbe99e07"
},
"downloads": -1,
"filename": "csnn-1.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0f66e7f2ba492b3d7b3485679af02832",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 23657,
"upload_time": "2025-02-17T11:56:31",
"upload_time_iso_8601": "2025-02-17T11:56:31.875443Z",
"url": "https://files.pythonhosted.org/packages/b5/f3/cb99e12540a7a0f6ce255a123ea715da5294a6b2278f648da50f05412947/csnn-1.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "fcbd5b513c463659aea6ae3af46fdbe030e537b0ee54e9096a877b92063d9ec7",
"md5": "5b417c0a6d1fc0e6fda24a7e06c9a351",
"sha256": "6d1a32cfe9d7682d2891e0a7185f1f8d1cce78fc99d12866df47406f7fa733ec"
},
"downloads": -1,
"filename": "csnn-1.0.6.tar.gz",
"has_sig": false,
"md5_digest": "5b417c0a6d1fc0e6fda24a7e06c9a351",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 23523,
"upload_time": "2025-02-17T11:56:33",
"upload_time_iso_8601": "2025-02-17T11:56:33.150317Z",
"url": "https://files.pythonhosted.org/packages/fc/bd/5b513c463659aea6ae3af46fdbe030e537b0ee54e9096a877b92063d9ec7/csnn-1.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-17 11:56:33",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "FilippoAiraldi",
"github_project": "casadi-neural-nets",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "numpy",
"specs": [
[
">=",
"1.24.2"
]
]
},
{
"name": "casadi",
"specs": [
[
">=",
"3.6.3"
]
]
},
{
"name": "typing_extensions",
"specs": [
[
">=",
"4.6.0"
]
]
}
],
"lcname": "csnn"
}