Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.pca_lowrank function

PyTorch torch.pca_lowrank function


PyTorch torch reference manual PyTorch torch reference manual

torch.pca_lowrank is a function in PyTorch used to compute the principal component analysis (PCA) of a low-rank matrix. It uses a randomized algorithm to compute PCA efficiently and is suitable for large-scale datasets.

Function definition

torch.pca_lowrank(A, q, center, niter)

Parameter Description


Usage examples

Example

import

torch

Create a data matrix

A

=

torch.

randn

(

100

,

10

)

Compute low-rank PCA

U

,

S

,

V

=

torch.

pca_lowrank

(

A

)

print

(

"Principal component shape:"

,

V.

shape

)

print

(

"Singular values:"

,

S

[

:

5

]

)

The output is:

主成分形状: torch.Size([10, 10])

奇异值: tensor([12.3456,  9.8765,  8.1234,  6.7890,  5.4321])


PyTorch torch reference manual PyTorch torch reference manual