Reputation: 6121
I want to implement a custom layer in keras. Unfortunately one part of the calculation requires the pseudo inverse (to solve x = (A'A)⁻¹A'b). Now I am missing the functionality of K.inverse
. Is there a way I can solve an OLS equation using the keras backend?
def call(inputs, **kwargs):
A = ...
b = ...
return K.inverse(K.transpose(A) @ A) @ K.transpose(A) @ b
Maybe I can read it back to numpy arrays do the inverse and then feed it back to a tensor or similar?
Upvotes: 2
Views: 708
Reputation: 969
you can use tensorflow's inverse(tf.linalg.inv) inside a keras Lambda layer, that way, you don't have to create a custom layer, just a custom function.
Upvotes: 1