def bootstrap_nvphi(boot_payload, beta_phi_vals, bins): n_boot = boot_payload.shape[0] out = np.zeros((n_boot, beta_phi_vals.size)) for i, (boot_logweights, boot_data, boot_data_N) in enumerate(boot_payload): neglogpdist, neglogpdist_N, avg, chi, avg_N, chi_N, cov_N = extract_and_reweight_data( boot_logweights, boot_data, boot_data_N, bins, beta_phi_vals) print(i) out[i] = chi return out
def get_n_v_phi(all_data, all_data_aux, boot_indices, boot_logweights): bins = np.arange(0, np.ceil(all_data.max())+1) beta_phi_vals = np.arange(0,10.02,0.02) assert boot_logweights.size == boot_indices.size boot_data = all_data[boot_indices] boot_data_aux = all_data_aux[boot_indices] neglogpdist, neglogpdist_N, avg_ntwid, var_ntwid, avg_N, var_N, this_cov = extract_and_reweight_data(boot_logweights, boot_data, boot_data_aux, bins, beta_phi_vals) return (boot_indices, boot_logweights, neglogpdist, neglogpdist_N, avg_ntwid, var_ntwid, avg_N, var_N, bins, beta_phi_vals)
mpl.rcParams.update({'ytick.labelsize': 40}) mpl.rcParams.update({'axes.titlesize': 50}) all_data_ds = np.load('all_data.dat.npz', allow_pickle=True) all_logweights = all_data_ds['logweights'] all_data = all_data_ds['data'] all_data_N = all_data_ds['data_aux'] max_val = int(np.ceil(np.max((all_data, all_data_N))) + 1) # Ntwid and N bins bins = np.arange(0, max_val + 1, 1) print("extracting all...") #all_neglogpdist, all_neglogpdist_N, avg_ntwid, var_ntwid, avg_N, var_N, cov_data = extract_and_reweight_data(all_logweights, all_data, all_data_N, bins, beta_phi_vals) all_neglogpdist, all_neglogpdist_N, avg_ntwid, var_ntwid, avg_N, var_N, cov_data = extract_and_reweight_data( all_logweights, all_data_N, all_data_N, bins, beta_phi_vals) integ_ntwid = np.append(0, cumtrapz(avg_ntwid, beta_phi_vals)) ## Now get errorbars from bootstrap samples dat = np.load('boot_fn_payload.dat.npy', encoding='bytes', allow_pickle=True) boot_n_iter = len(dat) boot_neglogpdist = np.zeros((boot_n_iter, bins.size - 1)) boot_neglogpdist_N = np.zeros((boot_n_iter, bins.size - 1)) boot_avg_N = np.zeros((boot_n_iter, beta_phi_vals.size)) boot_var_N = np.zeros((boot_n_iter, beta_phi_vals.size)) boot_integ_N = np.zeros_like(boot_avg_N) print("Extracting and reweighting bootstrap samples...") # Extract data for each bootstrap
dat = np.load('phi_sims/ni_rad_weighted.dat.npz') all_data_ds = np.load('phi_sims/data_reduced/all_data.dat.npz') all_logweights = all_data_ds['logweights'] all_data = all_data_ds['data'] all_data_N = all_data_ds['data_aux'] max_val = int(np.ceil(np.max((all_data, all_data_N))) + 1) bins = np.arange(0, max_val+1, 1) ## In kT! beta_phi_vals = np.linspace(0,4,101) ## Get PvN, <Nv>, chi_v from all data ### all_neglogpdist, all_neglogpdist_N, all_avg, all_chi, all_avg_N, all_chi_N, _ = extract_and_reweight_data(all_logweights, all_data, all_data_N, bins, beta_phi_vals) ### Now input all <n_i>_\phi's for a given i ### print('') print('Extracting all n_i\'s...') sys.stdout.flush() n_heavies = None n_i_dat_fnames = np.append(sorted(glob.glob('phi_sims/data_reduced/phi*/rho_data_dump_rad_6.0.dat.npz')), sorted(glob.glob('phi_sims/data_reduced/nstar*/rho_data_dump_rad_6.0.dat.npz'))) all_data_n_i = None ## Gather n_i data from each umbrella window (phi value) for fname in n_i_dat_fnames:
all_data_cube.append(np.loadtxt(fname)) all_data_com.append(np.load('{}/com_cube.dat.npy'.format(dirname))) all_data_cube = np.concatenate(all_data_cube) all_data_com = np.concatenate(all_data_com, axis=0) print('') print('WHAMing and reweighting to phi-ens') sys.stdout.flush() # Make sure our PV(N) goes to high enough N bins = np.arange(all_data_cube.max() + 3) # Find <N_V>0 and unbiased average water COM in V all_neglogpdist, all_neglogpdist_N, all_avg, all_chi, all_avg_cube, all_chi_N, all_cov_cube = extract_and_reweight_data( all_logweights, all_data, all_data_cube, bins, beta_phi_vals) all_neglogpdist, all_neglogpdist_comx, all_avg, all_chi, all_avg_comx, all_chi_comx, all_cov_comx = extract_and_reweight_data( all_logweights, all_data, all_data_com[:, 0], bins, beta_phi_vals) all_neglogpdist, all_neglogpdist_comy, all_avg, all_chi, all_avg_comy, all_chi_comy, all_cov_comy = extract_and_reweight_data( all_logweights, all_data, all_data_com[:, 1], bins, beta_phi_vals) all_neglogpdist, all_neglogpdist_comz, all_avg, all_chi, all_avg_comz, all_chi_comz, all_cov_comz = extract_and_reweight_data( all_logweights, all_data, all_data_com[:, 2], bins, beta_phi_vals) all_neglogpdist, all_neglogpdist_N, all_avg, all_chi, all_avg_N, all_chi_N, all_cov_N = extract_and_reweight_data( all_logweights, all_data, all_data_N, bins, beta_phi_vals) this_dat = np.vstack((beta_phi_vals, all_avg, all_chi)).T np.savetxt("NvPhi.dat", this_dat) # Find chi_v max! (small probe) max_idx = np.argmax(all_chi)