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

Correct computation of mf_snr and logL at the end of the trajectory

parent d0073b78
......@@ -507,6 +507,11 @@ if __name__ == '__main__':
snr_dict = likelihood.calculate_network_snrs()
snr_dict_formatted = cut.dictionary_to_formatted_string(snr_dict, decimal_format=2)
cut.logger.info(f'SNR at starting point: {snr_dict_formatted}')
# Set the first value of the snr of the chain.
if likelihood.phase_marginalization:
mf_snr = snr_dict['network']['matched_filter_snr_phasemarg']
else:
mf_snr = snr_dict['network']['matched_filter_snr']
......@@ -593,16 +598,17 @@ if __name__ == '__main__':
count += 1
traj_status = "** ACCEPTED **"
fnr.update_train_data(qpos_traj_phase1, dlogL_traj_phase1, qpos_from_traj, dlogL_from_traj)
# Very circonvoluted way of setting the matched filter snr value of the new point in the chain. If trajectory was accepted as here, we use the last value computed of the trajectory and otherwise don't modify mf_snr which will keep the previous value.
if sampler.likelihood.phase_marginalization:
mf_snr = sampler.likelihood.snr_dict['network']['matched_filter_snr_phasemarg']
else:
mf_snr = sampler.likelihood.snr_dict['network']['matched_filter_snr']
Acc = count/traj_index
# Print the position of the chain
sampler.samples.append(q_pos.tolist())
if config_dict['analysis']['phase_marginalization']:
mf_snr = sampler.likelihood.snr_dict['network']['matched_filter_snr_phasemarg']
else:
mf_snr = sampler.likelihood.snr_dict['network']['matched_filter_snr']
logL2 = sampler.likelihood.snr_dict['network']['log_l_ratio'] # equal to logL?
sampler.chain_metrics.append([mf_snr, logL2, Acc, Accept])
sampler.chain_metrics.append([mf_snr, logL, Acc, Accept])
idx_Mc = sampler.search_parameter_keys.index('chirp_mass')
idx_mu = sampler.search_parameter_keys.index('reduced_mass')
eta = paru.Mc_mu_to_eta(q_pos[idx_Mc], q_pos[idx_mu])
......@@ -614,7 +620,7 @@ if __name__ == '__main__':
flag_strange_proba = ''
if abs(proba_acc - 1) > 0.35:
flag_strange_proba = ' - ??'
cut.logger.info(f'{traj_index:3} - {traj_status} - Acc = {Acc:5.1%} - {a:1.5f} {sup_or_inf} {proba_acc:1.5f}{flag_strange_proba} - mf_snr = {sampler.likelihood_gradient.matched_filter_snr_at_point:1.3f} - eta = {eta:.6f}')
cut.logger.info(f'{traj_index:3} - {traj_status} - Acc = {Acc:5.1%} - {a:1.5f} {sup_or_inf} {proba_acc:1.5f}{flag_strange_proba} - mf_snr = {mf_snr:1.3f} - eta = {eta:.6f}')
if False:
# if sampler.n_traj_fit >= 100 and traj_index%int(sampler.n_traj_fit/4)==0:
......@@ -1340,12 +1346,12 @@ if __name__ == '__main__':
# Record the position of the chain
sampler.samples.append(q_pos.tolist())
# import IPython; IPython.embed();sys.exit()
if config_dict['analysis']['phase_marginalization']:
mf_snr = sampler.likelihood.snr_dict['network']['matched_filter_snr_phasemarg']
else:
mf_snr = sampler.likelihood.snr_dict['network']['matched_filter_snr']
logL2 = sampler.likelihood.snr_dict['network']['log_l_ratio'] # equal to logL
sampler.chain_metrics.append([mf_snr, logL2, Acc_phase3, Accept])
if Accept == 1:
if sampler.likelihood.phase_marginalization:
mf_snr = sampler.likelihood.snr_dict['network']['matched_filter_snr_phasemarg']
else:
mf_snr = sampler.likelihood.snr_dict['network']['matched_filter_snr']
sampler.chain_metrics.append([mf_snr, logL, Acc_phase3, Accept])
# Print position of the chain
# if traj_index%int(sampler.n_traj_for_this_run/20000)==0:
......
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