MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / _init_factor_matrices

Method _init_factor_matrices

numpy_ml/factorization/factors.py:227–245  ·  view source on GitHub ↗

Initialize the factor matrices using vanilla ALS

(self, X, W, H)

Source from the content-addressed store, hash-verified

225 }
226
227 def _init_factor_matrices(self, X, W, H):
228 """Initialize the factor matrices using vanilla ALS"""
229 ALS = None
230 N, M = X.shape
231
232 # initialize factors using ALS if not already defined
233 if W is None:
234 ALS = VanillaALS(self.K, alpha=0, max_iter=200)
235 ALS.fit(X, verbose=False)
236 W = ALS.W / np.linalg.norm(ALS.W, axis=0)
237
238 if H is None:
239 H = np.abs(np.random.rand(self.K, M)) if ALS is None else ALS.H
240
241 assert W.shape == (N, self.K)
242 assert H.shape == (self.K, M)
243
244 self.H = H
245 self.W = W
246
247 def _loss(self, X, Xhat):
248 """Return the least-squares reconstruction loss between X and Xhat"""

Callers 1

_fitMethod · 0.95

Calls 2

fitMethod · 0.95
VanillaALSClass · 0.85

Tested by

no test coverage detected