reservoirpy / reservoirpy Goto Github PK
View Code? Open in Web Editor NEWA simple and flexible code for Reservoir Computing architectures like Echo State Networks
License: MIT License
A simple and flexible code for Reservoir Computing architectures like Echo State Networks
License: MIT License
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
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
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.
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.
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
Hello, I have this problem in "Introduction_to_RC.ipynb",
cannot import name 'ESN' from 'reservoirpy'
Thank you for your help :)
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)
I installed reservoirpy 0.3.0b2
version with pip install --pre reservoirpy
.
I tried this tutorial : simple_example_MackeyGlass
I get the error:
Traceback (most recent call last):
File "simple_example_MackeyGlass.py", line 4, in <module>
from reservoirpy import ESN
ImportError: cannot import name 'ESN' from 'reservoirpy'
In ubuntu with python 3.8.10
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)
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
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.
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
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.
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.
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)
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")
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?
I dont know how to calculate the memory capcity of the esn with reservoirpy.
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)
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 ?
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
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.
In this tutorial it is written v0.2.3 for the installation, but the tutorial seemed to have been updated recently, so it is the 0.3?
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;
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
`
I have hyperopt==2.7 and this problem seems linked to this version.
On hyperopt github, two issues are related:
hyperopt/hyperopt-sklearn#179
hyperopt/hyperopt#829
--> changing hyperopt to 2.5 version solved the issue.
Could you provide a quick example of both to see how they work with the new api?
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
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'
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).
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)
The following tutorial is both in English and French:
https://github.com/reservoirpy/reservoirpy/blob/master/tutorials/Introduction%20%20to%20Reservoir%20Computing/R4_2021_RC_Tutorial.ipynb
When time allows, it should probably be duplicated for one in English and one in French.
In this tutural.
I Can not file the data used for chapter 4 or chapter 5. these data needs downloading by myself? or provided somewhere in the project. Thanks a lot.
BTW. The examples in the example folder maybe outdated.
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()
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
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?
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()
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 ?
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)
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
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.
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,
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
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.
Basic info about the paper and what the task is about could be added in the Asabuki tutorial:
https://github.com/reservoirpy/reservoirpy/tree/master/examples/Interactive%20reservoir%20computing%20for%20chunking%20information%20streams
For instance, a link to the paper:
https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1006400
Could we parallelize the loop in file
reservoirpy/reservoirpy/ESN.py line 367 ?
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.
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).
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.