Giter Club home page Giter Club logo

nschaetti / echotorch Goto Github PK

View Code? Open in Web Editor NEW
433.0 433.0 113.0 60.19 MB

A Python toolkit for Reservoir Computing and Echo State Network experimentation based on pyTorch. EchoTorch is the only Python module available to easily create Deep Reservoir Computing models.

Home Page: https://nschaetti.github.io/echotorch.github.io/

License: GNU General Public License v3.0

Python 99.83% Jupyter Notebook 0.17%
artificial-intelligence artificial-neural-networks echo-state-networks machine-learning machine-learning-algorithms machinelearning neural-networks python python-toolkit pytorch recurrent-networks recurrent-neural-networks reservoir-computing torch

echotorch's People

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

echotorch's Issues

cannot import echotorch because can't find datasets module ?

I installed echotorch in conda on Windows 10 using "pip install " , and I have the echotorch folder in my C:\Miniconda3\lib\site-packages
(note that my pytorch installation is working)
Problem is, every time I try to just import echotorch, I am given the following error message:
import echotorch
Traceback (most recent call last):
File "<pyshell#2>", line 1, in
import echotorch
File "C:\Miniconda3\lib\site-packages\echotorch_init_.py", line 5, in
import datasets
ModuleNotFoundError: No module named 'datasets'

That seems weird because the datasets folder has been copied during installation.
Any idea ?

Can't run any examples in timeserie_prediction folder

Trying to run any examples leads to issues

Reproduction steps

  1. install EchoTorch pip install -i https://test.pypi.org/simple/ EchoTorch
  2. Run narma10_gated_esn.py
  3. Errors: TypeError: NARMADataset.init() got an unexpected keyword argument 'seed'
  4. Remove Seed from dataset call
  5. TypeError: ESNCell.init() got an unexpected keyword argument 'spectral_radius' (bias_scaling, sparsity, w_sparsity, input_set)
  6. Remove these arguments in the constructor GatedESN call to LiESNCell constructor.
    if create_cell: self.esn_cell = LiESNCell( input_dim=input_dim, output_dim=reservoir_dim, input_scaling=input_scaling, w=w, w_in=w_in, w_bias=w_bias, nonlin_func=nonlin_func, leaky_rate=leaky_rate )
  7. Error with Dataloader when num_workers > 0, Set to 0
  8. ESNCell.py", line 319, in _input_layer
    return self.w_in.mv(ut)
    ^^^^^^^^^^^^^^^^
    RuntimeError: vector + matrix @ vector expected, got 1, 1, 1

Not sure where the problem lies or if I'm using an incompatible version of EchoTorch, has anyone had success running this one?

optimizer got an empty parameter list

Hi,
I am trying to run the code time series prediction sgd but I got an error "optimizer got an empty parameter list". I googled and found we need to register some parameters. Do you have an updated code for LiESN with the parameters list fixed?

Thank you!

I can't load the model.

D:\Software\Anaconda3\envs\zy_dl\python.exe D:/2022_DA/EchoTorch-dev/trial.py
Traceback (most recent call last):
File "D:/2022_DA/EchoTorch-dev/trial.py", line 4, in
gated_esn = etnn.GatedESN(
AttributeError: module 'echotorch.nn' has no attribute 'GatedESN'

examples of observable point

The class observable looks interesting and with lots of potential. It is used everywhere (with add_observation_point).
Is there any place in the repo where there is an example of how it is used?

Shape error of a tensor

Traceback (most recent call last):
File "switch_attractor_esn.py", line 81, in
esn(inputs, targets)
File "/Users/YumaKajihara/.pyenv/versions/anaconda3-2.5.0/lib/python3.5/site-packages/torch/nn/modules/module.py", line 491, in call
result = self.forward(*input, **kwargs)
File "/Users/YumaKajihara/research/ikeg/code/EchoTorch/examples/switch_attractor/echotorch/nn/ESN.py", line 164, in forward
hidden_states = self.esn_cell(u, y)
File "/Users/YumaKajihara/.pyenv/versions/anaconda3-2.5.0/lib/python3.5/site-packages/torch/nn/modules/module.py", line 491, in call
result = self.forward(*input, **kwargs)
File "/Users/YumaKajihara/research/ikeg/code/EchoTorch/examples/switch_attractor/echotorch/nn/LiESNCell.py", line 102, in forward
y_wfdb = self.w_fdb.mv(yt)
RuntimeError: mv: Expected 1-D argument vec, but got 0-D

Why I can't import Echotorch

Why I can't import Echotorch?What's wrong with module 'datasets'?
This problem disturbs me for days. Thank you for your help

import echotorch.nn.reservoir as etrs
import echotorch.utils
import echotorch.utils.matrix_generation as mg


ModuleNotFoundError Traceback (most recent call last)
in ()
----> 1 import echotorch.nn.reservoir as etrs
2 import echotorch.utils
3 import echotorch.utils.matrix_generation as mg

~/anaconda3/lib/python3.7/site-packages/echotorch/init.py in ()
3
4 # Imports
----> 5 import datasets
6 import models
7 import nn

ModuleNotFoundError: No module named 'datasets'

How to use an ESN with output feedbacks ?

Hi, and first of all, thanks for the awesome work :)

The issue I have is the following : I did succeed in training an ESN and using it to make predictions without feedback weights. But, when I add the parameter feedbacks=True when creating the ESN, I get an error from the following line of ESN.py:

hidden_states = self.esn_cell(u, w_out=self.w_out)

because:

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

Then, I thought I had to change this line to:

hidden_states = self.esn_cell(u, w_out=self.output.w_out)

But I get another error from ESNCell.py from the line yt = w_out.mv(self.hidden) because:

RuntimeError: size mismatch, [6 x 1], [5] at /pytorch/aten/src/TH/generic/THTensorMath.c:1928

Any idea ?

Not able to run the examples

Hi Nils,
I just installed EchoTorch and tried to run one of the examples provided by EchoTorch.
After running: python validation_10cv.py, it raised the following errors. It is the same on Windows and Ubuntu. Thanks.

Traceback (most recent call last):
File "validation_10cv.py", line 25, in
from echotorch import datasets
File "C:\Users\guan\AppData\Local\Continuum\anaconda3\lib\site-packages\echotorch_init_.py", line 5, in
import datasets
ModuleNotFoundError: No module named 'datasets'

Documentation Needs to Be Addressed

I'm new to EchoTorch and have been trying to train a LiESN. All of the examples are using old import statements, and I'm not sure how to get it working. For example,

from echotorch.models.reservoir.LiESN import LiESN
Error: cannot import name 'conceptors' from 'echotorch.nn' (/home/.local/lib/python3.8/site-packages/echotorch/nn/init.py)

No module named 'models'

I'm not sure why the init.py file for echotorch can't find the models folder when it is in the same location as the folder. How do I fix this?
image

How to prepare training data, especially the size ?

I have a batch of time serial data for regression analysis. Every timestamp has 30 features. At the beginning data are prepared as numpy ndarries. Then, I transform them into tensor datasets and set the batch_size=15 for data loader, just like this:

data_tensors = TensorDataset(torch.Tensor(x_tr), torch.Tensor(y_tr))

loader_tr = DataLoader(
            data_tensors, batch_size=batch_size, shuffle=False, num_workers=4)

However, I got an error as follows.

~/miniconda3/envs/py36/lib/python3.6/site-packages/echotorch/nn/ESNCell.py in forward(self, u, y, w_out)
    128 
    129                 # Compute input layer
--> 130                 u_win = self.w_in.mv(ut)
    131 
    132                 # Apply W to x

RuntimeError: mv: Expected 1-D argument vec, but got 0-D

It looks like the forward method need parameter "u" to be a 3-D tensor, and time_length need to be set explicitly. Is the time_length mean the number of reservoirs ? but we already have the hidden_dim.

I am quite confused about how to prepare the training data for LiESN. Could you please help me?

No gradient in ESN.py outputs

Hi guys,
I am working on this nice package (and thank you Nils for making this available) I want to add one FC layer to the network. however, when data is fed to the network, the output does not have the gradient attached to it and hence, it loses information that is needed for backpropagation.
I am able to incorporate ESNCell.py into my network and run backprop in it. however, if I use the ridge regression cell (RRCell.py) it generates an output that does not have the gradient and therefore no backprop on its output.
I used both ESN.py , LiESN.py, and after calling the finalize method, and then testing the network, the output does not have the gradient.
for example:

esn= esn = etnn.LiESN(input_dim=input_dim, hidden_dim=n_hidden, output_dim=1, spectral_radius=spectral_radius, learning_algo='inv', leaky_rate=leaky_rate)
esn(inputs,targets)
esn.finalize()
y_predicted=esn(inputs)
and then y_predicted is just a tensor without any gradient attached to it

any suggestions?

P.S.

  1. the model I want to build is: fc1==>ESN==>output

  2. If I put requires_grad=True in either line 73 or line 149(which will be w_out or output), I can get gradient in the output, but I am not sure if it is a good idea to do so :|

I installed torch but got an error: No module named 'torch'

I installed torch v1.7.0

pip show torch
Name: torch
Version: 1.7.0+cpu
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: [email protected]
License: BSD-3
Location: c:\users\thinker\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Requires: typing-extensions, future, dataclasses, numpy
Required-by: torchvision, torchaudio

However, when I run

python mackey_glass_esn.py

I got the error

Traceback (most recent call last):
  File "mackey_glass_esn.py", line 24, in <module>
    import torch
ModuleNotFoundError: No module named 'torch'

Any ideas on what to do?

Algorithm breaks when using cuda

The ESN Algo breaks (throws an exception) when it is run with a GPU. More specifically the function finalize in /echotorch/nn/RRCell.py.

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~/bachelor/test.py in <module>
     68
     69 # Finalize training
---> 70 esn.finalize()
     71
     72 # Train MSE

~/libs/EchoTorch/echotorch/nn/ESN.py in finalize(self)
    187         """
    188         # Finalize output training
--> 189         self.output.finalize()
    190
    191         # Not in training mode anymore

~/libs/EchoTorch/echotorch/nn/RRCell.py in finalize(self, train)
    178
    179                 # Algo
--> 180                 ridge_xTx = self.xTx + self.ridge_param * torch.eye(self.input_dim + self.with_bias, dtype=self.dtype)
    181                 inv_xTx = ridge_xTx.inverse()
    182                 self.w_out.data = torch.mm(inv_xTx, self.xTy).data

RuntimeError: expected type torch.cuda.FloatTensor but got torch.FloatTensor

This error was created by running the Mackey Glass example
The workaround that I have for now is

 # Algo
algo_eye = torch.eye(self.input_dim + self.with_bias, dtype=self.dtype)

#convert to cuda if necessary
if self.xTx.is_cuda:
    algo_eye = algo_eye.cuda()

ridge_xTx = self.xTx + self.ridge_param * algo_eye

Definitely not the best solution but works for now

Update pip release

First off, thanks for the library. I was running into an issue that seems to be addressed by #1 which is supposed to be fixed now, however it seems like there hasn't been an update to the release on PyPI. Would you be able to push an update to the PyPI package?

Timeserie data prediction

Hi,
I recently want to predict chaotic timeserie data and referred to your code mackey_glass_esn.py.
Unfortunately, I have met some bugs.
Firstly, this code can't find EchoTorch.datasets.MackeyGlassDataset . Obviously, it is the location problem
and I just change "EchoTorch" to "echotorch" to use MackeyGlassDataset which is in my python3.5 's packages(/usr/local/lib/python3.5/dist-packages/EchoTorch-0.1.2-py3.5.egg/echotorch/datasets/MackeyGlassDataset.py).

Next, I ran this code .


Traceback (most recent call last):
File "mackey_glass_esn.py", line 89, in
next_hidden = esn(inputs[pos], hidden)
File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 489, in call
result = self.forward(*input, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/EchoTorch-0.1.2-py3.5.egg/echotorch/nn/ESNCell.py", line 110, in forward
time_length = int(u.size()[1])
IndexError: tuple index out of range


It seems that in mackey_glass_esn.py line 89 ,the input value inputs[pos] is a single float number and its' size is 1, so tuple index out of range, I guess.

Could you give me a hand to solve the problem? Thanks :)

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.