Skip to content

compute_matrix_root_inverse_residuals

compute_matrix_root_inverse_residuals computes the residual of a matrix root inverse, which is typically used for debugging or testing the accuracy of matrix root inverse computations.

Function Definition

def compute_matrix_root_inverse_residuals(
    A: torch.Tensor,
    X_hat: torch.Tensor,
    root: int,
    epsilon: float,
    exponent_multiplier: float
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:

Parameters

Parameter Type Description
A torch.Tensor The matrix of interest.
X_hat torch.Tensor The computed matrix root inverse.
root int The root of interest.
epsilon float A small value added as epsilon * I to the matrix to provide numerical stability.
exponent_multiplier float The exponent multiplier applied to computation of the inverse root.

Returns

Name Type Description
absolute_error torch.Tensor Absolute error of the matrix root inverse.
relative_error torch.Tensor Relative error of matrix root inverse.
residual torch.Tensor Residual of the matrix root inverse computation.

Detailed Description

This function aims to calculate the discrepancy between the exact mathematical inverse root of a matrix and one that has been computed using numerical methods. Errors and residuals are calculated in the infinity norm, providing an overview of the largest errors in the computation without averaging.

  • The relative error refers to the absolute difference of the computed matrix root inverse from the expected exact value, relative to the magnitude of the exact value.
  • The relative residual is the discrepancy between the multiplied result of the matrix and its computed root inverse from the identity matrix, which ideally should be zero.

Usage Examples

Basic Usage

Here we will show some code written in the same markdown file as an example to showcase how the function can be used in a simple case.

```python
import torch

from zeta.ops import compute_matrix_root_inverse_residuals

# Sample 3x3 matrix
A = torch.rand((3, 3), dtype=torch.float64)
X_hat = torch.rand((3, 3), dtype=torch.float64)

# Compute the residuals
abs_error, rel_error, residual = compute_matrix_root_inverse_residuals(
    A, X_hat, root=2, epsilon=1e-6, exponent_multiplier=1.0
)
print("Absolute Error:", abs_error)
print("Relative Error:", rel_error)
print("Residual:", residual)

Additional Usage Examples

Owing to the limitations of this platform, we cannot provide additional explicit examples in this response. However, similar examples could range from using this function to verify the accuracy of differently computed matrix roots to varying epsilon and seeing the impact on stability.

Common Issues and Troubleshooting

  • ValueError: Occurs if A is not a square matrix or if the size of A and X_hat do not match. Ensure that A is square and the dimensions match X_hat.
  • Numerical Stability: Choosing a very small or large value of epsilon might cause numerical instability. It is recommended to keep this value within the range typical for your data type, for instance, 1e-6 for float64.
  • High Relative Error: If the relative error is unusually high, it might indicate an issue with the computation of X_hat.

References and Resources

  • PyTorch Documentation: https://pytorch.org/docs/stable/index.html
  • Matrix Algebra Theory: (Insert relevant link or book citation)
  • Numerical Methods for Matrix Computations: (Insert relevant link or book citation)