Giter VIP home page Giter VIP logo

reservoirpy / reservoirpy Goto Github PK

View Code? Open in Web Editor NEW
370.0 16.0 92.0 108.55 MB

A simple and flexible code for Reservoir Computing architectures like Echo State Networks

License: MIT License

Python 100.00%
esn reservoir echo-state-networks timeseries timeseries-prediction python reservoir-computing timeseries-forecasting machine-learning machine-learning-algorithms recurrent-neural-networks neural-network artificial-intelligence timeseries-analysis

reservoirpy's Introduction


PyPI - Python Version PyPI version Documentation Status Testing codecov PyPI - Downloads

ReservoirPy (v0.3.11) πŸŒ€πŸ§ 

Simple and flexible code for Reservoir Computing architectures like Echo State Networks (ESN).

Binder

from reservoirpy.nodes import Reservoir, Ridge, Input

data = Input(input_dim=1)
reservoir = Reservoir(100, lr=0.3, sr=1.1)
readout = Ridge(ridge=1e-6)

esn = data >> reservoir >> readout

forecast = esn.fit(X, y).run(timeseries)

ReservoirPy is a simple user-friendly library based on Python scientific modules. It provides a flexible interface to implement efficient Reservoir Computing (RC) architectures with a particular focus on Echo State Networks (ESN). Advanced features of ReservoirPy allow to improve computation time efficiency on a simple laptop compared to basic Python implementation, with datasets of any size.

Some of its features are: offline and online training, parallel implementation, sparse matrix computation, fast spectral initialization, advanced learning rules (e.g. Intrinsic Plasticity) etc. It also makes possible to easily create complex architectures with multiple reservoirs (e.g. deep reservoirs), readouts, and complex feedback loops. Moreover, graphical tools are included to easily explore hyperparameters with the help of the hyperopt library. Finally, it includes several tutorials exploring exotic architectures and examples of scientific papers reproduction.

This library works for Python 3.8 and higher.

Follow @reservoirpy updates and new releases on Twitter.

Official documentation πŸ“–

See the official ReservoirPy's documentation to learn more about the main features of ReservoirPy, its API and the installation process. Or you can access directly the User Guide with tutorials.

Quick example of how to code a deep reservoir

Image

Installation

pip install reservoirpy

(See below for more advanced installation options)

Quick try ⚑

An example on Chaotic timeseries prediction (MackeyGlass)

Step 1: Load the dataset

ReservoirPy comes with some handy data generator able to create synthetic timeseries for well-known tasks such as Mackey-Glass timeseries forecasting.

from reservoirpy.datasets import mackey_glass

X = mackey_glass(n_timesteps=2000)

Step 2: Create an Echo State Network...

...or any kind of model you wish to use to solve your task. In this simple use case, we will try out Echo State Networks (ESNs), one of the most minimal architecture of Reservoir Computing machines.

An ESN is made of a reservoir, a random recurrent network used to encode our inputs in a high-dimensional (non-linear) space, and a readout, a simple feed-forward layer of neurons in charge with reading-out the desired output from the activations of the reservoir.

from reservoirpy.nodes import Reservoir, Ridge

reservoir = Reservoir(units=100, lr=0.3, sr=1.25)
readout = Ridge(output_dim=1, ridge=1e-5)

We here obtain a reservoir with 100 neurons, a spectral radius of 1.25 and a leak rate of 0.3 (you can learn more about these hyperparameters going through the tutorial Understand and optimize hyperparameters). Here, our readout layer is just a single unit, that we will receive connections from (all units of) the reservoir. Note that only the readout layer connections are trained. This is one of the cornerstone of all Reservoir Computing techniques. In our case, we will train these connections using linear regression, with a regularization coefficient of 10-5.

Now, let's connect everything using the >> operator.

esn = reservoir >> readout

That's it! Next step: fit the readout weights to perform the task we want. We will train the ESN to make one-step-ahead forecasts of our timeseries.

Step 3: Fit and run the ESN

We train our ESN on the first 500 timesteps of the timeseries, with 100 steps used to warm up the reservoir states.

esn.fit(X[:500], X[1:501], warmup=100)

Our ESN is now trained and ready to use. Let's run it on the remainder of the timeseries:

predictions = esn.run(X[501:-1])

As a shortcut, both operations can be performed in just one line!

predictions = esn.fit(X[:500], X[1:501]).run(X[501:-1])

Let's now evaluate its performances.

Step 4: Evaluate the ESN

from reservoirpy.observables import rmse, rsquare

print("RMSE:", rmse(X[502:], predictions), "R^2 score:", rsquare(X[502:], predictions))

Run and analyse this simple file (in the "tutorials/Simple Examples with Mackey-Glass" folder) to see a complete example of timeseries prediction with ESNs:

  • simple_example_MackeyGlass.py (using the ESN class)

    python simple_example_MackeyGlass.py

If you have some issues testing some examples, have a look at the extended packages requirements in ReadTheDocs.

More installation options

To install it, use one of the following commands:

pip install reservoirpy

or

pip install reservoirpy==0.3.11

If you want to run the Python Notebooks of the tutorials folder, install the packages in requirements file (warning: this may downgrade the version of hyperopt installed):

pip install -r tutorials/requirements.txt

If you want to use the previous version 0.2.4, you can install ReservoirPy using:

pip install reservoirpy==0.2.4

If you want to enable the hyper package and its hyperparameter optimization helpers using hyperopt, use:

pip install reservoirpy[hyper]

More examples and tutorials πŸŽ“

Go to the tutorial folder for tutorials in Jupyter Notebooks.

Go to the examples folder for examples and papers with codes, also in Jupyter Notebooks.

Paper with tutorials

Tutorial for ReservoirPy (v0.2) can be found in this Paper (Trouvain et al. 2020).

Explore Hyper-Parameters with Hyperopt

A quick tutorial on how to explore hyperparameters with ReservoirPy and Hyperopt can be found in this paper (Trouvain et al. 2020).

Take a look at our advices and our method to explore hyperparameters for reservoirs in our recent paper: (Hinaut et al 2021) HTML HAL

Tutorial and Jupyter Notebook for hyper-parameter exploration

More info on hyperopt: Official website

Papers and projects using ReservoirPy

If you want your paper to appear here, please contact us (see contact link below).

  • Leger et al. (2024) Evolving Reservoirs for Meta Reinforcement Learning. EvoAPPS 2024 HAL PDF Code
  • Chaix-Eichel et al. (2022) From implicit learning to explicit representations. arXiv preprint arXiv:2204.02484. arXiv PDF
  • Trouvain & Hinaut (2021) Canary Song Decoder: Transduction and Implicit Segmentation with ESNs and LTSMs. ICANN 2021 HTML HAL PDF
  • Pagliarini et al. (2021) Canary Vocal Sensorimotor Model with RNN Decoder and Low-dimensional GAN Generator. ICDL 2021. HTML
  • Pagliarini et al. (2021) What does the Canary Say? Low-Dimensional GAN Applied to Birdsong. HAL preprint. HAL PDF
  • Which Hype for My New Task? Hints and Random Search for Echo State Networks Hyperparameters. ICANN 2021 HTML HAL PDF

Contact

If you have a question regarding the library, please open an Issue. If you have more general question or feedback you can contact us on twitter or by email to xavier dot hinaut the-famous-home-symbol inria dot fr.

Citing ReservoirPy

Trouvain, N., Pedrelli, L., Dinh, T. T., Hinaut, X. (2020) Reservoirpy: an efficient and user-friendly library to design echo state networks. In International Conference on Artificial Neural Networks (pp. 494-505). Springer, Cham. HTML HAL PDF

If you're using ReservoirPy in your work, please cite our package using the following bibtex entry:


@incollection{Trouvain2020,
  doi = {10.1007/978-3-030-61616-8_40},
  url = {https://doi.org/10.1007/978-3-030-61616-8_40},
  year = {2020},
  publisher = {Springer International Publishing},
  pages = {494--505},
  author = {Nathan Trouvain and Luca Pedrelli and Thanh Trung Dinh and Xavier Hinaut},
  title = {{ReservoirPy}: An Efficient and User-Friendly Library to Design Echo State Networks},
  booktitle = {Artificial Neural Networks and Machine Learning {\textendash} {ICANN} 2020}
}

This package is developed and supported by Inria at Bordeaux, France in Mnemosyne group. Inria is a French Research Institute in Digital Sciences (Computer Science, Mathematics, Robotics, ...).

reservoirpy's People

Contributors

ajuvenn avatar alarths avatar corentinlger avatar deepayan137 avatar dependabot[bot] avatar dtrocellier avatar hugochateaulaurent avatar jodemaey avatar jokfun avatar lucapedrelli avatar matheushjs avatar neuronalx avatar ntrouvain avatar paul-bernard avatar trungdinht avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reservoirpy's Issues

How can I use wash_nr_time_step correctly in generative task?

Hello. I want to use this library to compare my from scratch code's results but when I try to use your washout parameter, I come across with this error. I know the reason behind this error but could not find the solution without changing the actual source code. Am I missing something about this repo?

Thank you for this wonderful repo.

image

OverflowError: Python int too large to convert to C long

There's a slight problem with setting rc_connectivity to low values. It works with 0.1 but nothing lower....I only tested 0.01 and 0.001. It comes up with this error....

File "reservoirpy3.py", line 1072, in
res = eval_funk(ind)
File "reservoirpy3.py", line 586, in eval_funk
deep_esn.fit(X, y)
File "/home/chaos/.local/lib/python3.8/site-packages/reservoirpy/base/model.py", line 596, in fit
next_X += [_partial_fit_fn(x_seq=x_seq, y_seq=y_seq)]
File "/home/chaos/.local/lib/python3.8/site-packages/reservoirpy/base/model.py", line 39, in _run_and_partial_fit
states = model.run(x_seq, y_seq,
File "/home/chaos/.local/lib/python3.8/site-packages/reservoirpy/base/model.py", line 479, in run
state = self._call(x, return_states=return_states)
File "/home/chaos/.local/lib/python3.8/site-packages/reservoirpy/base/model.py", line 260, in _call
self._forward(self, x)
File "/home/chaos/.local/lib/python3.8/site-packages/reservoirpy/base/model.py", line 88, in forward
node(data[node].x)
File "/home/chaos/.local/lib/python3.8/site-packages/reservoirpy/base/types.py", line 67, in call
return self.call(*args, **kwargs)
File "/home/chaos/.local/lib/python3.8/site-packages/reservoirpy/base/node.py", line 915, in call
state = self._call(x, from_state, stateful, reset)
File "/home/chaos/.local/lib/python3.8/site-packages/reservoirpy/base/node.py", line 365, in _call
state = self._forward(self, x)
File "/home/chaos/.local/lib/python3.8/site-packages/reservoirpy/nodes/reservoir.py", line 58, in forward_internal
+ lr * f(_reservoir_kernel(reservoir, u, r))
File "/home/chaos/.local/lib/python3.8/site-packages/reservoirpy/activationsfunc.py", line 18, in vect_wrapper
v = vect(u)
File "/home/chaos/.local/lib/python3.8/site-packages/numpy/lib/function_base.py", line 2163, in call
return self._vectorize_call(func=func, args=vargs)
File "/home/chaos/.local/lib/python3.8/site-packages/numpy/lib/function_base.py", line 2249, in _vectorize_call
res = asanyarray(outputs, dtype=otypes[0])
OverflowError: Python int too large to convert to C long

Problem with Iterable while importing reservoirpy

Hello ! I am using Python 3.10 with Windows. I had a problem while importing reservoirpy. Thank you for your help !

import reservoirpy
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Amaelle\AppData\Local\Programs\Python\Python310\lib\site-packages\reservoirpy_init_.py", line 15, in
from . import nodes
File "C:\Users\Amaelle\AppData\Local\Programs\Python\Python310\lib\site-packages\reservoirpy\nodes_init_.py", line 1, in
from .reservoir import Reservoir
File "C:\Users\Amaelle\AppData\Local\Programs\Python\Python310\lib\site-packages\reservoirpy\nodes\reservoir.py", line 8, in
from reservoirpy.base.node import Node
File "C:\Users\Amaelle\AppData\Local\Programs\Python\Python310\lib\site-packages\reservoirpy\base\node.py", line 154, in
from reservoirpy.base.model import Model
File "C:\Users\Amaelle\AppData\Local\Programs\Python\Python310\lib\site-packages\reservoirpy\base\model.py", line 10, in
from collections import Iterable
ImportError: cannot import name 'Iterable' from 'collections' (C:\Users\Amaelle\AppData\Local\Programs\Python\Python310\lib\collections_init_.py)

How to predict on unknown data

I have the following program predicting the next step ahead on the Mackey-glass dataset. If I manually change the data in the prediction range of X_test to all zeros the prediction plot shows the changed zero value data. I thought it would show some data that it was trained on? How can I train on a dataset then run a new dataset and do a prediction on the the new dataset without training. Using the training data from the initial dataset. I am looking at a system that would stream heart ECG data and do real time prediction of arrhythmia data wherein I use a trained arrhythmia model and run it against new data streams to predict arrhythmia data.

import matplotlib.pyplot as plt
import numpy as np
from reservoirpy.nodes import NVAR, Ridge
from reservoirpy.datasets import lorenz
from reservoirpy.datasets import mackey_glass
from reservoirpy.nodes import Input
import reservoirpy as rpy
rpy.verbosity(1)

nvar = NVAR(delay=2, order=2, strides=1)
readout = Ridge(1, ridge=2.5e-6)
model = nvar >> readout

tau = 17
data = mackey_glass(10000, tau=tau)
data = data.reshape(-1, 1)

VERBOSE = True

train_size = 2000
test_size = 2000
horizon = 1 # horizon p of the forecast (predict X[t+p] from X[t])

X = data[:train_size]
y = data[horizon : train_size + horizon]
X_test = data[train_size : train_size + test_size]
y_test = data[train_size + horizon : train_size + test_size + horizon]

normalize = True

if VERBOSE:
print("X, y dimensions", X.shape, y.shape)
print("X_test, y_test dimensions", X_test.shape, y_test.shape)

y_pred = model.fit(X, y).run(X_test)

plt.figure(figsize=(12, 4))
plt.plot(y_pred, color="red", lw=1.5, label="Predictions")
plt.plot(y_test, color="blue", lw=0.75, label="Ground truth")
plt.title("Output predictions against real timeseries")
plt.legend()
plt.show()

compute_all_states method in the v0.3

Hello,

I wondered how i could use compute_all_states method if I set the ESN with esn1 = input1 >> reservoir1

Error message: AttributeError: No attribute named 'compute_all_states' found in node 'Model-0': Model('Input-0', 'Reservoir-0')when i run state = esn1.compute_all_states([input.reshape(-1,n_input)], verbose=False)?

Thanks a lot

Could not install and run in google colab

I installed with:
!pip install reservoirpy==0.3.0b0

I try this example:
from reservoirpy.nodes import Reservoir, Ridge, Input

data = Input(input_dim=1)
reservoir = Reservoir(100, lr=0.3, sr=1.1)
readout = Ridge(1, ridge=1e-6)

esn = data >> reservoir >> readout

forecast = esn.fit(X, y).run(timeseries)

I have the following error:
ImportError: cannot import name 'runtime_checkable' from 'typing' (/usr/lib/python3.7/typing.py)

`PicklingError` when training the reservoir with parallelization activated in Google Colab

I'm getting the following error when running this cell:

Input:

states = reservoir.train([X_train.reshape(-1, 1)], [y_train.reshape(-1, 1)], return_states=True, verbose=True)

y_pred, states1 = reservoir.run([X_test.reshape(-1, 1)], init_state=states[0][-1], return_states=True, verbose=True)

y_pred = y_pred[0].reshape(-1, 1)
states1 = states1[0]

Output:

Training on 1 inputs (20000 steps) -- wash: 0 steps
Train:   0%|          | 0/20000 [00:00<?, ?it/s]
---------------------------------------------------------------------------
_RemoteTraceback                          Traceback (most recent call last)
_RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/joblib/externals/loky/backend/queues.py", line 153, in _feed
    obj_ = dumps(obj, reducers=reducers)
  File "/usr/local/lib/python3.7/dist-packages/joblib/externals/loky/backend/reduction.py", line 271, in dumps
    dump(obj, buf, reducers=reducers, protocol=protocol)
  File "/usr/local/lib/python3.7/dist-packages/joblib/externals/loky/backend/reduction.py", line 264, in dump
    _LokyPickler(file, reducers=reducers, protocol=protocol).dump(obj)
  File "/usr/local/lib/python3.7/dist-packages/joblib/externals/cloudpickle/cloudpickle_fast.py", line 563, in dump
    return Pickler.dump(self, obj)
  File "/usr/lib/python3.7/pickle.py", line 437, in dump
    self.save(obj)
  File "/usr/lib/python3.7/pickle.py", line 549, in save
    self.save_reduce(obj=obj, *rv)
  File "/usr/lib/python3.7/pickle.py", line 662, in save_reduce
    save(state)
  File "/usr/lib/python3.7/pickle.py", line 504, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/lib/python3.7/dist-packages/dill/_dill.py", line 990, in save_module_dict
    StockPickler.save_dict(pickler, obj)
  File "/usr/lib/python3.7/pickle.py", line 859, in save_dict
    self._batch_setitems(obj.items())
  File "/usr/lib/python3.7/pickle.py", line 885, in _batch_setitems
    save(v)
  File "/usr/lib/python3.7/pickle.py", line 549, in save
    self.save_reduce(obj=obj, *rv)
  File "/usr/lib/python3.7/pickle.py", line 662, in save_reduce
    save(state)
  File "/usr/lib/python3.7/pickle.py", line 504, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/lib/python3.7/dist-packages/dill/_dill.py", line 990, in save_module_dict
    StockPickler.save_dict(pickler, obj)
  File "/usr/lib/python3.7/pickle.py", line 859, in save_dict
    self._batch_setitems(obj.items())
  File "/usr/lib/python3.7/pickle.py", line 890, in _batch_setitems
    save(v)
  File "/usr/lib/python3.7/pickle.py", line 549, in save
    self.save_reduce(obj=obj, *rv)
  File "/usr/lib/python3.7/pickle.py", line 638, in save_reduce
    save(args)
  File "/usr/lib/python3.7/pickle.py", line 504, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python3.7/pickle.py", line 789, in save_tuple
    save(element)
  File "/usr/lib/python3.7/pickle.py", line 504, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python3.7/pickle.py", line 819, in save_list
    self._batch_appends(obj)
  File "/usr/lib/python3.7/pickle.py", line 846, in _batch_appends
    save(tmp[0])
  File "/usr/lib/python3.7/pickle.py", line 504, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python3.7/pickle.py", line 774, in save_tuple
    save(element)
  File "/usr/lib/python3.7/pickle.py", line 504, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/lib/python3.7/dist-packages/joblib/externals/cloudpickle/cloudpickle_fast.py", line 745, in save_function
    *self._dynamic_function_reduce(obj), obj=obj
  File "/usr/local/lib/python3.7/dist-packages/joblib/externals/cloudpickle/cloudpickle_fast.py", line 682, in _save_reduce_pickle5
    dictitems=dictitems, obj=obj
  File "/usr/lib/python3.7/pickle.py", line 638, in save_reduce
    save(args)
  File "/usr/lib/python3.7/pickle.py", line 504, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python3.7/pickle.py", line 789, in save_tuple
    save(element)
  File "/usr/lib/python3.7/pickle.py", line 504, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python3.7/pickle.py", line 774, in save_tuple
    save(element)
  File "/usr/lib/python3.7/pickle.py", line 504, in save
    f(self, obj) # Call unbound method with explicit self
  File "/usr/local/lib/python3.7/dist-packages/dill/_dill.py", line 1226, in save_cell
    f = obj.cell_contents
ValueError: Cell is empty
"""

The above exception was the direct cause of the following exception:

PicklingError                             Traceback (most recent call last)
<ipython-input-12-60c2f330d9e0> in <module>()
----> 1 states = reservoir.train([X_train.reshape(-1, 1)], [y_train.reshape(-1, 1)], return_states=True, verbose=True)
      2 
      3 y_pred, states1 = reservoir.run([X_test.reshape(-1, 1)], init_state=states[0][-1], return_states=True, verbose=True)
      4 
      5 y_pred = y_pred[0].reshape(-1, 1)

6 frames
/usr/lib/python3.7/concurrent/futures/_base.py in __get_result(self)
    382     def __get_result(self):
    383         if self._exception:
--> 384             raise self._exception
    385         else:
    386             return self._result

PicklingError: Could not pickle the task to send it to the workers.

I understand that it is due to an underlying process which implements parallelization, but I'm not that experienced in this and couldn't find a proper solution.

Any help would be appreciated!

Note: I'm running the notebook in Google Colab

ModuleNotFoundError: No module named 'reservoirpy.nodes'

I installed with pip install reservoirpy

I tried this tutorial : simple_example_MackeyGlass

And I get this error : Traceback (most recent call last): File "simple_example_MackeyGlass.py", line 31, in <module> from reservoirpy.nodes import Reservoir, Ridge, Input ModuleNotFoundError: No module named 'reservoirpy.nodes'

I'm on Windows 10 with a 3.8.5 Python's version

Cannot import reservoirpy v0.3.0b1

Windows
Anaconda Jupyter
Python 3.7.3
Cannot import reservoirpy v0.3.0b1

ImportError Traceback (most recent call last)
in
----> 1 import reservoirpy

~\Anaconda3\lib\site-packages\reservoirpy_init_.py in
5 from ._version import version
6
----> 7 from .utils import verbosity
8 from reservoirpy.compat.utils.save import load
9 from .utils.random import set_seed

~\Anaconda3\lib\site-packages\reservoirpy\utils_init_.py in
9 from tqdm import tqdm
10
---> 11 from .validation import is_mapping, is_sequence_set
12
13

~\Anaconda3\lib\site-packages\reservoirpy\utils\validation.py in
8 from scipy.sparse import issparse
9
---> 10 from reservoirpy.base.types import GenericNode, Weights
11
12

~\Anaconda3\lib\site-packages\reservoirpy\base\types.py in
6 from typing import (Any, Callable, Dict, Iterable, Iterator, Optional, Tuple,
7 TypeVar, Union, Sequence, List)
----> 8 from typing import overload, runtime_checkable
9
10 if sys.version_info < (3, 8):

ImportError: cannot import name 'runtime_checkable' from 'typing' (C:\Users\coren\Anaconda3\lib\typing.py)

predict on data not in the training dataset

By the lack of response I assume my usage scenario detailed below is not possible. If that is the case what is the use of Reservoirpy when the need is to train once to map a pattern then use that pattern to predict if the pattern occurs in new incoming datasets?

I have the following program predicting the next step ahead on the Mackey-glass dataset. If I manually change the data in the prediction range of X_test to all zeros the prediction plot shows the changed zero value data. I thought it would show some data that it was trained on? How can I train on a dataset then run a new dataset and do a prediction on the the new dataset without training. Using the training data from the initial dataset. I am looking at a system that would stream heart ECG data and do real time prediction of arrhythmia data wherein I use a trained arrhythmia model and run it against new data streams to predict arrhythmia data.

import matplotlib.pyplot as plt
import numpy as np
from reservoirpy.nodes import NVAR, Ridge
from reservoirpy.datasets import lorenz
from reservoirpy.datasets import mackey_glass
from reservoirpy.nodes import Input
import reservoirpy as rpy
rpy.verbosity(1)

nvar = NVAR(delay=2, order=2, strides=1)
readout = Ridge(1, ridge=2.5e-6)
model = nvar >> readout

tau = 17
data = mackey_glass(10000, tau=tau)
data = data.reshape(-1, 1)

VERBOSE = True

train_size = 2000
test_size = 2000
horizon = 1 # horizon p of the forecast (predict X[t+p] from X[t])

X = data[:train_size]
y = data[horizon : train_size + horizon]
X_test = data[train_size : train_size + test_size]
y_test = data[train_size + horizon : train_size + test_size + horizon]

normalize = True

if VERBOSE:
print("X, y dimensions", X.shape, y.shape)
print("X_test, y_test dimensions", X_test.shape, y_test.shape)

y_pred = model.fit(X, y).run(X_test)

plt.figure(figsize=(12, 4))
plt.plot(y_pred, color="red", lw=1.5, label="Predictions")
plt.plot(y_test, color="blue", lw=0.75, label="Ground truth")
plt.title("Output predictions against real timeseries")
plt.legend()
plt.show()

Problem while splitting the data

I wonder why do we have to split data into half equally when we are creating X and y. Why doesn't the algorithm support different ratios such as 0.8? I saw the split_timeseries_for_task function in the introduction to the RC notebook. But it basically splits data into 4 parts and each of the two is equal to each other. What is the exact explanation for this?

Thank for your time.

ValueError Introduction_to_RC.ipynb

Using version 0.2.2.post1, I've ran into following errors.
Versions dependencies

Linux (Ubuntu 20.04.2)
Using a virtual env:
Python version 3.8
reservoirpy: 0.2.2.post1
jupyter 1.0.0
jupyter-client 6.1.11
jupyter-console 6.2.0
jupyter-core 4.7.1
matplotlib 3.3.4
joblib 1.0.1
numpy 1.20.1
scipy 1.6.1


Following issue occurred after rerunning the notebook in cell 29

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-29-87d07857a691> in <module>
      4 Xgen_test = X_test[start+seed_timesteps: start+nb_generations+seed_timesteps]
      5 
----> 6 Xgen, states, warming_out, warming_states = reservoir.generate(nb_generations, 
      7                                                                 warming_inputs=warming_inputs.reshape(-1, 1))
      8 Xgen = Xgen.flatten(); warming_out = warming_out.flatten()

~/PycharmProjects/ReservoirTest/reservoirpy/reservoirpy/_esn.py in generate(self, nb_timesteps, warming_inputs, init_state, init_fb, verbose, init_inputs, seed, return_init)
    958             # from new input u1 and previous state s0
    959             # compute next state s1 -> s0
--> 960             _, s1 = self._get_next_state(single_input=u1,
    961                                          feedback=fb0,
    962                                          last_state=s0,

~/PycharmProjects/ReservoirTest/reservoirpy/reservoirpy/_esn.py in _get_next_state(self, single_input, feedback, last_state, noise_generator)
    277         # add bias
    278         if self.in_bias:
--> 279             u = np.hstack((1, single_input)).astype(self.typefloat)
    280         else:
    281             u = np.asarray(single_input)

<__array_function__ internals> in hstack(*args, **kwargs)

~/PycharmProjects/ReservoirTest/venv/lib/python3.8/site-packages/numpy/core/shape_base.py in hstack(tup)
    342     # As a special case, dimension 0 of 1-dimensional arrays is "horizontal"
    343     if arrs and arrs[0].ndim == 1:
--> 344         return _nx.concatenate(arrs, 0)
    345     else:
    346         return _nx.concatenate(arrs, 1)

<__array_function__ internals> in concatenate(*args, **kwargs)

ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 1 dimension(s) and the array at index 1 has 2 dimension(s)

RuntimeError at training due to multiprocessing

Hi,

Congrats on this great tool. I wanted to give it a go but I get the error below when I train a reservoir (see reservoir.train) in Introduction_to_RC.ipynb.

I ran the code on macOS Big Sur (Version 11.6.1) and tried both jupiter notebook and copy-pasting the relevant code into a script then using visual studio code (in this case, I even embedded the script in if name == 'main' and called freeze_support() as suggested in forums but with no success). ​

Please can you help me how to resolve this issue?

Thanks a lot and Best,
Agoston

Traceback (most recent call last):
​File "", line 1, in
​File "/usr/local/Cellar/[email protected]/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 116, in spawn_main
​exitcode = _main(fd, parent_sentinel)
​File "/usr/local/Cellar/[email protected]/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 126, in _main
​self = reduction.pickle.load(from_parent)
​File "/Users/amihalik/Documents/projects/reservoir/vsc-test/.venv/lib/python3.9/site-packages/reservoirpy/init.py", line 6, in
​from .utils.save import load
​File "/Users/amihalik/Documents/projects/reservoir/vsc-test/.venv/lib/python3.9/site-packages/reservoirpy/utils/save.py", line 11, in
​from .. import regression_models
​File "/Users/amihalik/Documents/projects/reservoir/vsc-test/.venv/lib/python3.9/site-packages/reservoirpy/regression_models.py", line 22, in
​from .utils.parallel import lock as global_lock
​File "/Users/amihalik/Documents/projects/reservoir/vsc-test/.venv/lib/python3.9/site-packages/reservoirpy/utils/parallel.py", line 17, in
​manager = Manager()
​File "/usr/local/Cellar/[email protected]/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 57, in Manager
​m.start()
​File "/usr/local/Cellar/[email protected]/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/managers.py", line 554, in start
​self._process.start()
​File "/usr/local/Cellar/[email protected]/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 121, in start
​self._popen = self._Popen(self)
​File "/usr/local/Cellar/[email protected]/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
​return Popen(process_obj)
​File "/usr/local/Cellar/[email protected]/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in init
​super().init(process_obj)
​File "/usr/local/Cellar/[email protected]/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_fork.py", line 19, in init
​self._launch(process_obj)
​File "/usr/local/Cellar/[email protected]/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 42, in _launch
​prep_data = spawn.get_preparation_data(process_obj._name)
​File "/usr/local/Cellar/[email protected]/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 154, in get_preparation_data
​_check_not_importing_main()
​File "/usr/local/Cellar/[email protected]/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 134, in _check_not_importing_main
​raise RuntimeError('''
RuntimeError:
​An attempt has been made to start a new process before the
​current process has finished its bootstrapping phase.
​This probably means that you are not using fork to start your
​child processes and you have forgotten to use the proper idiom
​in the main module:
​if name == 'main':
​freeze_support()
​...
​The "freeze_support()" line can be omitted if the program
​is not going to be frozen to produce an executable.

cannot import name 'Literal' from 'typing'

Reservoirpy had been worked in Google Colab (which has only python 3.7 version) for few months, and recentry I got the error messege bellow.

ImportError: cannot import name 'Literal' from 'typing' (/usr/lib/python3.7/typing.py)

According to this page , typing.Literal was induced in python 3.8 and not worked in python 3.7.

This error was not appeared in older version reservoirpy, and solved by installing old version reservoirpy in google colab.

!pip install reservoirpy==0.3.1.post1

Possible problem with reproducibility

Hello! I've been trying out the package lately, but I'm having some problems on getting reproducible results.

I'm using the set_seed function, but after the computations, the final results are not always the same. The difference seems to get bigger the more complicated the network gets.

I've coded a simple example showing how the results can be different (even if in a small proportion in this particular case) with the same seed.

Shouldn't the results be always the same? Am I doing something wrong?

The code:

def test_esn():
    import numpy as np
    import reservoirpy as rpy
    from reservoirpy.datasets import mackey_glass
    from reservoirpy.nodes import Reservoir, Ridge

    def mae(y_true, y_pred):
        return np.mean(np.abs(y_true - y_pred))
        
    rpy.set_seed(42)
    rpy.verbosity(0)

    tau = 17
    data = mackey_glass(10000, tau=tau)

    reservoir = Reservoir(units=200, lr=0.5, sr=0.8)
    readout = Ridge(ridge=1e-2)
    model = reservoir >> readout

    steps_ahead = 2
    x = data[:-steps_ahead]
    y = data[steps_ahead:]

    test_size = 1000
    x_train, y_train = x[:-test_size], y[:-test_size]
    x_test, y_test = x[-test_size:], y[-test_size:]

    model = model.fit(x, y, warmup=10)
    y_pred = model.run(x_test)

    return mae(y_test, y_pred)

n_tests = 10
for i in range(n_tests):
    print(test_esn())

The results I get:

0.008992516477464301
0.008992516477548628
0.008992516477505631
0.00899251647734063
0.008992516477433692
0.008992516477373787
0.008992516477478443
0.008992516477318252
0.008992516477449598
0.008992516477380235

DeepESN for long run patterns

ESN's are powerful but they seem to have problems with long term patterns. DeepESN might alleviate this but there aren't too many implementations of it. This is an enhancement suggestion.

Out-of-sample Prediction with ReservoirPy

Hello,

Firstly, thank you for the latest commit that solve the all problems regarding this library for me. I am stuck with question that how to predict the specific interval after our data by using our reservoir model.

Let's assume that we have 1-D array with timestamp until December 31st and we want to predict one month after December 31st which is January. How do I use RC to predict the January. Do I have to use RC in generative mode or just give the slice of all December, because we want one month prediction, from data to .run()? In the second case, will the prediction be the output of the RC model for January?

Let's assume X[-750:] is the data for December.

Will esn.run(X[-750:]) be prediction for the January?

Thanks.

Installing v2.4 instead of 3.0 with pip --pre

It's not the the right version is install in my computer

pip3 install reservoirpy
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at Homebrew/homebrew-core#76621
Collecting reservoirpy
Downloading reservoirpy-0.2.4.post1.tar.gz (45 kB)
|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 45 kB 1.6 MB/s
Preparing metadata (setup.py) ... done
Collecting tqdm>=4.43.0
Downloading tqdm-4.62.3-py2.py3-none-any.whl (76 kB)
|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 76 kB 3.2 MB/s
Requirement already satisfied: joblib>=0.12 in /opt/homebrew/lib/python3.9/site-packages (from reservoirpy) (1.1.0)
Collecting dill>=0.3.0numpy>=1.15.0
Downloading dill-0.3.4-py2.py3-none-any.whl (86 kB)
|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 86 kB 3.8 MB/s
Requirement already satisfied: scipy>=1.0.0 in /opt/homebrew/lib/python3.9/site-packages (from reservoirpy) (1.8.0.dev0+1753.a063cf3)
Requirement already satisfied: numpy>=1.17.3 in /opt/homebrew/lib/python3.9/site-packages (from scipy>=1.0.0->reservoirpy) (1.21.2)
Building wheels for collected packages: reservoirpy
Building wheel for reservoirpy (setup.py) ... done
Created wheel for reservoirpy: filename=reservoirpy-0.2.4.post1-py3-none-any.whl size=54214 sha256=71ecf37a2e29bab3187bb34473e21f02d445963348ea53f79cdd4122414dfc0e
Stored in directory: /Users/cloebrissaud/Library/Caches/pip/wheels/7b/53/10/7e57451fb406376ebedd8497c5dee6d6f2dbf8d05cf2f23bb7
Successfully built reservoirpy
Installing collected packages: tqdm, dill, reservoirpy
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at Homebrew/homebrew-core#76621
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at Homebrew/homebrew-core#76621
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at Homebrew/homebrew-core#76621
Successfully installed dill-0.3.4 reservoirpy-0.2.4.post1 tqdm-4.62.3
cloebrissaud@MacBook-Air-de-Cloe ~ % pip3 install --pre reservoirpy

DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at Homebrew/homebrew-core#76621
Requirement already satisfied: reservoirpy in /opt/homebrew/lib/python3.9/site-packages (0.2.4.post1)
Requirement already satisfied: dill>=0.3.0numpy>=1.15.0 in /opt/homebrew/lib/python3.9/site-packages (from reservoirpy) (0.3.4)
Requirement already satisfied: tqdm>=4.43.0 in /opt/homebrew/lib/python3.9/site-packages (from reservoirpy) (4.62.3)
Requirement already satisfied: joblib>=0.12 in /opt/homebrew/lib/python3.9/site-packages (from reservoirpy) (1.1.0)
Requirement already satisfied: scipy>=1.0.0 in /opt/homebrew/lib/python3.9/site-packages (from reservoirpy) (1.8.0.dev0+1753.a063cf3)
Requirement already satisfied: numpy>=1.17.3 in /opt/homebrew/lib/python3.9/site-packages (from scipy>=1.0.0->reservoirpy) (1.21.2)

IndexError for Multiclass Classification Problem

Hello!

So, I am trying to use reservoirpy and I am using as base this tutorial of yours: https://github.com/reservoirpy/reservoirpy/blob/master/tutorials/5-Classification-with-RC.ipynb

Basically, on my first try, I tried to do the same as the tutorial but with my personal data, which is basically the same of japanease_vowels but with different dimension.

But on my case, I keep receiving this erro when I try to fit the model:

IndexError: index 1 is out of bounds for axis 0 with size 1

And I don't know why I getting this. Can someone help me on that, please?

Here is the notebook that I am trying to replicate the tutorial: https://github.com/arturossouza/MoStress/blob/reservoir/experiments/reservoirTesting.ipynb

Training an ESN for times series with multiple value for each time frame?

Hi, we are trying to build and ESN with reservoirpy to perform time series prediction. Unlike most task, each time frame contains 4 values (representing coordinates), so our training data will be in shape (n, t, 4) where n is the number of unique time series, t the number of time frames.

How should I make reservoirpy.ESN learn this data?

memory leak

There's clearly a memory leak somewhere. I have no idea how to find where though. I inserted gc.collect() into the objective function and it helped alot but still memory is growing forever. I cannot run more than 60 runs without it hitting 15gb in memory.

About the more basic Nodes

Hi,

Again thank you for this great package.

In this section. I have no idea how to use the Tanh, Sigmoid, etc nodes
At first I thought those will implement a basic reservoir close to the Reservoir class. Something that could be connected to a Ridge Node.
But the capacity of those Nodes are far less than the other Reservoir class.

For improvement those Nodes could implement a less basic initializer and forward functions. At least a reservoir_kernel define here and a simple initialize as here (but only for W and W_int)

So those Nodes will have the input_connectivity, rc_connectivity and fb_connectivity parameters.

What do you think ?

installation error with 0.3.0b1 and b2 but not b0

I'm trying to install reservoirpy 0.3.0 on my laptop but I keep getting the error below. I can install 0.3.0.b0 fine its b1 and b2 that give this error.

`C:\Users\ABC\Desktop\Chaos> pip install reservoirpy==0.3.0b1

Collecting reservoirpy==0.3.0b1
Using cached reservoirpy-0.3.0b1.tar.gz (62.4 MB)
ERROR: Command errored out with exit status 1:
command: 'C:\Users\ABC\Desktop\Chaos\venv2\Scripts\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\ABC\AppData\Local\Temp\pip-install-if8bfpu1\reservoirpy_55e5a19e160542fc8a5638c833866cc0\setup.py'"'"'; file='"'"'C:\Users\ABC\AppData\Local\Temp\pip-install-if8bfpu1\reservoirpy_55e5a19e160542fc8a5638c833866cc0\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\ABC\AppData\Local\Temp\pip-pip-egg-info-5mcx8nih'
cwd: C:\Users\ABC\AppData\Local\Temp\pip-install-if8bfpu1\reservoirpy_55e5a19e160542fc8a5638c833866cc0
Complete output (7 lines):
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\ABC\AppData\Local\Temp\pip-install-if8bfpu1\reservoirpy_55e5a19e160542fc8a5638c833866cc0\setup.py", line 22, in
LONG_DESCRIPTION = f.read()
File "C:\Users\ABC\AppData\Local\Programs\Python\Python310\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 1842: character maps to
`

Readthedocs: start with simpler example than MackeyGlass

The UserGuide is well done, but some people find it difficult to grasp all the definitions and equations given in the first example here:
https://reservoirpy.readthedocs.io/en/latest/user_guide/quick.html

Some people told me that they understood better from this example (online learning rule with predicting cosine function):
https://reservoirpy.readthedocs.io/en/latest/user_guide/learning_rules.html
and they then came back to the first MackeyGlass example to better understand it.

Thus maybe we should create a "example 0" with very simple info on cosine prediction before the full MackeyGlass example.

Loading ESN

Hello,

What is the proper way to load an ESN from the disk? The following appear to work but _utils seems like using internal functions

from reservoirpy._utils import load
esn = load("esn_data")

Make more explicit the difference beetween run and generate in examples

In the following python notebook:
https://github.com/reservoirpy/reservoirpy/blob/master/examples/Introduction%20%20to%20Reservoir%20Computing/Introduction_to_RC.ipynb

Some users seem disturbed by the fact that only "generate" mode is available and take it as a "run" mode.
Maybe we should include both examples of "run mode" (predict one variables base on the others) and "generate mode" (predict / forecasting all variables in the T+n future).

Multivariate Regression in reservoirpy

Hi. I am little bit confused with the this issue that was about using this library for multivariate regression. I have some stock price data with columns like "Open, Close, High, Low" and Target column that indicates its return on that hour. So, in this task, the model predict the Target with using other features. How can I able to construct my model? I'm creating input matrix with 5 dimensions that includes "Open, Close, High, Low, Target" but in that sense, model's trying to predict all one by one. I'm not sure that I could tell my story correctly but I hope someone can answer.

Thanks

Is it possible to run Ridge() without memmap?

Hello,

many thanks for providing your great library. I tried to develop an adapter class for ReservoirPy so that it fits the API of scikit-learn. It seems as if this works for everything but for the Ridge() node, where I receive the following error:

  File ".virtualenv2\lib\site-packages\reservoirpy\node.py", line 555, in create_buffer
    self._buffers[name] = memmap_buffer(self, data=data,
  File ".virtualenv2\lib\site-packages\reservoirpy\utils\parallel.py", line 75, in memmap_buffer
    memmap = np.memmap(temp, shape=shape, mode=mode, dtype=dtype)
  File ".virtualenv2\lib\site-packages\numpy\core\memmap.py", line 228, in __new__
    f_ctx = open(os_fspath(filename), ('r' if mode == 'c' else mode)+'b')
OSError: [Errno 22] Invalid argument: 'C:\\Users\\UserName\\AppData\\Local\\Temp\\reservoirpy-temp\\Ridge-0XXT'

I think, the problem arises, because the model selection tools by scikit-learn copy an estimator. Is it possible to deactivate memmap for the Ridge Node?

on call function

Hello again,

I have an issue while using the call function on my reservoir.

From the user guide I can train the reservoir as such:

esn = reservoir >> readout

esn = esn.fit(X_train1, y_train1)

but I thought I would be able to do : reservoir.call(X_train1[0]) to get the first state of my reservoir after feeding it the first step of input data.

But the later code give the following error : ValueError: Dimension mismatch between Win and input vector in Reservoir-71: Win is (5, 1) and input is (1, 1) (1 + 1 (bias) != 4 + 1 (bias))

Anything that I misunderstood ?

Error on reservoirpy.mat_gen.generate_input_weights

Hi,
Thanks for this tool.

I have notice while using it that reservoirpy.mat_gen.generate_input_weights have small problems.

First the description of the function is not accurate for the parameter dist
For the uniform distribution the parameters are not loc and scale but low and high.

Secondly the proba parameter doesn't seem to work at all, while setting it to 1 with a uniform distribution, I still get zeros.

Best regards,

issue on unashable csr matrix nb "Introduction_to_RC"

Hi,
we are using the "Introduction_to_RC". However we encounter this issue :
"TypeError Traceback (most recent call last)
in
6 proba=density, seed=seed)
7
----> 8 reservoir = ESN(leak_rate, W, Win, ridge=regularization)

~\anaconda3\lib\site-packages\reservoirpy\nodes\esn.py in init(self, reservoir_method, learning_method, reservoir, readout, feedback, Win_bias, Wout_bias, workers, backend, name, **kwargs)
107
108 if readout is None:
--> 109 if learning_method not in _LEARNING_METHODS:
110 raise ValueError(msg.format(learning_method, "readout",
111 list(_LEARNING_METHODS.keys())))

TypeError: unhashable type: 'csr_matrix' "

For the cell :
"Win = mat_gen.generate_input_weights(units, 1, input_scaling=input_scaling,
proba=input_connectivity, input_bias=True,
seed=seed)

W = mat_gen.generate_internal_weights(units, sr=spectral_radius,
proba=density, seed=seed)

reservoir = ESN(leak_rate, W, Win, ridge=regularization)"

We are using Python 3.8.8.

HELP

Regards

How to tain a reservoir with warmup is not described in the documentation

In order to warmup (warming-up) the reservoir states at the beginning of a sequence, one need to use the "transient" parameter of Ridge. However, the documentation seems incomplete, because no description of what is "transient" is given:
https://reservoirpy.readthedocs.io/en/latest/api/generated/reservoirpy.nodes.Ridge.html#reservoirpy.nodes.Ridge

PS: changing the name "transient" to "warmup" would probably be a good idea to help people that are familiar with reservoirs to find this feature quickly (e.g., it was the name used in Oger toolbox).

Error Running Hyperoptimization

I'm running hyperopt on a model and it runs fine but it doesn't save any results completely. It saves files with the dict incomplete for all the hyperparameters.

I also get this error message:

/home/ubuntu/.local/lib/python3.8/site-packages/reservoirpy/hyper/_hypersearch.py:167: UserWarning: Results of current simulation were NOT saved correctly to JSON file.
  warnings.warn("Results of current simulation were NOT saved "

/home/ubuntu/.local/lib/python3.8/site-packages/reservoirpy/hyper/_hypersearch.py:169: UserWarning: Object of type int64 is not JSON serializable
  warnings.warn(str(e))

I did a bit of research and you cannot serialize int64 numpy objects with json.

unsupported operand type(s) for >>: 'method' and 'method'

I have tried this on macOS, Arch Linux, and Ubuntu and still get the same error. This is run on python3.10.9, in a Jupyter notebook, and I have tried running it as a python script file. In some functions, the << operator works, and sometimes it does not.

For example, for the hierarchical ESN structure.

`connection_one = data >> reservoir >> Readout

connection_two = data >> Readout

ESN_MODEL = connection_one & connection_two`

Works fine. Issues arise when the DeepESN structure is applied.

`connection_one = reservoir1 >> reservoir2 >> reservoir

connection_two = data >> [reservoir1, reservoir2, reservoir3] >> RidgeReg

ESN_MODEL = connection_one & connection_two # link the two connections`

It does not work, and I get the type error returned.

ModuleNotFoundError: No module named 'scipy.sparse.linalg.eigen.arpack'; 'scipy.sparse.linalg.eigen' is not a package

Hi,

Just upgraded lots of things while upgrading to ubuntu 22.
I have now python 3.10.4 BUT still have scipy 1.7.3, last version of reservoirpy 0.3.2.post1

I get the following error while charging the reservoir.dataset module

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 from reservoirpy.datasets import mackey_glass
      3 timesteps = 50000
      4 tau = 17

File ~/.local/lib/python3.10/site-packages/reservoirpy/__init__.py:5, in <module>
      2 import os
      3 import tempfile
----> 5 from . import activationsfunc, compat, hyper, mat_gen, nodes, observables, type
      6 from ._version import __version__
      7 from .compat import load_compat

File ~/.local/lib/python3.10/site-packages/reservoirpy/compat/__init__.py:52, in <module>
     49 from scipy import sparse
     51 from ..activationsfunc import identity
---> 52 from ..mat_gen import zeros
     53 from ..nodes import ESN as ESN_v3
     54 from ..nodes import Reservoir, Ridge

File ~/.local/lib/python3.10/site-packages/reservoirpy/mat_gen.py:111, in <module>
    109 from numpy.random import Generator
    110 from scipy import sparse, stats
--> 111 from scipy.sparse.linalg.eigen.arpack.arpack import ArpackNoConvergence
    113 from .observables import spectral_radius
    114 from .type import global_dtype

ModuleNotFoundError: No module named 'scipy.sparse.linalg.eigen.arpack'; 'scipy.sparse.linalg.eigen' is not a package

Problem with multiple inputs

Hi,

thanks a lot for the great library. I am having some stupid problem, but when trying to do multiple inputs, I get some error messages. The code is actually from the documentation, could you help me what I am doing wrong here?

from reservoirpy.nodes import Reservoir, Input
import numpy as np
source1, source2 = Input(name="s1", input_dim=5,), Input(name="s2", input_dim=3,)
res1, res2 = Reservoir(100), Reservoir(100)
model = source1 >> [res1, res2] & source2 >> [res1, res2]
outputs = model.run({"s1": np.ones((10, 5)), "s2": np.ones((10, 3))})

And the code leads to the following error message:


AttributeError Traceback (most recent call last)
/var/folders/bl/r4t30wmj1dd63sm1kdt1fs_40000gn/T/ipykernel_62311/3650941534.py in
6 res1, res2 = Reservoir(100), Reservoir(100)
7 model = source1 >> [res1, res2] & source2 >> [res1, res2]
----> 8 outputs = model.run({"s1": np.ones((10, 5)), "s2": np.ones((10, 3))})

~/miniforge3/envs/reservoir/lib/python3.9/site-packages/reservoirpy/model.py in run(self, X, forced_feedbacks, from_state, stateful, reset, shift_fb, return_states)
810 )
811
--> 812 self.initialize_on_sequence(X, forced_feedbacks_)
813
814 states = allocate_returned_states(self, X, return_states)

~/miniforge3/envs/reservoir/lib/python3.9/site-packages/reservoirpy/model.py in _initialize_on_sequence(self, X, Y)
337 y_init = np.atleast_2d(Y[0])
338
--> 339 self.initialize(x_init, y_init)
340
341 def _call(self, x=None, return_states=None, *args, **kwargs):

~/miniforge3/envs/reservoir/lib/python3.9/site-packages/reservoirpy/model.py in initialize(self, x, y)
673 """
674 self._is_initialized = False
--> 675 self._initializer(self, x=x, y=y)
676 self.reset()
677 self._is_initialized = True

~/miniforge3/envs/reservoir/lib/python3.9/site-packages/reservoirpy/model.py in initializer(model, x, y)
220 # (no real call, only zero states)
221 for node in model.nodes:
--> 222 node.initialize(x=data[node].x, y=data[node].y)
223
224 # second, probe feedback demanding nodes to

~/miniforge3/envs/reservoir/lib/python3.9/site-packages/reservoirpy/node.py in initialize(self, x, y)
672 if not self.is_initialized:
673 x_init, y_init = _init_vectors_placeholders(self, x, y)
--> 674 self._initializer(self, x=x_init, y=y_init)
675 self.reset()
676 self._is_initialized = True

~/miniforge3/envs/reservoir/lib/python3.9/site-packages/reservoirpy/nodes/reservoirs/base.py in initialize(reservoir, x, sr, input_scaling, bias_scaling, input_connectivity, rc_connectivity, W_init, Win_init, bias_init, input_bias, seed, **kwargs)
115 ):
116 if x is not None:
--> 117 reservoir.set_input_dim(x.shape[1])
118
119 dtype = reservoir.dtype

AttributeError: 'list' object has no attribute β€˜shape'

save / load esn model issue

Hello,
I try your esn lib to test a robotic grounding scenario. I succeed to train the esn and would like to save / load it to test the model under a robotic plateform (ie: webots).
But i have an issue when running the loaded esn model, see below:

reservoir.save("./esn_trained")  
esn = load("./esn_trained")
y_one, _ = esn.run([Xa[0].reshape(-1,n_input)], seed=seed)

with the following error:

AttributeError: 'ESN' object has no attribute 'noise_in'

Thanks a lot,
Nicolas

Can online learning or ReservoirPy in general be used for time series classification?

Hi,

Thank you for this library.

Currently, I am trying to use online learning as demonstrated in https://github.com/reservoirpy/reservoirpy/blob/master/tutorials/Online learning/online_learning_example_MackeyGlass.py for a classification task. The input dataset is of the shape (batch, time_sequence, features) and for each batch there is one prediction (0 or 1) which yields the shape (batch, prediction).

As I was playing around the online learning example (I could be wrong), it seems to me that online learning in ReservoirPy is built for time series forecasting where the predictions (teachers for training) should be (batch, time_sequence, prediction) or in other words, each time_sequence in each batch has its prediction.

Hence, my questions are;

  1. Can online learning be used for time series classification as I outlined above?
  2. Generally, can ReservoirPy be used for time series classification as I outlined above?

Advice: Ridge dimension should be explicit or removed from examples

In the examples and tutorials, people could be misled by what the '1' mean in such line when reusing code:
readout = Ridge(1, ridge=1e-6)

I suggest to either make it explicit that this concern the dimension of the output,
or either remove it, as for most application the Ridge will automatically autoadapt:
readout = Ridge(ridge=1e-6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.