Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Updates on metric, whitespace

This commit is contained in:
Arnar Flatberg 2007-03-14 16:31:25 +00:00
parent 22f6e3284c
commit 7f1f639ee7
1 changed files with 13 additions and 10 deletions

View File

@ -96,10 +96,11 @@ def procrustes(A, B, strict=True, center=False, verbose=False):
else: else:
return b_rot return b_rot
def expl_var_x(X, T): def expl_var_x(Xc, T):
"""Returns explained variance of X.""" """Returns explained variance of X.
# centered X,Y T should carry variance in length, Xc has zero col-mean.
exp_var_x = diag(dot(T.T, T))*100/(sum(X**2)) """
exp_var_x = diag(dot(T.T, T))*100/(sum(Xc**2))
return exp_var_x return exp_var_x
def expl_var_y(Y, T, Q): def expl_var_y(Y, T, Q):
@ -139,14 +140,16 @@ def pls_qvals(a, b, aopt=None, alpha=.3,
n_false = zeros((n, n_iter), dtype='<f8') n_false = zeros((n, n_iter), dtype='<f8')
#full model #full model
if metric!=None:
a = dot(a, metric)
if algo=='bridge': if algo=='bridge':
dat = bridge(a, b, aopt, 'loads', 'fast') dat = bridge(a, b, aopt, 'loads', 'fast')
else: else:
dat = pls(a, b, aopt, 'loads', 'fast') dat = pls(a, b, aopt, 'loads', 'fast')
Wcv = pls_jkW(a, b, aopt, n_blocks=None, algo=algo) Wcv = pls_jkW(a, b, aopt, n_blocks=None, algo=algo, metric=metric)
tsq_full = hotelling(Wcv, dat['W'], p_center=p_center, tsq_full = hotelling(Wcv, dat['W'], p_center=p_center,
alpha=alpha, crot=crot, strict=strict, alpha=alpha, crot=crot, strict=strict,
cov_center=cov_center, metric=metric) cov_center=cov_center)
t0 = time.time() t0 = time.time()
Vs = shuffle_1d(b, n_iter) Vs = shuffle_1d(b, n_iter)
for i, b_shuff in enumerate(Vs): for i, b_shuff in enumerate(Vs):
@ -155,10 +158,10 @@ def pls_qvals(a, b, aopt=None, alpha=.3,
dat = bridge(a, b_shuff, aopt, 'loads','fast') dat = bridge(a, b_shuff, aopt, 'loads','fast')
else: else:
dat = pls(a, b, aopt, 'loads', 'fast') dat = pls(a, b, aopt, 'loads', 'fast')
Wcv = pls_jkW(a, b_shuff, aopt, n_blocks=None, algo=algo) Wcv = pls_jkW(a, b_shuff, aopt, n_blocks=None, algo=algo, metric=metric)
TSQ[:,i] = hotelling(Wcv, dat['W'], p_center=p_center, TSQ[:,i] = hotelling(Wcv, dat['W'], p_center=p_center,
alpha=alpha, crot=crot, strict=strict, alpha=alpha, crot=crot, strict=strict,
cov_center=cov_center, metric=metric) cov_center=cov_center)
print time.time() - t1 print time.time() - t1
sort_index = argsort(tsq_full)[::-1] sort_index = argsort(tsq_full)[::-1]
back_sort_index = sort_index.argsort() back_sort_index = sort_index.argsort()