Neural Networks with CasADi
csnn is a package for creating symbolic neural networks in CasADi in a PyTorch-like API style.
Introduction
The package allows the creation of neural networks with the symbolic language offered by CasADi. This is done in a similar way to PyTorch. For example, the following code allows us to create an MLP with a hidden layer:
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
pip install csnn
csnn has the following dependencies
For playing around with the source code instead, run
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, PhD Candidate [f.airaldi@tudelft.nl | filippoairaldi@gmail.com]
Delft Center for Systems and Control in Delft University of Technology
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.
Metadata
Release files for csnn 1.0.6.post3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| csnn-1.0.6.post3.tar.gz | 23.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| csnn-1.0.6.post3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 47.6 kB
Release files / csnn-1.0.6.post3.tar.gz
| Download URL | csnn-1.0.6.post3.tar.gz |
|---|---|
| Size | 23.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9ae150dd0f5608f1d0b007176bfe700399b7b0572b0853bcabf076d6162d0186
|
|
BLAKE2b-256 checksum How to use checksums |
383c1ff77896fff5ed097351d1cc5a5bd03da8f33f8e9d33e9fc2986f7199fc8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.16
|
Release files / csnn-1.0.6.post3-py3-none-any.whl
| Download URL | csnn-1.0.6.post3-py3-none-any.whl |
|---|---|
| Size | 23.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7851de5fc904c715f468efe4c035b3bf1f9cb2e6e8e4adef0f19886e840a3ed7
|
|
BLAKE2b-256 checksum How to use checksums |
42c8518f64dec5c822085289165bafc88aea764c168006081d4d5c2b8870c129
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.16
|