PlasmaControl / PyRCN

A Python 3 framework for Reservoir Computing with a scikit-learn-compatible API.
BSD 3-Clause "New" or "Revised" License
89 stars 19 forks source link

ReservoirWeightGeneration_TIMIT notebook dependencies not available #50

Closed alvin-garcia closed 2 years ago

alvin-garcia commented 2 years ago

Hello PyRCN Team,

I followed the basic tutorial and got it to work.

Screen Shot 2022-08-15 at 10 48 07 AM

I want to adapt the TIMIT notebook to my dataset since I'm doing classification over spectrogram images as shown below.

image

Using a sliding window with 75% overlap, the inputs are [samples*sliding windows, timestamps in window, frequency]. You'll notice four "sub-bins" per dashed window in the predictions.

However, I can't seem to import the dependencies shown below.

Screen Shot 2022-08-15 at 10 47 15 AM

My versions are up to date

Screen Shot 2022-08-15 at 10 53 34 AM

Please update the dependencies. Thanks.

renierts commented 2 years ago

Dear @alvin-garcia,

thanks for bringing up this issue. In fact, I was already notified about this before. The SeqToSeqESNClassifier is no more required and now included in the ESNClassifier. You can have a look on the updated version of the notebook in the dev-Branch. After releasing the next version of PyRCN, this will be available on the main branch.

renierts commented 2 years ago

Dear @alvin-garcia,

with the release of the new version of PyRCN, we updated everything. Can you please confirm whether this works now and close this issue if so?

alvin-garcia commented 2 years ago

Dear @renierts,

Thanks for looking into this issue. I need help getting the RCN code to run successfully. I noticed the TIMIT example was removed from the examples, so instead I will attach what I really want to train. rcn_spec.pdf

There's an issue in ~/.conda/envs/tf2-gpu/lib/python3.7/site-packages/pyrcn/echo_state_network/_esn.py, with ndim on line 205. Wrapping the input using np.asarray created a new error. Not sure how to proceed?

Screen Shot 2022-08-25 at 9 57 40 AM

renierts commented 2 years ago

Hi @alvin-garcia,

thanks for the hint. I noticed from your appended example that you want to train the ESN with multiple spectrograms (each spectrogram is a sequence). As shown in the documentation, this can be done by passing numpy arrays to the ESN. I think, the solution to your problem is to change a few lines of code in cell 12 your jupyter notebook:

There, you have the following lines:

X_train = [x for x in x_train_arr]
y_train = [y for y in y_train_arr]
X_test = [x for x in x_val_arr]
y_test = [y for y in y_val_arr]

you should change these lines of code to the following:

X_train = np.empty(shape=(x_train_arr.shape[0], ), dtype=object)  # shape is the number of sequences/spectrograms
y_train = np.empty(shape=(y_train_arr.shape[0], ), dtype=object)  # shape is the number of sequences/spectrograms
X_test = np.empty(shape=(x_test_arr.shape[0], ), dtype=object)  # shape is the number of sequences/spectrograms
y_test = np.empty(shape=(y_test_arr.shape[0], ), dtype=object)  # shape is the number of sequences/spectrograms
for k, (x, y) in enumerate(zip(x_train_arr, y_train_arr)):
    X_train[k] = x  # x has the shape (n_samples, n_features)
    y_train[k] = y
for k, (x, y) in enumerate(zip(x_test_arr, y_test_arr)):
    X_test[k] = x  # x has the shape (n_samples, n_features)
    y_test[k] = y

This creates a numpy array of dtype object (similar as a list). PyRCN will then iterate across each element in this numpy array.

alvin-garcia commented 2 years ago

Ah interesting solution, yes that worked. Thanks!

The code completed and first_try.joblib was output.

Don't close the issue yet please, I need to make sure the outputs of the model make at least some sense.

renierts commented 2 years ago

Great that it works.

Sure, I will not close the issue before you notify me that everything works. You can close it by yourself as well, if you want.