Issue with Non-negative Matrix Factorization

676 views
Skip to first unread message

Jordan Hachtel

unread,
Jan 8, 2018, 6:25:20 PM1/8/18
to hyperspy-users
Hello all,

I have what could likely be a very naive question. I am attempting to use non-negative matrix factorization on a spectrum image. Normal decomposition works just fine, but when I try to run with algorithm = 'nmf' I get the following error.

SI=hs.load(pathtodm3SI)
SI.decomposition(algorithm='nmf')

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-341-4312a4040e32> in <module>()
      1 SI=hs.load(pathtodm3SI)
----> 2 SI.decomposition(algorithm='nmf')

~/anaconda2/envs/Py3/lib/python3.6/site-packages/hyperspy/learn/mva.py in decomposition(self, normalize_poissonian_noise, algorithm, output_dimension, centre, auto_transpose, navigation_mask, signal_mask, var_array, var_func, polyfit, reproject, return_info, **kwargs)
    274                 sk.n_components = output_dimension
    275                 loadings = sk.fit_transform((
--> 276                     dc[:, signal_mask][navigation_mask, :]))
    277                 factors = sk.components_.T
    278                 if return_info:

~/anaconda2/envs/Py3/lib/python3.6/site-packages/sklearn/decomposition/nmf.py in fit_transform(self, X, y, W, H)
   1032             shuffle=self.shuffle,
   1033             nls_max_iter=self.nls_max_iter, sparseness=self.sparseness,
-> 1034             beta=self.beta, eta=self.eta)
   1035 
   1036         if self.solver == 'pg':

~/anaconda2/envs/Py3/lib/python3.6/site-packages/sklearn/decomposition/nmf.py in non_negative_factorization(X, W, H, n_components, init, update_H, solver, tol, max_iter, alpha, l1_ratio, regularization, random_state, verbose, shuffle, nls_max_iter, sparseness, beta, eta)
    743 
    744     X = check_array(X, accept_sparse=('csr', 'csc'))
--> 745     check_non_negative(X, "NMF (input X)")
    746     _check_string_param(sparseness, solver)
    747 

~/anaconda2/envs/Py3/lib/python3.6/site-packages/sklearn/utils/validation.py in check_non_negative(X, whom)
    705     X = X.data if sp.issparse(X) else X
    706     if (X < 0).any():
--> 707         raise ValueError("Negative values in data passed to %s" % whom)

ValueError: Negative values in data passed to NMF (input X)

I have checked over the data in the Spectrum Image through my other means of analysis and there doesn't seem to be any strangeness in my data that could trip up the algorithm. Any suggestions or pieces of advice would be greatly appreciated.

Francisco de la Peña

unread,
Jan 9, 2018, 3:52:03 AM1/9/18
to hypersp...@googlegroups.com
Hi Jordan,

The issue is that your data contains negative values. If your data is positive but you get negative values due to noise or a wrong offset, in order to use NMF you could mask the negative values, set them to zero or add a common offset to the data. The best solution depends on the source of the negative values in your data.

Best regards,

Francisco

--
You received this message because you are subscribed to the Google Groups "hyperspy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hyperspy-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages