Hi Choi!



 geunseok_choi:

I don’t know how to make the backward part.
The backward part consisted of the gradient of the function is made with the eigenvalue problem.


If your main roadblock really is just backpropagating through the
“eigenvalue problem,” then you could perform that part of the
calculation using pytorch’s torch.eig() (or torch.symeig()),
and use autograd to backpropagate through the eigenvalue piece.
If, furthermore, the rest of your loss function can also be written with
pytorch tensor functions, you could use autograd to backpropagate
through the entire loss function.
But even if not, you could:
loss = (tensor functions) --> c-function-A --> torch.eig() --> c-function-B --> (more tensor functions)

If you can figure out the gradient for c-function-A and c-function-B
(even if you can’t for the eigenvalue problem), you can write your
custom c functions with both .forward() and .backward() functions,
and use autograd to backpropagate through the whole thing.  This way,
you’re letting pytorch’s autograd do the “hard part” (namely, calculating
the gradient of the eigenvalue problem) for you, while you write the
gradients (the .backward() functions) for c-function-A and
c-function-B, which you can’t, or don’t want to, write using pytorch
tensor functions.
Best.
K. Frank