Finnished the l-pls fdr

This commit is contained in:
Arnar Flatberg 2007-09-21 13:16:40 +00:00
parent 6698ebe932
commit 18f33decc7

View File

@ -4,9 +4,10 @@ from scipy import zeros,zeros_like,sqrt,dot,trace,sign,round_,argmax,\
from scipy.linalg import svd,inv,norm,det,sqrtm
from scipy.stats import mean,median
from cx_utils import mat_center
from validation import pls_jkW
from validation import pls_jkW, lpls_jk
from select_generators import shuffle_1d
from engines import *
from engines import pca, pls, bridge
from engines import nipals_lpls as lpls
import time
@ -362,8 +363,9 @@ def mahalanobis(a, loc=None, acov=None, invcov=None):
mdist = (dot(xc, covmat)*xc).sum(1)
return mdist
def lpls_qvals(a, b, c, aopt=None, alpha=.3, zx_alpha=.5, n_iter=20,center=True,
sim_method='shuffle',p_center='med', cov_center='med',crot=True, strict=False):
def lpls_qvals(a, b, c, aopt=None, alpha=.3, zx_alpha=.5, n_iter=20,
sim_method='shuffle',p_center='med', cov_center='med',crot=True,
strict=False, mean_ctr=[2,0,2]):
"""Returns qvals for l-pls model.
@ -383,32 +385,29 @@ def lpls_qvals(a, b, c, aopt=None, alpha=.3, zx_alpha=.5, n_iter=20,center=True,
"""
m, n = a.shape
TSQ = zeros((n, n_iter), dtype='d') # (nvars x n_subsets)
n_false = zeros((n, n_iter), dtype='d')
p, k = c.shape
pert_tsq_x = zeros((n, n_iter), dtype='d') # (nxvars x n_subsets)
pert_tsq_z = zeros((p, n_iter), dtype='d') # (nzvars x n_subsets)
# Full model
dat = lpls(a, b, c, aopt, scale='loads')
Wcv = lpls_jk(a, b, c ,aopt, n_blocks=None, algo=algo,center=center)
tsq_x = hotelling(Wcv, dat['W'], p_center=p_center,alpha=alpha, crot=crot, strict=strict,
cov_center=cov_center)
Lcv = lpls_jk(a, b, c ,aopt, n_blocks=None, algo=algo,center=center)
tsq_z = hotelling(Lcv, dat['L'], p_center=p_center,alpha=alpha, crot=crot, strict=strict,
cov_center=cov_center)
#print "Full model start"
dat = lpls(a, b, c, aopt, scale='loads', mean_ctr=mean_ctr)
Wc,Lc = lpls_jk(a, b, c ,aopt)
#print "Full hot"
cal_tsq_x = hotelling(Wc, dat['W'], alpha=alpha)
cal_tsq_z = hotelling(Lc, dat['L'], alpha=alpha)
# Perturbations
t0 = time.time()
Vs = shuffle_1d(b, n_iter, axis=0)
for i, b_shuff in enumerate(Vs):
t1 = time.time()
dat = pls(ac, b_shuff, aopt, 'loads', 'fast')
Wcv = pls_jkW(a, b_shuff, aopt, n_blocks=None, algo=algo)
TSQ[:,i] = hotelling(Wcv, dat['W'], p_center=p_center,
alpha=alpha, crot=crot, strict=strict,
cov_center=cov_center)
print time.time() - t1
#print i
time.sleep(.01)
dat = lpls(a, b_shuff,c, aopt, scale='loads', mean_ctr=mean_ctr)
Wi, Li = lpls_jk(a, b_shuff, c, aopt)
pert_tsq_x[:,i] = hotelling(Wi, dat['W'], alpha=alpha)
pert_tsq_z[:,i] = hotelling(Li, dat['L'], alpha=alpha)
return fdr(tsq_full, TSQ, median)
return fdr(cal_tsq_z, pert_tsq_z, median), fdr(cal_tsq_x, pert_tsq_x, median)