pca#
- diffsptk.PCA#
alias of
PrincipalComponentAnalysis
- class diffsptk.PrincipalComponentAnalysis(order: int, n_comp: int, *, cov_type: str | int = 'sample', sort: str = 'descending', batch_size: int | None = None, verbose: bool = False)[source]#
See this page for details. Note that the forward method is not differentiable.
- Parameters:
- orderint >= 0
The order of the vector, \(M\).
- n_compint >= 1
The number of principal components, \(K\).
- cov_type[‘sample’, ‘unbiased’, ‘correlation’]
The type of covariance matrix.
- sort[‘ascending’, ‘descending’]
The order of eigenvalues.
- batch_sizeint >= 1 or None
The batch size.
- verbosebool
If True, shows progress bars.
- center(x: Tensor) Tensor [source]#
Center the input vectors using the estimated mean.
- Parameters:
- xTensor [shape=(…, M+1)]
The input vectors.
- Returns:
- outTensor [shape=(…, M+1)]
The centered vectors.
- forward(x: Tensor | DataLoader) tuple[Tensor, Tensor, Tensor] [source]#
Perform principal component analysis.
- Parameters:
- xTensor [shape=(T, M+1)] or DataLoader
The input vectors or a DataLoader that yields the input vectors.
- Returns:
- sTensor [shape=(K,)]
The eigenvalues.
- VTensor [shape=(K, M+1)]
The eigenvectors.
- mTensor [shape=(M+1,)]
The mean vector.
Examples
>>> x = diffsptk.nrand(10, 3) >>> x.size() torch.Size([10, 4]) >>> pca = diffsptk.PCA(3, 3) >>> s, _, _ = pca(x) >>> s tensor([1.3465, 0.7497, 0.4447]) >>> y = pca.transform(x) >>> y.size() torch.Size([10, 3])