Neural Networks with CasADi
Project description
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)
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.