Out-of-the-box framework for Echo State Networks
Project description
esnpy
esnpy
is an out-of-the-box framework to experiment around ESN and DeepESN.
Models have been implemented in pure NumPy/SciPy, so there is no need for a powerful GPU, or any esoteric requirements.
Right now, the focus is on batch training, and feedback loops have not been taken into account.
But feel free to open a ticket a discuss about anything you need, features you want, or even help !
Note from the author: esnpy
is a small projet I initiated during my master intership, and have recently cleaned up. I might keep working on it for fun, but If you want/need a more robust framework, ReservoirPy might be the own you need ;)
Getting Started
Installation
From PyPI
pip install esnpy
From source
pip install git+https://github.com/NiziL/esnpy#egg=esnpy
Use github.com/NiziL/esnpy@<tag or branch>#egg=esnpy
to install from a specific branch or tag instead of main.
Quickstart
import esnpy
config = createConfig()
trainer = createTrainer()
warmup, data, target = loadData()
# create the echo state network
esn = esnpy.ESN(config, trainer)
# train it
esn.fit(warmup, data, target)
# test it
predictions = esnpy.transform(data)
print(f"error: {compute_err(target, predictions)}")
ESN
and DeepESN
You can create your ESN with esnpy.ESN
.
The constructor needs a esnpy.ReservoirConfig
and an implementation of esnpy.train.Trainer
.
esnpy.DeepESN
doesn't differ a lot, it just expect a list of ReservoirConfig
and have an optional parameters mask
to specify from which reservoirs the Trainer
should learn. The size of mask
and configs
must be the same.
Then, simply call fit
function by passing some warm up and training data with the related targets.
Once trained, run predictions using transform
.
ReservoirConfig
Parameters | Type | Info |
---|---|---|
input_size | int |
Size of input vectors |
size | int |
Number of units in the reservoir |
leaky | float |
Leaky parameter of the reservoir |
fn | Callable |
Activation function of the reservoir |
input_bias | bool |
Enable the usage of a bias in the input |
input_init | esnpy.init.Initializer |
Define how to initialize the input weights |
input_tuners | list[esnpy.tune.Tuner] |
Define how to tune the input weights |
intern_init | esnpy.init.Initializer |
Define how to intialize the internal weights |
intern_tuners | list[esnpy.init.Tuner] |
Define how to tune the internal weights |
Initializer
and Tuner
esnpy.init.Initializer
and esnpy.tune.Tuner
are the abstract base classes used to setup the input and internal weights of a reservoir.
Initializer
is defined by a init() -> Matrix
function.
esnpy
provides implementations of initializer for both uniform and gaussian distribution of weights, and for both dense and sparse matrix.
Tuner
is defined by a init(matrix : Matrix) -> Matrix
function, which can be used to modify the weights after initialization.
For example, esnpy
provides a SpectralRadiusTuner
to change the spectral radius of a weights matrix.
Trainer
esnpy.train.Trainer
is responsible to create the output weights matrix from the training data and targets.
It is defined by a train(inputs: Matrix, data: Matrix, target: Matrix) -> Matrix
function.
esnpy
provides a RidgeTrainer
to compute the output weights using a ridge regression.
This trainer has three parameters : one float, the regularization parameter's weight alpha
, and two optionals boolean (default to true) use_bias
and use_input
to control if we should use a bias and the input to compute the readout weights.
Code Examples
Want to see some code in action ? Take a look at the examples/
directory:
MackeyGlass/
demonstrates how to learn to predict a time seriesTrajectoryClassification/
demonstrates how to learn to classify 2D trajectories
Tips & Tricks
- Sparse matrices are usually way faster than dense matrix
- Use
numpy.random.seed(seed)
before creating an ESN if you want to compare two indentical reservoir.
Bibliography
Based on:
- The "echo state" approach to analysing and training recurrent neural networks by Herbert Jaeger (pdf),
- A pratical guide to applying Echo State Networks by Mantas Lukoševičius (pdf),
- Design of deep echo state networks by Claudio Gallicchio and al (link),
- Deep echo state network (DeepESN): A brief survey by Claudio Gallicchio and Alessio Micheli (pdf).
Special thanks to Mantas Lukoševičius for his minimal ESN example, which greatly helped me to get started with reservoir computing.
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
Built Distribution
File details
Details for the file esnpy-0.2.1.tar.gz
.
File metadata
- Download URL: esnpy-0.2.1.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de93c4fac28e282dd050a0213a22c0c215f501e147494fb4ca3341cfc3de7cec |
|
MD5 | 743004fe4a0ee872af3f1870a840c907 |
|
BLAKE2b-256 | adb0659d07ee539d3696665f30a217eca68180e17ebe6d697b4b2f17b68e439e |
File details
Details for the file esnpy-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: esnpy-0.2.1-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d72f239491dbcb742f9de59a054748f8446d7bd702ced0a29bf8f2e5bbfbf87 |
|
MD5 | 9a445b60901868c566d62cffce98b624 |
|
BLAKE2b-256 | c5ad7afed8bb7ea3ab96456e96af1f7c72bc0490144482c06138452ce50666a4 |