results[m] = np.zeros((n_repeat, n_train_tasks.size)) for rep in xrange(n_repeat): print rep x_train, y_train = dataset.resample(n_task, n) x_test = dataset.test['x_test'] y_test = dataset.test['y_test'] for index, t in np.ndenumerate(n_train_tasks): x_temp = x_train[0:np.cumsum(n_ex)[t], :] y_temp = y_train[0:np.cumsum(n_ex)[t], :] if p < 10: s_hat = subset_search.subset(x_temp, y_temp, n_ex[0:t], delta=alpha_test, valid_split=0.6, use_hsic=use_hsic) # Pooled lr_temp = linear_model.LinearRegression() lr_temp.fit(x_temp, y_temp) results['pool'][rep, index] = utils.mse(lr_temp, x_test, y_test) # Mean error_mean = np.mean((y_test - np.mean(y_temp))**2) results['mean'][rep, index] = error_mean # Estimated S if p < 10: if s_hat.size > 0:
train_x_ul_a = np.concatenate(train_x_ul, axis=0) for s in range(samp_array.size): samp = samp_array[s] draw_train = samp mask = mask_training_tasks(n_task, draw_train, train_x_lab_a.shape[0], p) train_x = train_x_lab_a[mask].reshape((n_task * draw_train, p)) train_y = train_y_lab_a[mask[:, 0]].reshape((n_task * draw_train, 1)) sub_list = subset_search.subset(train_x, train_y, np.array(n_task * [samp]), delta=alpha_test, valid_split=0.6, use_hsic=False, return_n_best=3) if len(sub_list) == 0: sub_list.append(np.array([])) #-------------------------------------------- #Errors with DA #-------------------------------------------- train_cov_mats = dataset.true_cov() ns = train_x.shape[0] probas = np.linspace(0.01, 1, 10) times = []
x2 = gamma_task * y + np.random.normal(0, sx2, (n_examples_task, 1)) x_task = np.concatenate([x1, x2, x3], axis=1) test_x = np.append(test_x, x_task, axis=0) test_y = np.append(test_y, y) test_x = test_x[1:, :] test_y = test_y[1:, np.newaxis] #--------------------------------------------------------------- #Estimate subset #--------------------------------------------------------------- s_hat = subset_search.subset(train_x, train_y, n_ex, valid_split=0.5, delta=0.05, use_hsic=use_hsic) s_hat_greedy = subset_search.greedy_subset(train_x, train_y, n_ex, valid_split=0.5, delta=0.05, use_hsic=use_hsic) print "TRANSFER LEARNING: NO LABELED EX. FROM TEST AT TRAINING TIME" print print "The complete subset of predictors:" print tuple(np.arange(train_x.shape[1])) print "The true causal set for this problem:" print(0, 2)
t = n_train_tasks[0] for rep in xrange(n_repeat): print rep x_train, y_train = dataset.resample(n_task, n) x_test = dataset.test['x_test'] y_test = dataset.test['y_test'] for index, delta in np.ndenumerate(deltas): x_temp = x_train[0:np.cumsum(n_ex)[t], :] y_temp = y_train[0:np.cumsum(n_ex)[t], :] if p<10: s_hat = subset_search.subset(x_temp, y_temp, n_ex[0:t], delta=delta, use_hsic=use_hsic, valid_split=0.8) # Pooled lr_temp = linear_model.LinearRegression() lr_temp.fit(x_temp, y_temp) results['pool'][rep, index] = utils.mse(lr_temp, x_test, y_test) ## Mean error_mean = np.mean((y_test - np.mean(y_temp))**2) #results['mean'][rep, index] = error_mean # Estimated S if p<10: if s_hat.size> 0: lr_s_temp = linear_model.LinearRegression()
count = np.zeros((len(dif_inter), p)) for ind_l, l_d in enumerate(dif_inter): for rep in xrange(n_repeat): where_to_intervene = l_d mask = utils.intervene_on_p(where_to_intervene, p - p_s) dataset = data.gauss_tl(n_task, n, p, p_s, p_conf, eps, g, lambd, lambd_test, mask) x_train = dataset.train['x_train'] y_train = dataset.train['y_train'] s_hat = subset_search.subset(x_train, y_train, dataset.n_ex, valid_split=0.6, delta=alpha_test, use_hsic=use_hsic) for pred in xrange(p): if pred in s_hat: count[ind_l, pred] += 1 #Save pickle save_all = {'count': count, 'n_repeat': n_repeat, 'inter': dif_inter} with open(os.path.join(save_dir, file_name + '.pkl'), 'wb') as f: pickle.dump(save_all, f) #Create plot plotting.plot_interv(os.path.join(save_dir, file_name + '.pkl'))