PyTorch torch.pinverse-Funktion
PyTorch torch Referenzhandbuch
torch.pinverseist eine Funktion in PyTorch, die verwendet wird, um die Moore-Penrose-Pseudoinverse einer Matrix zu berechnen. Sie isttorch.linalg.pinvein Alias von.
Funktionsdefinition
torch.pinverse(input, rcond=1e-15)
Parameters:
input(Tensor): Eingabematrix.rcond(float, optional): Schwellenwert für Singularwert-Abschneidung. Standardwert ist 1e-15.
Rückgabewert:
torch.Tensor: Gibt die Pseudoinverse der Matrix zurück.
Anwendungsbeispiel
Beispiel
import torch
# Erstelle eine nichtquadratische Matrix
A = torch.tensor([[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0]], dtype=torch.float64)
# Berechne die Pseudoinverse
A_pinv = torch.pinverse(A)
print("Matrix A:")
print(A)
print("nPseudoinverse A^+:")
print(A_pinv)
# Erstelle eine nichtquadratische Matrix
A = torch.tensor([[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0]], dtype=torch.float64)
# Berechne die Pseudoinverse
A_pinv = torch.pinverse(A)
print("Matrix A:")
print(A)
print("nPseudoinverse A^+:")
print(A_pinv)
Das Ausgabeergebnis ist:
矩阵 A:
tensor([[1., 2., 3.],
[4., 5., 6.]], dtype=torch.float64)
伪逆 A^+:
tensor([[-0.9444, 0.4444],
[-0.2778, 0.2778],
[ 0.3889, 0.1111]], dtype=float64)
Andere Erweiterungen