def moyenneMMD_MC(methodeMMD, kernel, law_p, law_q, m, n, repeat=100, verbose=1): mmd_list = np.zeros(repeat) for i in range(repeat): if verbose > 0: print(i / repeat * 100, '% achevé', end='\r', flush=True) X_ = law_p(m) Y_ = law_q(n) MMD = methodeMMD(kernel) MMD.fit(Y_, X_) mmd_list[i] = MMD.MMD return mmd_list.mean()
def moyenneMMD_Bt(methodeMMD, kernel, X, Y, n_boot, m_boot, repeat=100, verbose=1): mmd_list = np.zeros(repeat) for i in range(repeat): if verbose > 0: print(i / repeat * 100, '% achevé', end='\r', flush=True) X_ = utils.bootstrap(X, m_boot) Y_ = utils.bootstrap(Y, n_boot) MMD = methodeMMD(kernel) MMD.fit(Y_, X_) mmd_list[i] = MMD.MMD return mmd_list.mean()
def sampleMMD_MC(methodeMMD, kernel, law_p, law_q, m, n, finalSampleSize=1000, verbose=1): Liste_mmdl = [] for _ in range(finalSampleSize): if verbose > 0: print(_ / finalSampleSize * 100, '% achevé', end='\r', flush=True) X = law_p(m) Y = law_q(n) MMD = methodeMMD(kernel) MMD.fit(Y, X) Liste_mmdl.append(MMD.MMD) return np.r_[Liste_mmdl]
# Compute U-statistics and bootstrap intervals ksd_stats, _ = ksd_est([kappa_vals]) ksd_boot_list, ksd_thres_list = ksd_boot([kappa_vals]) ksd_pvals = ksd_pvalue(ksd_boot_list, ksd_stats) ksd_stat = ksd_stats[0] ksd_thres = ksd_thres_list[0] ksd_pval = ksd_pvals[0] ksd_pred = 1 * (ksd_stat > ksd_thres) # 0 for p, 1 for q # ------------------------- Perform MMD test ------------------------- # print "Performing MMD test ..." mmd = MMD(kernel_fun=wl_kernel) mmd_stat, mmd_thres, mmd_pval, _ = mmd.perform_test(samples_p, samples_q) mmd_pred = 1 * (mmd_stat > mmd_thres) # 0 for p, 1 for q res = {'n': n, 'param0': [rho0, theta0, tau0], 'param': [rho, theta, tau], 'true_dist': true_dist, 'ksd_stat': ksd_stat, 'ksd_thres': ksd_thres, 'ksd_pval': ksd_pval, 'ksd_pred': ksd_pred, 'mmd_stat': mmd_stat, 'mmd_thres': mmd_thres, 'mmd_pval': mmd_pval, 'mmd_pred': mmd_pred} pckl_write(res, res_dir + "pow-ergm-n%d-d%d-rho%.3f-theta%.3f-tau%.3f-seed%d.res" % (n, d, rho, theta, tau, seed)) print 'Finished!'