In [1]:
%matplotlib inline
import numpy as np
import scipy.io as sio
from libnmf import NMF, NMF_SO, NMF_ARD_SO
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
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)
Out[3]:
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)
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)
Out[5]:
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 [ ]: