Fonction torch.orgqr de PyTorch
Manuel de référence Pytorch torch
torch.orgqrIl s'agit d'une fonction de PyTorch utilisée pour reconstruire la matrice orthogonale Q à partir de la décomposition QR. Elle utilise les réflecteurs de Householder obtenus à partir de la décomposition QR pour calculer la matrice Q.
Définition de fonction
torch.orgqr(input)
Parameters:
input(Tensor) : tenseur d'entrée contenant les réflecteurs de Householder.
Valeur de retour:
torch.Tensor: Renvoie la matrice orthogonale Q.
Exemple d'utilisation
Exemple
import torch
# Créer une matrice
A = torch.tensor([[12.0, -51.0, 4.0],
[6.0, 167.0, -68.0],
[-4.0, 24.0, -41.0]], dtype=torch.float64)
# Décomposition QR
Q, R = torch.linalg.qr(A)
print("Matrice A :")
print(A)
print("nMatrice orthogonale Q:")
print(Q)
print("nVerify Q.T @ Q = I:")
print(Q.T @ Q)
# Créer une matrice
A = torch.tensor([[12.0, -51.0, 4.0],
[6.0, 167.0, -68.0],
[-4.0, 24.0, -41.0]], dtype=torch.float64)
# Décomposition QR
Q, R = torch.linalg.qr(A)
print("Matrice A :")
print(A)
print("nMatrice orthogonale Q:")
print(Q)
print("nVerify Q.T @ Q = I:")
print(Q.T @ Q)
Le résultat de sortie est:
矩阵 A:
tensor([[ 12., -51., 4.],
[ 6., 167., -68.],
[ -4., 24., -41.]], dtype=torch.float64)
正交矩阵 Q:
tensor([[-0.8571, 0.3943, 0.3314],
[-0.4286, -0.9029, -0.0343],
[ 0.2857, -0.1714, 0.9428]], dtype=torch.float64)
验证 Q.T @ Q = I:
tensor([[ 1.0000e+00, -1.4895e-16, 2.2204e-16],
[-1.4895e-16, 1.0000e+00, 9.8601e-32],
[ 2.2204e-16, 9.8601e-32, 1.0000e+00]], dtype=torch.float64)
Autres extensions