spd_learn.functional.modeig_backward#

spd_learn.functional.modeig_backward(grad_output, s, U, s_modified, derivative, *args)[source]#

Backward pass for the modified eigenvalue of a symmetric matrix.

This function computes the backward pass for a function that modifies the eigenvalues of a symmetric matrix using the Loewner matrix formulation.

Parameters:
  • grad_output (torch.Tensor) – Gradient of the loss with respect to the output.

  • s (torch.Tensor) – Eigenvalues of the input matrix.

  • U (torch.Tensor) – Eigenvectors of the input matrix.

  • s_modified (torch.Tensor) – Modified eigenvalues after applying the function.

  • derivative (callable) – Derivative of the applied function with respect to the eigenvalues.

  • *args (tuple) – Additional arguments for the derivative of the applied function.

Returns:

grad_input – Gradient of the loss with respect to the input.

Return type:

torch.Tensor

Notes

The Loewner matrix L is computed as:

\[\begin{split}L_{ij} = \begin{cases} \frac{f(\lambda_i) - f(\lambda_j)}{\lambda_i - \lambda_j} & \text{if } \lambda_i \neq \lambda_j \\ f'(\lambda_i) & \text{if } \lambda_i = \lambda_j \end{cases}\end{split}\]

For numerical stability, we use an adaptive threshold for detecting “equal” eigenvalues that scales with the magnitude of the eigenvalues.