""" loadings plot; shows, how flu on different freq-s affect PC; axis: em, ex, loading; figure per PC; ',' and '.' goes to next PC; lines should be smooth, so that flu on next freq-s affect PC in similar way; but they are not in large areas; there is an error; then we disable normalizing (/=std) data, and lines become smooth; scaling can prevent spectroscopic interpretation of loadings; we see peaks on em==ex; is it right, or we'd preprocess data in this area? idea: may be we'd normalize not by var (freq pair), but by em or ex; """ normalize=0 from numpy import load, array, arange from linre_tools import pcs_calc from linre_explorer import freq3d_save l = load('linre_big.npz') max_components = 7 pco = pcs_calc( exa=l['exa'], flum=l['flum'], max_components=max_components, no_peaks=1, recalc_wo_outliers=1, normalize=normalize, ret_loadings=1, ) freq3d_save('out14/loadings', ema=l['ema'], exa=l['exa'], data=pco.loadings, zlabel='Scaling coefficient', pga=['L'+str(i+1) for i in range(max_components)] )
""" residuals plot by variables (ex-em); """ max_components = 9 from numpy import load, array, arange, power, sqrt from linre_tools import pcs_calc from linre_explorer import freq3d_save l = load('linre_big.npz') pco = pcs_calc( exa=l['exa'], flum=l['flum'], max_components=max_components, no_peaks=1, recalc_wo_outliers=1, normalize=0, ret_X=1, ret_pca=1, ret_PC=1 ) def evar(X_fwd,X_back): return power(X_fwd-X_back,2).sum(axis=0) ## variance X = pco.X var0 = evar( X, X.mean(axis=0) ) ## mean in already 0 var = evar( X, pco.pca.inverse_transform(pco.PC) ) freq3d_save('out15/residuals', ema=l['ema'], exa=l['exa'], data=sqrt(var/var0)[None], pga=['residuals'] ) #sqrt(var/var0) print pco.pca.explained_variance_ratio_
""" pls: loadings explorer loadings are like cutten, what about making EX even less? higher component: more noise """ preprocess = 'pp_' #|'' from numpy import load, hstack from linre_tools import AttrDict from linre_explorer import freq3d_save l = AttrDict(load('linre_big.npz')) pls = AttrDict(load("out21/"+preprocess+"loadings.npz")) #print pls.y_loadings, l.ema.shape, l.exa.shape, pls.x_loadings.shape def annotate(pf,d): return map(lambda v:pf+str(v), range(d)) data = hstack((pls.x_loadings,pls.x_rotations)).T pga = annotate('L ',pls.x_loadings.shape[1]) + annotate('R ',pls.x_rotations.shape[1]) print pga freq3d_save("out22/"+preprocess+"loadings",ema=l.ema,exa=l.exa,data=data,pga=pga)
def show3d(preprocess): coefs, x_mean, y_mean = load_pls(preprocess) print y_mean data = hstack((coefs, x_mean)).T pga = ['coefs','x_mean'] freq3d_save("out27/a"+preprocess,ema=ema,exa=exa,data=data,pga=pga) #not final plot
from numpy import load from linre_tools import AttrDict from linre_explorer import freq3d_save for fn in ['linre_big','linre_big2']: l = AttrDict(load(fn+'.npz')) freq3d_save(fn, ema=l.ema, exa=l.exa, data=l.flum.T, pga=l.expa, zlabel='Fluorescence' )