I have the following dataframe that I am trying to use mapply
to apply a neural network function.
learning_rate = c(0.01, 0.02)
decay = c(0, 1e-1)
df = expand.grid(lr = learning_rate, decay = decay)
> df
lr decay
1 0.01 0.0
2 0.02 0.0
3 0.01 0.1
4 0.02 0.1
When I execute my function I get an error
df2 = cbind(df, mapply(LSTM_FUNC(iterations = 3, learning_rate = df$lr, decay = df$decay, epochs = 20)))
Error in py_call_impl(callable, dots$args, dots$keywords) :
TypeError: '<' not supported between instances of 'list' and 'int'
But, if I execute the same function just changing the arguments to hard-coded numbers everything works great. The function below works fine and it returns the RMSE and MAE
LSTM_FUNC(iterations = 3, learning_rate = 0.01, decay = 0, epochs = 20)
avg_rmse avg_mae
[1,] 0.5255 0.4101
The problem seems just to use df$lr
and df$decay
as arguments of the function and I do not understand why.
CodePudding user response:
We could do this by specifying the arguments in MoreArgs
mapply(LSTM_FUNC, learning_rate = df$lr, decay = df$decay,
MoreArgs = list(iterations = 3, epochs = 20))
CodePudding user response:
You mistake how mapply()
is used. The first argument is a function and the others are list or vector arguments to be passed into the function.
mapply(\(x, y) LSTM_FUNC(iterations = 3, learning_rate = x, decay = y, epochs = 20),
x = df$lr, y = df$decay)