Updates on metric, whitespace
This commit is contained in:
parent
22f6e3284c
commit
7f1f639ee7
|
@ -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,26 +140,28 @@ 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):
|
||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
if algo=='bridge':
|
if algo=='bridge':
|
||||||
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()
|
||||||
|
@ -210,7 +213,7 @@ def leverage(aopt=1,*args):
|
||||||
lev.append(lev_u)
|
lev.append(lev_u)
|
||||||
return lev
|
return lev
|
||||||
|
|
||||||
def variances(a,t,p):
|
def variances(a, t, p):
|
||||||
"""Returns explained variance and ind. var from blm-params.
|
"""Returns explained variance and ind. var from blm-params.
|
||||||
input:
|
input:
|
||||||
a -- full centered matrix
|
a -- full centered matrix
|
||||||
|
|
Reference in New Issue