Demo of NMF-SO and NMF-ARD-SO

[1] Motoki Shiga, Kazuyoshi Tatsumi, Shunsuke Muto, Koji Tsuda, Yuta Yamamoto, Toshiyuki Mori, Takayoshi Tanji, "Sparse Modeling of EELS and EDX Spectral Imaging Data by Nonnegative Matrix Factorization", Ultramicroscopy, Vol.170, p.43-59, 2016.


In [1]:
%matplotlib inline
import numpy as np
import scipy.io as sio
from libnmf import NMF, NMF_SO, NMF_ARD_SO

Generate a synthetic dataset with noise


In [2]:
#load theoretical data of Mn3O4 without noise
mat_dict = sio.loadmat('mn3o4_f2.mat')
ximage = mat_dict['datar']

# focusing channel
n_ch = np.arange(37-1,116);
ximage = ximage[:,:,n_ch];

# # of pixels along x and y axis, # of EELS channels
xdim,ydim,Nch = ximage.shape

#  generating pahtom data by adding gaussian noise
X = np.reshape(ximage, (xdim*ydim, Nch))
scale_spect = np.max(X)
s2_noise = 0.1  #noise variance
X = X + np.random.randn(xdim*ydim, Nch) * s2_noise * scale_spect;
X = (X + np.abs(X))/2;
scale_X = np.mean(X)
X = X / scale_X

NMF-SO


In [3]:
# define and training model
nmf_so = NMF_SO(n_components=2, wo=0.05, reps=3, max_itr=100)
nmf_so.fit(X, num_xy=(xdim,ydim), channel_vals=n_ch)


Training NMF with Soft Orthogonal constraint....
1th iteration of NMF-SO algorithm
2th iteration of NMF-SO algorithm
3th iteration of NMF-SO algorithm
Out[3]:
NMF_SO(n_components=2, wo=0.05, reps=3, max_itr=100, random_seed=0)

In [4]:
nmf_so.imshow_component(figsize=(6, 3))  # for 2D spactrum (Spectrum Imaging) dataset
# nmf.plot_component()   # for 1D spactrum dataset

nmf_so.plot_spectra(figsize=(6,3)) # plot decomposed spectra

nmf_so.plot_object_fun(figsize=(6,3)) # plot learnig curve (object function)


NMF-ARD-SO


In [5]:
# define and training model
nmf_ard = NMF_ARD_SO(n_components=9, wo=0.05, reps=3, max_itr=100)
nmf_ard.fit(X, num_xy=(xdim,ydim), channel_vals=n_ch)


Training NMF with ARD and Soft Orthogonal constraint....
1th iteration of NMF-ARD-SO algorithm
2th iteration of NMF-ARD-SO algorithm
3th iteration of NMF-ARD-SO algorithm
Out[5]:
NMF_ARD_SO(n_components=9, wo=0.05, reps=3, max_itr=100, alpha=1.000000000000001, threshold_merge=0.99, random_seed=0)

In [6]:
nmf_ard.plot_ard()  # plot learning curve with component intensities
nmf_ard.imshow_component(figsize=(6, 3))  # for 2D spactrum (Spectrum Imaging) dataset
nmf_ard.plot_spectra(figsize=(6,3)) # plot decomposed spectra
nmf_ard.plot_object_fun(figsize=(6,3)) # #plot learnig curve (object function)



In [ ]: