Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mackey-glass problem with LMU giving out the error with the recent updates of keras-lmu 0.2.0 and 0.3.0 versions #25

Open
samarsreddy opened this issue Nov 7, 2020 · 6 comments

Comments

@samarsreddy
Copy link

samarsreddy commented Nov 7, 2020

<ipython-input-16-f9340b4f7a97> in <module>()
     50 layers = 4
     51 lstm_model = make_lstm(units=25, layers=layers)
---> 52 lmu_model = make_lmu(units=49, layers=layers)
     53 hybrid_model = make_hybrid(units_lstm=25, units_lmu=40, layers=layers)

1 frames

<ipython-input-16-f9340b4f7a97> in delay_layer(units, **kwargs)
     18                        #memory_d=memory_d,
     19                        #hidden_cell=tf.keras.layers.SimpleRNNCell(212),
---> 20                        theta=4,
     21                       ),
     22                return_sequences=True,

TypeError: __init__() missing 2 required positional arguments: 'memory_d' and 'hidden_cell'
]

Here I passed the missing parameters..

def make_lstm(units, layers):
    model = Sequential()
    model.add(LSTM(units,
                   input_shape=(train_X.shape[1], 1),  # (timesteps, input_dims)
                   return_sequences=True))  # continuously outputs per timestep
    for _ in range(layers-1):
        model.add(LSTM(units, return_sequences=True))
    model.add(Dense(train_X.shape[-1], activation='tanh'))
    model.compile(loss="mse", optimizer="adam")
    model.summary()
    return model

def delay_layer(units, **kwargs):
    return RNN(LMUCell(units=units,
                       order=4,
                       memory_d=4,
                       hidden_cell=tf.keras.layers.Layer,
                       #memory_d=memory_d,
                       #hidden_cell=tf.keras.layers.SimpleRNNCell(212),
                       theta=4,
                      ),
               return_sequences=True,
               **kwargs)
def make_lmu(units, layers):
    model = Sequential()
    model.add(delay_layer(units,
                          input_shape=(train_X.shape[1], 1)))  # (timesteps, input_dims)
    for _ in range(layers-1):
        model.add(delay_layer(units))
    model.add(Dense(train_X.shape[-1], activation='linear'))
    model.compile(loss="mse", optimizer="adam")
    model.summary()
    
    return model


def make_hybrid(units_lstm, units_lmu, layers):
    assert layers == 4, "unsupported"
    model = Sequential()
    model.add(delay_layer(units=units_lmu,input_shape=(train_X.shape[1], 1)))
    model.add(LSTM(units=units_lstm, return_sequences=True))
    model.add(delay_layer(units=units_lmu))
    model.add(LSTM(units=units_lstm, return_sequences=True))
    model.add(Dense(train_X.shape[-1], activation='tanh'))
    model.compile(loss="mse", optimizer="adam")
    model.summary()
    return model


layers = 4
lstm_model = make_lstm(units=25, layers=layers)
lmu_model = make_lmu(units=49, layers=layers) 
hybrid_model = make_hybrid(units_lstm=25, units_lmu=40, layers=layers)

Even after passing out the missing parameters giving another error with units, even I installed the latest keras-lmu but same problem I think because version 0.2.0 removed the units and hidden_activation parameters of LMUCell (these are now specified directly in the hidden_cell. (#22) So please provide the updated codes for mackey-glass prediction problem also. Thanks in advance

TypeError                                 Traceback (most recent call last)

<ipython-input-17-1c880cdb37fc> in <module>()
     50 layers = 4
     51 lstm_model = make_lstm(units=25, layers=layers)
---> 52 lmu_model = make_lmu(units=49, layers=layers)
     53 hybrid_model = make_hybrid(units_lstm=25, units_lmu=40, layers=layers)

6 frames

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/generic_utils.py in validate_kwargs(kwargs, allowed_kwargs, error_message)
    776   for kwarg in kwargs:
    777     if kwarg not in allowed_kwargs:
--> 778       raise TypeError(error_message, kwarg)
    779 
    780 

TypeError: ('Keyword argument not understood:', 'units')

@samarsreddy samarsreddy changed the title mackey-glass problem with LMU giving out the error with the recent updates of lkeras-lmu 0.2.0 and 0.3.0 versions mackey-glass problem with LMU giving out the error with the recent updates of keras-lmu 0.2.0 and 0.3.0 versions Nov 7, 2020
@drasmuss
Copy link
Member

drasmuss commented Nov 9, 2020

Which Mackey-Glass code are you trying to run? If it's the results from the original LMU paper, that code base is preserved here https://github.com/nengo/keras-lmu/blob/paper/experiments/mackey-glass.ipynb and should continue to run (note that you will need to be on the paper branch of the LMU repo). If it's your own code that you're trying to get running with KerasLMU 0.3.0 I'd recommend coming by the forum and we can help you there, it's just a better format for these kinds of questions.

However, from a brief look at your code, it looks like the problem is here

LMUCell(units=units,
        order=4,
        memory_d=4,
        hidden_cell=tf.keras.layers.Layer,
        #memory_d=memory_d,
        #hidden_cell=tf.keras.layers.SimpleRNNCell(212),
        theta=4,
),

As you said

0.2.0 removed the units and hidden_activation parameters of LMUCell (these are now specified directly in the hidden_cell.

So the units should be specified in the hidden cell, like

LMUCell(order=4,
        memory_d=4,
        hidden_cell=tf.keras.layers.SimpleRNNCell(units=212),
        theta=4,
),

You can see the API of LMUCell here and an example of using the API in practice here.

@samarsreddy
Copy link
Author

samarsreddy commented Nov 11, 2020 via email

@drasmuss
Copy link
Member

So please send me the correct code to run it on colab without errors

It shouldn't make any difference whether you're running on Colab or not (it's just a Python environment in any case).

If you just want to recreate the results from the paper (from https://github.com/nengo/keras-lmu/blob/paper/experiments/mackey-glass.ipynb), then as mentioned you should install the paper branch of the LMU repo. You can do this in Colab by adding !pip install git+https://github.com/nengo/keras-lmu@paper at the top of your code. Or, if you wanted to install the 0.1.0 version (which I'm guessing is what you were using before), you can install that by putting !pip install lmu==0.1.0 at the top of your code. In either case, you should then be able to recreate the results from the paper.

If you're wanting to update the code from the paper to work with recent KerasLMU versions, I'd recommend coming by the forum and we can help you there (that's a better format for those kinds of research support questions). I don't see any errors in the output you posted, just looks like you're getting a few warnings (which should be safe to ignore).

@samarsreddy
Copy link
Author

samarsreddy commented Nov 12, 2020 via email

@drasmuss
Copy link
Member

Sure sir, thank you very much for the help as you said I tried on colab(!pip
install git+https://github.com/nengo/keras-lmu@paper at the top of your
code. Or, if you wanted to install the 0.1.0 version (which I'm guessing is
what you were using before), you can install that by putting !pip install
lmu==0.1.0 at the top of your code) but it returned same only.

That means that it did not install correctly. To be clear, you need to have a line at the top of your notebook that looks like this:
Capture
That will install the 0.1.0 version, and you will not get that error.

@samarsreddy
Copy link
Author

samarsreddy commented Nov 14, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants