optmu2 = mu2init optcor = 0 for j1 in range(7): for j2 in range(7): mu = muinit * (ps_step**j1) mu2 = mu2init * (ps_step**j2) cor = 0 for k in range(5): # 5 for full 5 fold CV train1_idx = SP.concatenate( (train_idx[:int(n_train * k * 0.2)], train_idx[int(n_train * (k + 1) * 0.2):n_train])) valid_idx = train_idx[int(n_train * k * 0.2):int(n_train * (k + 1) * 0.2)] res1 = lmm_lasso.train(X[train1_idx], K[train1_idx][:, train1_idx], y[train1_idx], mu, mu2, group) w1 = res1['weights'] yhat = lmm_lasso.predict(y[train1_idx], X[train1_idx, :], X[valid_idx, :], K[train1_idx][:, train1_idx], K[valid_idx][:, train1_idx], res1['ldelta0'], w1) cor += SP.dot(yhat.T - yhat.mean(), y[valid_idx] - y[valid_idx].mean()) / (yhat.std() * y[valid_idx].std()) print mu, mu2, cor[0, 0] if cor > optcor: optcor = cor optmu = mu
for k in range(n_reps): opterr = 10000 optw = 0 stop = 4 w0 = 0 nm = {} mu = muinit train_idx = SP.random.permutation(SP.arange(n_s)) for j in range(20): mu *= ps_step train1_idx = train_idx[:int(n_s * 0.8)] valid_idx = train_idx[int(n_s * 0.8):] res = lmm_lasso.train(X[train1_idx], K[train1_idx][:, train1_idx], y[train1_idx], mu, 0, [], w0=w0, null_model=nm) w0 = res['weights'] nm = res['null_model'] yhat = lmm_lasso.predict(y[train1_idx], X[train1_idx, :], X[valid_idx, :], K[train1_idx][:, train1_idx], K[valid_idx][:, train1_idx], res['ldelta0'], res['lstsq']) err = LA.norm(yhat - y[valid_idx]) print mu, err if err < opterr: optw = w0 opterr = err