@@ -415,17 +415,18 @@ def rss(self, idx=None):
415415 def sparseness (self , idx = None ):
416416 """
417417 Compute sparseness of matrix (basis vectors matrix, mixture coefficients) [Hoyer2004]_.
418- This sparseness measure quantifies how much energy of a vector is packed into only
419- few components. The sparseness of a vector is a real number in [0, 1]. Sparser vector
420- has value closer to 1. The measure is 1 iff vector contains single
421- nonzero component and the measure is equal to 0 iff all components are equal.
418+
419+ Sparseness of a vector quantifies how much energy is packed into its components.
420+ The sparseness of a vector is a real number in [0, 1], where sparser vector
421+ has value closer to 1. Sparseness is 1 iff the vector contains a single
422+ nonzero component and is equal to 0 iff all components of the vector are equal.
422423
423- Sparseness of a matrix is the mean sparseness of its column vectors.
424+ Sparseness of a matrix is mean sparseness of its column vectors.
424425
425426 Return tuple that contains sparseness of the basis and mixture coefficients matrices.
426427
427- :param idx: Used in the multiple NMF model. In factorizations following
428- standard NMF model or nonsmooth NMF model ``idx`` is always None.
428+ :param idx: Used in the multiple NMF model. In standard NMF model or nonsmooth NMF
429+ model ``idx`` is always None.
429430 :type idx: None or `str` with values 'coef' or 'coef1' (`int` value of 0 or 1, respectively)
430431 """
431432 def sparseness (x ):
@@ -436,7 +437,9 @@ def sparseness(x):
436437 return x1 / x2
437438 W = self .basis ()
438439 H = self .coef (idx )
439- return np .mean ([sparseness (W [:, i ]) for i in range (W .shape [1 ])]), np .mean ([sparseness (H [:, i ]) for i in range (H .shape [1 ])])
440+ spars_W = np .mean ([sparseness (W [:, i ]) for i in range (W .shape [1 ])])
441+ spars_H = np .mean ([sparseness (H [:, i ]) for i in range (H .shape [1 ])])
442+ return spars_W , spars_H
440443
441444 def coph_cor (self , idx = None ):
442445 """
0 commit comments