Skip to main content

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.

PyPI version Source Code License Python 3.9

Tests Downloads Maintainability Test Coverage Code style: black


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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csnn-1.0.4.post1.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

csnn-1.0.4.post1-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file csnn-1.0.4.post1.tar.gz.

File metadata

  • Download URL: csnn-1.0.4.post1.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for csnn-1.0.4.post1.tar.gz
Algorithm Hash digest
SHA256 9d8bbb42d9e0477348dd9b622db1787c9da4a9d6dad949be9a73dd99371f19b9
MD5 801182b7e8c8ecbf705979ab42bf0110
BLAKE2b-256 e030078278957c45b1bebd4cca8b6dbb888790ca07328be45c889e5cfbdd04cf

See more details on using hashes here.

File details

Details for the file csnn-1.0.4.post1-py3-none-any.whl.

File metadata

  • Download URL: csnn-1.0.4.post1-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for csnn-1.0.4.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 dfaf154e5a9dd925ba32a225b3e276878818853ad8e5a895e41b975948f84989
MD5 a2bc60bca6b90c80f69871b8ca178793
BLAKE2b-256 a0f55d05c57eaae52543b1a378d694ad31cba080ce755b7f53c39add611631e9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page