From ff89a16226bcd4ce9d65212256f2e12bd76190b6 Mon Sep 17 00:00:00 2001
From: Colm Talbot <colm.talbot@ligo.org>
Date: Tue, 22 May 2018 14:55:34 +1000
Subject: [PATCH] fix distance and phase marginalisation

---
 tupak/likelihood.py | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/tupak/likelihood.py b/tupak/likelihood.py
index 43b9937ff..1ce7a78a7 100644
--- a/tupak/likelihood.py
+++ b/tupak/likelihood.py
@@ -14,10 +14,10 @@ import logging
 class Likelihood(object):
     """ Empty likelihood class to be subclassed by other likelihoods """
 
-    def log_likelihood():
+    def log_likelihood(self):
         return np.nan
 
-    def noise_log_likelihood():
+    def noise_log_likelihood(self):
         return np.nan
 
     def log_likelihood_ratio(self):
@@ -119,11 +119,20 @@ class GravitationalWaveTransient(Likelihood):
             matched_filter_snr_squared_array = matched_filter_snr_squared * \
                 self.waveform_generator.parameters['luminosity_distance'] / self.distance_array
 
+            if self.phase_marginalization:
+                matched_filter_snr_squared_array = self.bessel_function_interped(abs(matched_filter_snr_squared_array))
+            else:
+                matched_filter_snr_squared_array = np.real(matched_filter_snr_squared_array)
+
             log_l = logsumexp(matched_filter_snr_squared_array - optimal_snr_squared_array / 2,
                               b=self.distance_prior_array * self.delta_distance)
-        else:
+        elif self.phase_marginalization:
+            matched_filter_snr_squared = self.bessel_function_interped(abs(matched_filter_snr_squared))
             log_l = matched_filter_snr_squared - optimal_snr_squared / 2
 
+        else:
+            log_l = matched_filter_snr_squared.real - optimal_snr_squared / 2
+
         return log_l.real
 
     def log_likelihood(self):
-- 
GitLab