Commit b97d94c6 by Maxime

### Code for beta_div != 1

parent dd9fedb2
 ... ... @@ -4,7 +4,7 @@ Sparse NMF Example script for Sparse NMF with beta-divergence distortion function and L1 penalty on the activations. # Disclaimer This port has not been fully tested, and so far only the algorithm only runs with `beta_div=1`. This port has not been fully tested, especially with parameters `beta_div != 1`. # Copyright notice and License Copyright (C) 2015 Mitsubishi Electric Research Labs ... ...
 ... ... @@ -96,7 +96,7 @@ def sparse_nmf(v, beta=1, cf='kl', sparsity=0, max_iter=100, conv_eps=0, if init_h is None: ## init h h = np.random.rand(r,n) elif init_h=='ones': # what the hell is that?? elif init_h=='ones': print('INFO: initializing H with ones') h = np.ones((r,n)) else: ... ... @@ -111,20 +111,16 @@ def sparse_nmf(v, beta=1, cf='kl', sparsity=0, max_iter=100, conv_eps=0, if type(sparsity) in (int, float): # sparsity per matrix entry sparsity = np.ones((r,n))*sparsity elif sparsity.shape[1] == 1: sparsity = repmat(sparsity, 1, n) ## to debug, use numpy sparsity = np.tile(sparsity, (1,n)) ## to debug ## Normalize the columns of W and rescale H accordingly wn = ((w**2).sum(axis=0))**0.5 w = w/np.tile(wn, (w.shape[0], 1)) ## surely wrong h = h*np.tile(wn, (h.shape[1], 1)).T ##wn = sqrt(sum(w.^2)); ##w = bsxfun(@rdivide,w,wn); ##h = bsxfun(@times, h,wn'); wn = ((w**2).sum(axis=0))**0.5 ##wn = sqrt(sum(w.^2)); w = w/np.tile(wn, (w.shape[0], 1)) ##w = bsxfun(@rdivide,w,wn); h = h*np.tile(wn, (h.shape[1], 1)).T ##h = bsxfun(@times, h,wn'); ## Internal parameters flr = 1e-9 lamb = w.dot(h) # used to be lambda lamb = w.dot(h) # used to be lambda (but lambda is a reserved keyword in Python) lamb[lamb
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!