from scipy import ones,mean,sqrt,dot,newaxis,zeros,sum,empty,\ apply_along_axis,eye, kron from scipy.linalg import triu,inv,svd,norm from select_generators import w_pls_gen,w_pls_gen_jk,pls_gen,pca_gen,diag_pert from engines import w_simpls,pls, bridge,pca from pylab import * def w_pls_cv_val(X, Y, amax, n_blocks=None, algo='simpls'): """RMSEP calc for pls with wide X. """ k, l = Y.shape PRESS = zeros((l, amax+1), dtype='f') # X,Y are centered if n_blocks==None: n_blocks = Y.shape[0] V = w_pls_gen(dot(X, X.T), Y, n_blocks=n_blocks, center=True) for Din, Doi, Yin, Yout in V: ym = -sum(Yout, 0)[newaxis]/(1.0*Yin.shape[0]) Yin = Yin - ym PRESS[:,0] = PRESS[:,0] + ((Yout - ym)**2).sum(0) if algo=='simpls': dat = w_simpls(Din, Yin, amax) Q,U,H = dat['Q'], dat['U'], dat['H'] That = dot(Doi, dot(U, inv(triu(dot(H.T,U))) )) else: "Other algo-support comming soon" raise NotImplementedError #Yhat = empty((amax, k, l),dtype='