initialize module¶
- initialize.nnsvd_nmf_initialize(X, k, seed=None)[source]¶
Initializes the factors W and H for Non-negative Matrix Factorization (NMF) using the Non-negative Double Singular Value Decomposition (NNDSVD) method with PyTorch.
This initialization helps improve convergence speed and avoid local minima by providing structured non-negative starting points for W and H.
- Parameters:
X (torch.Tensor) -- The input non-negative matrix to be factorized, with shape (m, n). All elements of X should be non-negative.
k (int) -- The rank for the factorization, representing the number of components.
seed (int) -- (Optional) The random seed for reproducibility of the initialization. If not specified, a random seed will be used.
- Returns:
A tuple containing: - W (torch.Tensor): Initialized factor matrix of shape (m, k). - H (torch.Tensor): Initialized factor matrix of shape (n, k).
- Return type:
Tuple[torch.Tensor, torch.Tensor]
- initialize.nnsvd_nmtf_initialize(X, k1, k2, seed=None)[source]¶
NNDSVD-based initialization for Non-negative Matrix Tri-Factorization (NMTF) using PyTorch. Unlike standard NMF, the internal dimensions of W and H can differ.
This method aims to provide a structured, non-negative initialization for W and H, improving convergence speed and stability.
- Parameters:
X (torch.Tensor) -- The input non-negative matrix to factorize, with shape (m, n). All elements of X should be non-negative.
k_W (int) -- The rank for the row factorization, representing the number of components in W.
k_H (int) -- The rank for the column factorization, representing the number of components in H.
seed (int) -- (Optional) The random seed for reproducibility. If not specified, a random seed will be used.
- Returns:
A tuple containing the initialized factor matrices: - W (torch.Tensor): Factor matrix of shape (m, k_W). - H (torch.Tensor): Factor matrix of shape (n, k_H).
- Return type:
Tuple[torch.Tensor, torch.Tensor]