You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm playing around with the faces example, and the sparseness metric seems to be acting a little strange in some cases (the code is here).
I pulled it out to test it in different cases:
def sparseness_nimfa(x):
"""
reimplementation of sparseness measure
"""
from nimfa.utils.linalg import multiply
eps = np.finfo(x.dtype).eps if 'int' not in str(x.dtype) else 1e-9
x1 = np.sqrt(x.size) - (abs(x).sum() + eps) / \
(np.sqrt(multiply(x, x).sum()) + eps)
x2 = np.sqrt(x.size) - 1
return x1 / x2
This is the function that sparseness() averages over for W and H. The problem is that for an array of zeros, the above returns a 1, and we want it to return a 0. This happens fairly frequently in practice with some parameter settings for NMF.
What I have personally been doing is checking to see if the input is an array of zeros (within some rounding error), and if so, return 0. This hack seems to work well when W/H are nonnegative (though be careful of the more general case).
The text was updated successfully, but these errors were encountered:
I'm playing around with the faces example, and the sparseness metric seems to be acting a little strange in some cases (the code is here).
I pulled it out to test it in different cases:
This is the function that
sparseness()
averages over for W and H. The problem is that for an array of zeros, the above returns a 1, and we want it to return a 0. This happens fairly frequently in practice with some parameter settings for NMF.To test it:
What I have personally been doing is checking to see if the input is an array of zeros (within some rounding error), and if so, return 0. This hack seems to work well when W/H are nonnegative (though be careful of the more general case).
The text was updated successfully, but these errors were encountered: