Commit e14b7e8f authored by Marc Arene's avatar Marc Arene
Browse files

Cleaning up a bit

parent eefd076f
......@@ -543,49 +543,6 @@ if __name__ == '__main__':
# if True:
if False:
import IPython; IPython.embed(); sys.exit()
samples_lal_path = '/Users/marcarene/projects/lalinference_runs/GW170817/mcmc/30Hz/outdir/samples_lal_sis_5008.dat'
data_dir = '/Users/marcarene/projects/phd_manuscript/5e1f2f775f0e8800015c297c/chap9_comparisonLAL/fig/__samples_dnn_e60_b128_30Hz_64sec'
samples_hmc_path = data_dir + '/samples_hmc_sis_5001.dat'
samples_lal_sis = np.loadtxt(samples_lal_path)
samples_hmc_sis = np.loadtxt(samples_hmc_path)
columns_lal = ['theta_jn', 'psi', 'luminosity_distance', 'chirp_mass', 'mass_ratio', 'dec', 'ra', 'geocent_time', 'chi_1', 'chi_2', 'lambda_1', 'lambda_2']
columns_hmc = ['theta_jn', 'psi', 'luminosity_distance', 'chirp_mass', 'reduced_mass', 'dec', 'ra', 'geocent_time', 'chi_1', 'chi_2', 'lambda_1', 'lambda_2']
posterior_lal_sis = pd.DataFrame(samples_lal_sis, columns=columns_lal)
posterior_hmc_sis = pd.DataFrame(samples_hmc_sis, columns=columns_hmc)
dir = '/Users/marcarene/projects/phd_manuscript/5e1f2f775f0e8800015c297c/chap6_hmcgw/__data_phase1_phicmarg/gw170817inj-imrpv2roq'
x_train = np.loadtxt(dir + '/qpos_traj_phase1.dat')
y_train = np.loadtxt(dir + '/dlogL_train_true.dat')
fit_method = fnr.CubicFitRegressor()
fit_method.fit(x_train, y_train)
y_train_pred_cubic = fit_method.predict(x_train)
np.savetxt(dir + '/dlogL_train_predicted_cubic.dat', y_train_pred_cubic)
dir = outdir + 'plots/phase2/cubic'
y_val_pred_cubic = fit_method.predict(x_val)
np.savetxt(dir + f'/dlogL_val_predicted_cubic_{len(y_val_pred_cubic)}.dat', y_val_pred_cubic)
oluts_fit = sampler.set_oluts_regressor()
oluts_fit.set_oluts(x_train, y_train)
y_train_pred_olut = oluts_fit.predict(x_train)
np.savetxt(dir + '/dlogL_train_predicted_oluts.dat', y_train_pred_olut)
def get_scatter_points(qpos_traj_phase1, dlogL_traj_phase1, idxlow=0, idxhigh=200, idx=0, idy=2, idz=0, step=1):
x = qpos_traj_phase1[idxlow:idxhigh:step, idx]
y = qpos_traj_phase1[idxlow:idxhigh:step, idy]
z = dlogL_traj_phase1[idxlow:idxhigh:step, idz]
return x, y, z
def plot_scatter(x,y,z):
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(15,15))
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x,y,z)
plt.show()
if RUN_CONST.plot_traj:
sampler.plot_traj_dir = outdir + 'plot_traj/'
......@@ -598,8 +555,6 @@ if __name__ == '__main__':
dlogTrajPi_traj=[],
lengths=[]
)
# H_p_logL_logP = []
# pmom_trajs = []
#**************************************************************************************************#
#********************************** Phase 1 : numericalHMC *************************************#
......@@ -696,19 +651,7 @@ if __name__ == '__main__':
np.savetxt(sampler.plot_traj_dir + 'dlogTrajPi_traj.dat', sampler.dict_of_trajectories['dlogTrajPi_traj'])
np.savetxt(sampler.plot_traj_dir + 'lengths.dat', sampler.dict_of_trajectories['lengths'])
# # Make a walker and corner plots of the chain in phase1
# samples = np.asarray(sampler.samples)
# geocent_time_index = sampler.search_parameter_keys.index('geocent_time')
# # Convert the duration samples in gps times
# samples[:, geocent_time_index] += sampler.start_time
# # Condition meant for short runs of less 9 trajectories where the corner plot would bug because there are less samples than dimensions...
# if samples.shape[0] > samples.shape[1]:
# # These two lines have been added to be able to plot the injected value on phi_c on the corner plots. Otherwise the `phi_c` and `tc_3p5PN` keys are not used in the code.
# starting_point_parameters['tc_3p5PN'] = ext_analysis_dict['tc_3p5PN']
# cut.logger.info(f'Making corner plots of {len(samples)} samples.')
# plots.plot_walkers_and_corner_from_samples(samples, starting_point_parameters, sampler.search_parameter_keys, save=True, label='{}_samples'.format(len(samples)), outdir=outdir + 'plots', plot_walkers=True)
# sampler.plot_autocorrelations_of_parameters()
# Make a walker and corner plots of the chain in phase1
sampler.plot_corner(sis=False, reweighted=False, priors=True, save=True, outdir=outdir + 'plots/phase1/', in_comp_mass=False)
sampler.plot_walkers(outdir=outdir + 'plots/phase1/')
......@@ -746,8 +689,6 @@ if __name__ == '__main__':
if opts.fit_method == 'cubic':
fit_method = fnr.CubicFitRegressor()
elif opts.fit_method == 'dnn':
# epochs = 80
# batch_size = 1425
epochs = 60
batch_size = 128
fit_method = fnr.DNNRegressorMultipleGradients(
......@@ -838,12 +779,7 @@ if __name__ == '__main__':
# validation_data = None
cut.logger.info(f'Training set size = {len(x_train)}, which corresponds to data gathered by {len(x_train)/200:.0f} numerical trajectories accepted in Phase I.')
# batch_size_list = [16, 32768]
# batch_size_list = [32, 64, 128, 256, 512, 1024, 2048]
# for batch_size in batch_size_list:
# cut.logger.info(f'\n\nTesting batchsize {batch_size}')
# LOAD THE FIT IF IT WAS SAVED PREVIOUSLY AT THE END OF PHASE 1, MAKE THE FIT OTHERWISE IF PHASE 1 JUST FINISHED
# LOAD THE FIT IF IT WAS SAVED PREVIOUSLY AT THE END OF PHASE 1, MAKE THE FIT OTHERWISE IF PHASE 1 JUST FINISHED. NOTE THAT THE LOADING OF THE FIT IF PHASE 3 WAS ON-GOING IS NOT DONE HERE.
global_fit_dir = sampler.outdir + f'sampler_state/global_fit/train_size_{len(x_train)}'
global_fit_dir_specific = global_fit_dir + f'/{fit_method.save_dir_suffix}'
if os.path.exists(global_fit_dir_specific):
......@@ -882,7 +818,6 @@ if __name__ == '__main__':
fit_method.save(global_fit_dir)
# param_keys = sampler.search_parameter_keys_local_fit
oluts_fit = sampler.set_oluts_regressor()
oluts_fit_dir = sampler.outdir + 'sampler_state/oluts_fit'
# if False:
......@@ -896,8 +831,8 @@ if __name__ == '__main__':
# Make regression plots on the phase1 training set to see how good
# the fit did
if False:
# if True:
# if False:
if True:
# import IPython; IPython.embed();sys.exit()
# fit_method.plot_color = 'grey'
outdir_plots_phase2 = outdir + 'plots/phase2'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment