In [1]:
%matplotlib inline
import numpy as np
import scipy.io as sio
from libnmf import MultiNMF, MultiNMF_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
X = [X,X]
In [5]:
# define and training model
nmf_so = MultiNMF_SO(n_components=2, wo=0.05, reps=3, max_itr=100)
nmf_so.fit(X, weight_source=[0.1,0.9], num_xy=(xdim,ydim), channel_vals=n_ch)
Out[5]:
In [6]:
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 [ ]: