r""" Approximately factor a real-valued matrix using regularized alternating least-squares (ALS). Notes ----- The regularized ALS minimization problem is .. math:: \min_{\mathbf{W}, \mathbf{H}} ||\mathbf{X} - \mathbf{WH}||^2 -
(self, K, alpha=1, max_iter=200, tol=1e-4)
| 7 | |
| 8 | class VanillaALS: |
| 9 | def __init__(self, K, alpha=1, max_iter=200, tol=1e-4): |
| 10 | r""" |
| 11 | Approximately factor a real-valued matrix using regularized alternating |
| 12 | least-squares (ALS). |
| 13 | |
| 14 | Notes |
| 15 | ----- |
| 16 | The regularized ALS minimization problem is |
| 17 | |
| 18 | .. math:: |
| 19 | |
| 20 | \min_{\mathbf{W}, \mathbf{H}} ||\mathbf{X} - \mathbf{WH}||^2 - |
| 21 | \alpha \left( |
| 22 | ||\mathbf{W}||^2 + ||\mathbf{H}||^2 |
| 23 | \right) |
| 24 | |
| 25 | where :math:`||\cdot||` denotes the Frobenius norm, **X** is the |
| 26 | :math:`N \times M` data matrix, :math:`\mathbf{W}` and |
| 27 | :math:`\mathbf{H}` are learned factor matrices with dimensions :math:`N |
| 28 | \times K` and :math:`K \times M`, respectively, and :math:`\alpha` is a |
| 29 | user-defined regularization weight. |
| 30 | |
| 31 | ALS proceeds by alternating between fixing **W** and optimizing for |
| 32 | **H** and fixing **H** and optimizing for **W**. Vanilla ALS has no |
| 33 | convergance guarantees and the objective function is prone to |
| 34 | oscillation across updates, particularly for dense input matrices [1]_. |
| 35 | |
| 36 | References |
| 37 | ---------- |
| 38 | .. [1] Gillis, N. (2014). The why and how of nonnegative matrix |
| 39 | factorization. *Regularization, optimization, kernels, and support |
| 40 | vector machines, 12(257)*, 257-291. |
| 41 | |
| 42 | Parameters |
| 43 | ---------- |
| 44 | K : int |
| 45 | The number of latent factors to include in the factor matrices W |
| 46 | and H. |
| 47 | alpha : float |
| 48 | The L2 regularization weight on the factor matrices. Larger |
| 49 | values result in more aggressive regularization. Default is 1. |
| 50 | max_iter : int |
| 51 | The maximum number of iterations to run before stopping. Default is |
| 52 | 200. |
| 53 | tol : float |
| 54 | The tolerance for the stopping condition. Default is 1e-4. |
| 55 | """ |
| 56 | self.K = K |
| 57 | self.W = None |
| 58 | self.H = None |
| 59 | self.tol = tol |
| 60 | self.alpha = alpha |
| 61 | self.max_iter = max_iter |
| 62 | |
| 63 | @property |
| 64 | def parameters(self): |
nothing calls this directly
no outgoing calls
no test coverage detected