GithubHelp home page GithubHelp logo

Comments (4)

nTrouvain avatar nTrouvain commented on June 20, 2024

Hello,

Could you try to import reservoirpy from within the 'if name == "main":' statement ?

PS: Thank you for using reservoirpy, we are glad you like it :)

from reservoirpy.

anaston avatar anaston commented on June 20, 2024

Thank you for the quick reply:)

Yes, I tried adding it into an 'if name == "main":' statement but still getting this RuntimeError. However, what is very odd that actually the code does not stop at the error. Now I added some additional code after this error is printed in the terminal and that runs. Do you have an idea what's happenning? Sorry, I am new to Python, so I might miss something basic.

Pleas the script below that I use:

def split_timeserie_for_task1(forecast, train_length=20000):

X_train, y_train = X[:train_length], X[forecast: train_length+forecast]
X_test, y_test = X[train_length: -forecast], X[train_length+forecast:]

return (X_train, y_train), (X_test, y_test)

def reset_esn():
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)

return reservoir

def r2_score(y_true, y_pred):
return 1 - (np.sum((y_true - y_pred)**2) / np.sum((y_true - y_true.mean())**2))

def nrmse(y_true, y_pred):
return np.sqrt((np.sum(y_true - y_pred)**2) / len(y_true)) / (y_true.max() - y_true.min())

if name == 'main':
import numpy as np
import matplotlib.pyplot as plt
from reservoirpy import mat_gen, ESN
from reservoirpy.datasets import mackey_glass

# Generate data

timesteps = 25000
tau = 17
X = mackey_glass(timesteps, tau=tau)

# rescale between -1 and 1
X = 2 * (X - X.min()) / (X.max() - X.min()) - 1

forecast = 10
(X_train, y_train), (X_test, y_test) = split_timeserie_for_task1(forecast)

sample = 500
figsizex = 15
figsizey = 3

# %% ESN training and prediction

units = 100
leak_rate = 0.3
spectral_radius = 1.25
input_scaling = 1.0
density = 0.1
input_connectivity = 0.2
regularization = 1e-8
seed = 1234

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)

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

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

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

fig = plt.figure(figsize=(figsizex, figsizey)) # figsize=(15, 7)
plt.plot(np.arange(sample), y_pred[:sample], lw=3, label="ESN prediction")
plt.plot(np.arange(sample), y_test[:sample], linestyle="--", lw=2, label="True value")
plt.plot(np.abs(y_test[:sample] - y_pred[:sample]), label="Absolute deviation")

plt.legend()
plt.show()

from reservoirpy.

nTrouvain avatar nTrouvain commented on June 20, 2024

Hello,
We have partially fixed the issue, but I am affraid it is caused by the behaviour of Mac OS regarding how to instanciate processes.
Using the if __name__ == "__main__": statement is mandatory in your case when launching your code (it is actually a good practice in Python in any case). Thank you for drawing this to our attention, we will try to document this error the best we can. In the meantime, next releases v0.2.4-post1 and v0.3.0b1 will avoid raising this error all the time, even when parallelization is deactivated. You can deactivate it by using "sequential" as a backend in the trainnig functions, or by setting it globaly using the set_joblib_backend("sequential") function.

from reservoirpy.

anaston avatar anaston commented on June 20, 2024

Thanks a lot for trying to fix this and the help with the workaround. Feel free to let me know if I can be helpful in any testing.

from reservoirpy.

Related Issues (20)

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.