"""This module implements some common validation schemes from pca and pls. """ from scipy import ones,mean,sqrt,dot,newaxis,zeros,sum,empty,\ apply_along_axis,eye,kron,array,sort from scipy.stats import median 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 cx_utils import m_shape def w_pls_cv_val(X, Y, amax, n_blocks=None, algo='simpls'): """Returns and RMSEP for pls tailored for wide X. """ k, l = m_shape(Y) PRESS = zeros((l, amax+1), dtype='f') # X,Y are centered0 if n_blocks==None: n_blocks = Y.shape[0] XXt = dot(X, X.T) V = w_pls_gen(XXt, 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: raise NotImplementedError #Yhat = empty((amax, k, l),dtype='