def job_nfsicJ3_opt(paired_source, tr, te, r, J=3): """NFSIC with test locations optimzied. """ with util.ContextTimer() as t: nfsic_opt_options = { 'n_test_locs': J, 'max_iter': 200, 'V_step': 1, 'W_step': 1, 'gwidthx_step': 1, 'gwidthy_step': 1, 'batch_proportion': 1.0, 'tol_fun': 1e-4, 'step_pow': 0.5, 'seed': r + 2, 'reg': 1e-6 } op_V, op_W, op_gwx, op_gwy, info = it.GaussNFSIC.optimize_locs_widths( tr, alpha, **nfsic_opt_options) nfsic_opt = it.GaussNFSIC(op_gwx, op_gwy, op_V, op_W, alpha, reg='auto', seed=r + 3) nfsic_opt_result = nfsic_opt.perform_test(te) return { 'indtest': nfsic_opt, 'test_result': nfsic_opt_result, 'time_secs': t.secs }
def job_nfsic_grid(paired_source, tr, te, r): """ NFSIC where the test locations are randomized, and the Gaussian widths are optimized by a grid search. """ # randomize the test locations by fitting Gaussians to the data with util.ContextTimer() as t: V, W = it.GaussNFSIC.init_locs_2randn(tr, J, seed=r + 2) xtr, ytr = tr.xy() n_gwidth_cand = 30 gwidthx_factors = 2.0**np.linspace(-4, 4, n_gwidth_cand) gwidthy_factors = gwidthx_factors #gwidthy_factors = 2.0**np.linspace(-3, 4, 40) medx = util.meddistance(xtr, 1000) medy = util.meddistance(ytr, 1000) list_gwidthx = np.hstack(((medx**2) * gwidthx_factors)) list_gwidthy = np.hstack(((medy**2) * gwidthy_factors)) bestij, lambs = it.GaussNFSIC.grid_search_gwidth( tr, V, W, list_gwidthx, list_gwidthy) # These are width^2 best_widthx = list_gwidthx[bestij[0]] best_widthy = list_gwidthy[bestij[1]] # perform test nfsic_grid = it.GaussNFSIC(best_widthx, best_widthy, V, W, alpha) nfsic_grid_result = nfsic_grid.perform_test(te) return { 'indtest': nfsic_grid, 'test_result': nfsic_grid_result, 'time_secs': t.secs }
def job_nfsicJ10_stoopt(paired_source, tr, te, r, n_permute=None): J = 10 k, l = kl_kgauss_median(tr) medx2 = k.sigma2 medy2 = l.sigma2 fac_min = 5e-2 fac_max = 5e3 with util.ContextTimer() as t: nfsic_opt_options = { 'n_test_locs': J, 'max_iter': 100, 'V_step': 1, 'W_step': 1, 'gwidthx_step': 1, 'gwidthy_step': 1, 'batch_proportion': 1, 'tol_fun': 1e-4, 'step_pow': 0.5, 'seed': r + 2, 'reg': 1e-6, 'gwidthx_lb': medx2 * 1e-3, 'gwidthx_ub': medx2 * 1e3, 'gwidthy_lb': medy2 * 1e-3, 'gwidthy_ub': medy2 * 1e3 } op_V, op_W, op_gwx, op_gwy, info = it.GaussNFSIC.optimize_locs_widths( tr, alpha, **nfsic_opt_options) # make sure the optimized widths are not too extreme #last_gwx = info['gwidthxs'][-1] #last_gwy = info['gwidthys'][-1] #op_gwx = last_gwx #op_gwy = last_gwy op_gwx = max(fac_min * medx2, 1e-5, min(fac_max * medx2, op_gwx)) op_gwy = max(fac_min * medy2, 1e-5, min(fac_max * medy2, op_gwy)) nfsic_opt = it.GaussNFSIC(op_gwx, op_gwy, op_V, op_W, alpha=alpha, reg='auto', n_permute=n_permute, seed=r + 3) nfsic_opt_result = nfsic_opt.perform_test(te) return { 'indtest': nfsic_opt, 'test_result': nfsic_opt_result, 'time_secs': t.secs }
def setUp(self): n = 300 dx = 2 pdata_mean = get_pdata_mean(n, dx) X, Y = pdata_mean.xy() gwx2 = util.meddistance(X)**2 gwy2 = util.meddistance(Y)**2 J = 2 V = np.random.randn(J, dx) W = np.random.randn(J, 1) self.gnfsic = it.GaussNFSIC(gwx2, gwy2, V, W, alpha=0.01) self.pdata_mean = pdata_mean
def job_nfsicJ3_perm_stoopt(paired_source, tr, te, r): """ Use permutations to simulate from the null distribution. """ n_permute = 500 J = 3 with util.ContextTimer() as t: nfsic_opt_options = { 'n_test_locs': J, 'max_iter': 300, 'V_step': 1, 'W_step': 1, 'gwidthx_step': 1, 'gwidthy_step': 1, 'batch_proportion': 0.7, 'tol_fun': 1e-4, 'step_pow': 0.5, 'seed': r + 2, 'reg': 1e-6 } op_V, op_W, op_gwx, op_gwy, info = it.GaussNFSIC.optimize_locs_widths( tr, alpha, **nfsic_opt_options) nfsic_opt = it.GaussNFSIC(op_gwx, op_gwy, op_V, op_W, alpha, reg='auto', n_permute=n_permute, seed=r + 3) nfsic_opt_result = nfsic_opt.perform_test(te) return { 'indtest': nfsic_opt, 'test_result': nfsic_opt_result, 'time_secs': t.secs }