# 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)
```
---
## 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/9e/4a/d426fd21469739f31c0055aaddb8a2a5e42e32e0f2259d90289c3eeb289d/csnn-1.0.3.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## 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.3",
"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": "",
"digests": {
"blake2b_256": "c9046451303127753bbe627cc85848e5967fdcd3cf792f18921616545260e81b",
"md5": "bc8896418a79b7ab42dfbff798ff85f4",
"sha256": "1bb5d0bcc0b168648c47ab42a7f5f805e8c574374f6eb4c3d774db6fcd03d25e"
},
"downloads": -1,
"filename": "csnn-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bc8896418a79b7ab42dfbff798ff85f4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 24987,
"upload_time": "2024-10-25T14:48:17",
"upload_time_iso_8601": "2024-10-25T14:48:17.197460Z",
"url": "https://files.pythonhosted.org/packages/c9/04/6451303127753bbe627cc85848e5967fdcd3cf792f18921616545260e81b/csnn-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9e4ad426fd21469739f31c0055aaddb8a2a5e42e32e0f2259d90289c3eeb289d",
"md5": "e8750894d6a20d0e0a086ddd55438b1e",
"sha256": "dc84b2e0e0440b87adee76d2061ab37f95299b593fb2494d99ec43e393eae515"
},
"downloads": -1,
"filename": "csnn-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "e8750894d6a20d0e0a086ddd55438b1e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 26551,
"upload_time": "2024-10-25T14:48:18",
"upload_time_iso_8601": "2024-10-25T14:48:18.358931Z",
"url": "https://files.pythonhosted.org/packages/9e/4a/d426fd21469739f31c0055aaddb8a2a5e42e32e0f2259d90289c3eeb289d/csnn-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-25 14:48:18",
"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": [],
"lcname": "csnn"
}