I’m trying to implement a custom loss function for a neural network in Keras. The model must be trained to predict quaternion (a specific vector with four elements)

`Y_pred = [w x y z]`

Y_true and Y_pred are quaternion and the error is calculated by quaternion multiplication:

`Error = Y_true * inverse(Y_pred)`

`Error = [w_err x_err y_err z_err]`

Ideally, the first element must be 1 and other elements must be 0:

` Error = [1 0 0 0]`

How can I create such a custom loss function?

PS

The inverse is calculated by

` inverse(Y_pred) = [w, -x, -y, -z]`