def perform_me_test(train_miss_impute, test_miss_impute, train_full, test_full, alpha, test_locs_miss=None, gwidth_miss=None, test_locs_full=None, gwidth_full=None): me_result = np.zeros(2) op = { 'n_test_locs': 10, # number of test locations to optimize 'max_iter': 200, # maximum number of gradient ascent iterations 'locs_step_size': 1.0, # step size for the test locations (features) 'gwidth_step_size': 0.1, # step size for the Gaussian width 'tol_fun': 1e-4, # stop if the objective does not increase more than this. 'seed': 0 # random seed } sb_data_miss_impute = TSTData(train_miss_impute, test_miss_impute) train_miss_impute_sb, dumy = sb_data_miss_impute.split_tr_te( tr_proportion=1, seed=1) dumy, test_miss_impute_sb = sb_data_miss_impute.split_tr_te( tr_proportion=0, seed=1) #half_size = int(train_miss_impute.shape[0]/2) #train_miss_impute_sb = TSTData(train_miss_impute[:half_size], train_miss_impute[half_size:half_size*2]) #test_miss_impute_sb = TSTData(train_miss_impute, test_miss_impute) if test_locs_miss is None: test_locs_miss, gwidth_miss, info = tst.MeanEmbeddingTest.optimize_locs_width( train_miss_impute_sb, alpha, **op) met_opt = tst.MeanEmbeddingTest(test_locs_miss, gwidth_miss, alpha) test_result = met_opt.perform_test(test_miss_impute_sb) if test_result['h0_rejected']: me_result[0] = 1 sb_data_full = TSTData(train_full, test_full) train_full_sb, dumy = sb_data_full.split_tr_te(tr_proportion=1, seed=1) dumy, test_full_sb = sb_data_full.split_tr_te(tr_proportion=0, seed=1) if test_locs_full is None: test_locs_full, gwidth_full, info = tst.MeanEmbeddingTest.optimize_locs_width( train_full_sb, alpha, **op) met_opt = tst.MeanEmbeddingTest(test_locs_full, gwidth_full, alpha) test_result = met_opt.perform_test(test_full_sb) if test_result['h0_rejected']: me_result[1] = 1 return me_result, test_locs_miss, gwidth_miss, test_locs_full, gwidth_full
def perform_mmd_test(train_miss_impute, test_miss_impute, train_full, test_full, alpha, mmd_miss_impute=None, mmd_full=None): mmd_result = np.zeros(2) sb_data_miss_impute = TSTData(train_miss_impute, test_miss_impute) if mmd_miss_impute is None: print('ini') x, y = sb_data_miss_impute.xy() dist_mat_miss_impute = metrics.pairwise_distances(x, y) the_kernel = kernel.KGauss(dist_mat_miss_impute.std()) mmd_miss_impute = tst.QuadMMDTest(the_kernel, alpha=alpha) test_result = mmd_miss_impute.perform_test(sb_data_miss_impute) if test_result['h0_rejected']: mmd_result[0] = 1 sb_data_full = TSTData(train_full, test_full) if mmd_full is None: x, y = sb_data_full.xy() dist_mat_full = metrics.pairwise_distances(x, y) the_kernel = kernel.KGauss(dist_mat_full.std()) mmd_full = tst.QuadMMDTest(the_kernel, alpha=alpha) test_result = mmd_full.perform_test(sb_data_full) if test_result['h0_rejected']: mmd_result[1] = 1 return mmd_result, mmd_miss_impute, mmd_full
def perform_mmd_test(train_miss_impute, test_miss_impute, train_full, test_full, alpha, mmd_miss_impute=None, mmd_full=None): mmd_result = np.zeros(2) sb_data_miss_impute = TSTData(train_miss_impute, test_miss_impute) if mmd_miss_impute is None: print('ini') the_kernel = kernel.KGauss(sb_data_miss_impute.mean_std()) mmd_miss_impute = tst.QuadMMDTest(the_kernel, alpha=alpha) test_result = mmd_miss_impute.perform_test(sb_data_miss_impute) if test_result['h0_rejected']: mmd_result[0] = 1 sb_data_full = TSTData(train_full, test_full) if mmd_full is None: the_kernel = kernel.KGauss(sb_data_full.mean_std()) mmd_full = tst.QuadMMDTest(the_kernel, alpha=alpha) test_result = mmd_full.perform_test(sb_data_full) if test_result['h0_rejected']: mmd_result[1] = 1 return mmd_result, mmd_miss_impute, mmd_full