t, seobnre_waveform_time_domain = wf.seobnre_bbh_with_spin_and_eccentricity( parameters=injection_parameters, sampling_frequency=sampling_frequency, minimum_frequency=minimum_frequency - 10, maximum_frequency=maximum_frequency + 1000, ) seobnre_wf_td, seobnre_wf_fd, max_overlap, index_shift, phase_shift = ovlp.maximise_overlap( seobnre_waveform_time_domain, comparison_waveform_frequency_domain, sampling_frequency, interferometers[0].frequency_array, interferometers[0].power_spectral_density, ) print('maximum overlap: ' + str(max_overlap)) seobnre_wf_fd = ovlp.zero_pad_frequency_domain_signal(seobnre_wf_fd, interferometers) # Inject the signal interferometers.inject_signal(parameters=injection_parameters, injection_polarizations=seobnre_wf_fd) # plot the data for sanity signal = interferometers[0].get_detector_response(seobnre_wf_fd, injection_parameters) interferometers.plot_data(signal=signal, outdir=outdir, label=label) # Set up priors priors = bb.gw.prior.BBHPriorDict() for key in ['mass_1', 'mass_2', 'a_1', 'a_2']: priors.pop(key) for key in ['theta_jn', 'theta_jl', 'tilt_1', 'tilt_2']: priors[key] = 0 priors['mass_ratio'] = bb.core.prior.Uniform(name='mass_ratio',
def new_weight( log_L, parameters, comparison_waveform_frequency_domain, interferometers, duration, sampling_frequency, maximum_frequency, label, ): """ Compute the new weight for a point, weighted by the eccentricity-marginalised likelihood. :param log_L: float the original likelihood of the point :param parameters: dict the parameters that define the sample :param comparison_waveform_frequency_domain: dict frequency-domain waveform polarisations of the waveform used for the original analysis :param interferometers: InterferometerList list of interferometers used in the detection :param duration: int time duration of the signal :param sampling_frequency: int the frequency with which to 'sample' the waveform :param minimum_frequency: int the minimum frequency at which the data is analysed :param maximum_frequency: int the maximum frequency at which the data is analysed :param label: str identifier for results :return: e: float the new eccentricity sample average_log_likelihood: float the eccentricity-marginalised new likelihood log_weight: float the log weight of the sample """ # First calculate a grid of likelihoods. grid_size = 20 eccentricity_grid = np.logspace(np.log10(minimum_eccentricity), np.log10(0.2), grid_size) # Recalculate the log likelihood of the original sample recalculated_log_likelihood = log_likelihood_ratio( comparison_waveform_frequency_domain, interferometers, parameters, duration) # Print a warning if this is much different to the likelihood stored in the results if abs(recalculated_log_likelihood - log_L) / log_L > 0.1: percentage = abs(recalculated_log_likelihood - log_L) / log_L * 100 print( "WARNING :: recalculated log likelihood differs from original by {}%" .format(percentage)) print('original log L: ' + str(log_L)) print('recalculated log L: ' + str(recalculated_log_likelihood)) log_likelihood_grid = [] intermediate_outfile = open(label + "_eccentricity_result.txt", "w") intermediate_outfile.write("sample parameters:\n") for key in parameters.keys(): intermediate_outfile.write(key + ":\t" + str(parameters[key]) + "\n") intermediate_outfile.write("\n-------------------------\n") intermediate_outfile.write("e\t\tlog_L\t\tmaximised_overlap\n") # Prepare for the possibility that we have to disregard this sample disregard = False for e in eccentricity_grid: parameters.update({"eccentricity": e}) # Need to have a set minimum frequency, since this is also the reference frequency t, seobnre_waveform_time_domain = wf.seobnre_bbh_with_spin_and_eccentricity( parameters=parameters, sampling_frequency=sampling_frequency, minimum_frequency=10, maximum_frequency=maximum_frequency + 1000, ) if t is None: print('No waveform generated; disregard sample ' + label) intermediate_outfile.write( str(e) + "\t\t" + str(None) + "\t\t" + str(None) + "\n") disregard = True else: seobnre_wf_td, seobnre_wf_fd, max_overlap, index_shift, phase_shift = ovlp.maximise_overlap( seobnre_waveform_time_domain, comparison_waveform_frequency_domain, sampling_frequency, interferometers[0].frequency_array, interferometers[0].power_spectral_density, ) seobnre_wf_fd = ovlp.zero_pad_frequency_domain_signal( seobnre_wf_fd, interferometers) eccentric_log_L = log_likelihood_ratio(seobnre_wf_fd, interferometers, parameters, duration) log_likelihood_grid.append(eccentric_log_L) intermediate_outfile.write( str(e) + "\t\t" + str(eccentric_log_L) + "\t\t" + str(max_overlap) + "\n") intermediate_outfile.close() if not disregard: cumulative_density_grid = cumulative_density_function( log_likelihood_grid) # We want to pick a weighted random point from within the CDF e = pick_weighted_random_eccentricity(cumulative_density_grid, eccentricity_grid) # Also return eccentricity-marginalised log-likelihood average_log_likelihood = np.mean(log_likelihood_grid) # The weight is the ratio of this to the log likelihood log_weight = average_log_likelihood - recalculated_log_likelihood return e, average_log_likelihood, log_weight else: return None, None, None