Using make.link in a layer_lambda

Viewed 24

I am trying to pass an inverse link function to a keras::layer_lambda layer in a keras functional model. The layer is inside a function where "link" is a parameter:

link_layer <- spatial_summing_layer %>%
    keras::layer_lambda(stats::make.link(link)$linkinv,
                        name = "link_layer")

It works fine for "identity", "sqrt", "1/mu^2" and "inverse" (all do not use .Machine$double.eps), but when I try to use a different link ("log"), I get the following error:

Error in py_call_impl(callable, dots$args, dots$keywords) : 
RuntimeError: Exception encountered when calling layer "link_layer" (type Lambda).

Evaluation error: missing value where TRUE/FALSE needed.

Call arguments received by layer "link_layer" (type Lambda):
• inputs=tf.Tensor(shape=(None, 867, 1), dtype=float32)
• mask=None
• training=None

I believe it must be something to do with the environments, but I have no idea how to resolve it, except for manually coding the link functions myself.

0 Answers
Related