Updates on metric, whitespace

This commit is contained in:
Arnar Flatberg 2007-03-14 16:31:25 +00:00
parent 22f6e3284c
commit 7f1f639ee7

View File

@ -96,10 +96,11 @@ def procrustes(A, B, strict=True, center=False, verbose=False):
else:
return b_rot
def expl_var_x(X, T):
"""Returns explained variance of X."""
# centered X,Y
exp_var_x = diag(dot(T.T, T))*100/(sum(X**2))
def expl_var_x(Xc, T):
"""Returns explained variance of X.
T should carry variance in length, Xc has zero col-mean.
"""
exp_var_x = diag(dot(T.T, T))*100/(sum(Xc**2))
return exp_var_x
def expl_var_y(Y, T, Q):
@ -139,26 +140,28 @@ def pls_qvals(a, b, aopt=None, alpha=.3,
n_false = zeros((n, n_iter), dtype='<f8')
#full model
if metric!=None:
a = dot(a, metric)
if algo=='bridge':
dat = bridge(a, b, aopt, 'loads', 'fast')
else:
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,
alpha=alpha, crot=crot, strict=strict,
cov_center=cov_center, metric=metric)
cov_center=cov_center)
t0 = time.time()
Vs = shuffle_1d(b, n_iter)
for i,b_shuff in enumerate(Vs):
for i, b_shuff in enumerate(Vs):
t1 = time.time()
if algo=='bridge':
dat = bridge(a, b_shuff, aopt, 'loads','fast')
else:
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,
alpha=alpha, crot=crot, strict=strict,
cov_center=cov_center, metric=metric)
cov_center=cov_center)
print time.time() - t1
sort_index = argsort(tsq_full)[::-1]
back_sort_index = sort_index.argsort()
@ -210,7 +213,7 @@ def leverage(aopt=1,*args):
lev.append(lev_u)
return lev
def variances(a,t,p):
def variances(a, t, p):
"""Returns explained variance and ind. var from blm-params.
input:
a -- full centered matrix