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 optmu2 = mu2 print optmu, optmu2, optcor[0, 0] # train
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 stop = 4 score[(SP.nonzero(w0)[0])] += 1 elif err > opterr: stop -= 1 if stop <= 0: break freq[(SP.nonzero(optw)[0])] += 1 weight = weight + SP.absolute(optw)