PyTorch torch.orgqr 関数
torch.orgqrPyTorch において QR 分解から直交行列 Q を再構成するために使用される関数です。QR 分解で得られた Householder 反射器を使用して Q 行列を計算します。
関数定義
torch.orgqr(input)
パラメータ:
input(Tensor): 入力テンソル。Householder 反射器を含みます。
戻り値:
torch.Tensor: 直交行列 Q を返します。
使用例
サンプル
import torch
# 行列を作成
A = torch.tensor([[12.0, -51.0, 4.0],
[6.0, 167.0, -68.0],
[-4.0, 24.0, -41.0]], dtype=torch.float64)
# QR 分解
Q, R = torch.linalg.qr(A)
print("行列 A:")
print(A)
print("n直交行列 Q:")
print(Q)
print("n検証 Q.T @ Q = I:")
print(Q.T @ Q)
# 行列を作成
A = torch.tensor([[12.0, -51.0, 4.0],
[6.0, 167.0, -68.0],
[-4.0, 24.0, -41.0]], dtype=torch.float64)
# QR 分解
Q, R = torch.linalg.qr(A)
print("行列 A:")
print(A)
print("n直交行列 Q:")
print(Q)
print("n検証 Q.T @ Q = I:")
print(Q.T @ Q)
出力結果は次のとおりです:
矩阵 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)
その他の拡張
Pytorch torch リファレンスマニュアル