diff --git a/peyote/likelihood.py b/peyote/likelihood.py index 443469bf72a52cbb1389d8e0c029653f5898f7c2..40ec85d65e53e70c859f6fdb06e1787c80b94085 100644 --- a/peyote/likelihood.py +++ b/peyote/likelihood.py @@ -5,6 +5,8 @@ class Likelihood: def __init__(self, interferometers, source): self.interferometers = interferometers self.source = source + self.noise_log_likelihood = 0 + self.set_noise_log_likelihood() def get_interferometer_signal(self, waveform_polarizations, interferometer): h = [] @@ -12,7 +14,6 @@ class Likelihood: det_response = interferometer.antenna_response( self.source.ra, self.source.dec, self.source.geocent_time, self.source.psi, mode) - h.append(waveform_polarizations[mode] * det_response) signal = np.sum(h, axis=0) @@ -38,6 +39,16 @@ class Likelihood: / interferometer.power_spectral_density_array) return log_l.real + def log_likelihood_ratio(self): + return self.log_likelihood() - self.noise_log_likelihood + + def set_noise_log_likelihood(self): + log_l = 0 + for interferometer in self.interferometers: + log_l -= 4. / self.source.time_duration * np.sum(abs(interferometer.data)**2 + / interferometer.power_spectral_density_array) + self.noise_log_likelihood = log_l.real + class LikelihoodB(Likelihood): diff --git a/tutorials/Injection.py b/tutorials/Injection.py index 6a0d9f0e5c9886092199488718ca156652e91ee6..4cfb9c78e186a0fb8dee58c2a605de4a59ee19fe 100644 --- a/tutorials/Injection.py +++ b/tutorials/Injection.py @@ -24,7 +24,11 @@ for IFO in IFOs: IFO.inject_signal(source) -likelihood = peyote.likelihood.LikelihoodB(source=source, interferometers=IFOs) +likelihood = peyote.likelihood.Likelihood(source=source, interferometers=IFOs) + +print(likelihood.noise_log_likelihood) +print(likelihood.log_likelihood()) +print(likelihood.log_likelihood_ratio()) prior = source.copy() prior.mass_1 = peyote.parameter.Parameter('mass_1', prior=peyote.prior.Uniform(lower=35, upper=37), @@ -32,8 +36,8 @@ prior.mass_1 = peyote.parameter.Parameter('mass_1', prior=peyote.prior.Uniform(l prior.mass_2 = peyote.parameter.Parameter('mass_2', prior=peyote.prior.Uniform(lower=28, upper=30), latex_label='$m_2$') -result = peyote.sampler.run_sampler(likelihood, prior, sampler='dynesty', npoints=100, print_progress=True) +# result = peyote.sampler.run_sampler(likelihood, prior, sampler='dynesty', npoints=100, print_progress=True) -truths = [source.__dict__[x] for x in result.search_parameter_keys] -fig = corner.corner(result.samples, labels=result.labels, truths=truths) -fig.savefig('Injection Test') +# truths = [source.__dict__[x] for x in result.search_parameter_keys] +# fig = corner.corner(result.samples, labels=result.labels, truths=truths) +# fig.savefig('Injection Test')