From faf7c78cc53e81b554a2bdfe23ea411577fc51ba Mon Sep 17 00:00:00 2001 From: Shichao Wu Date: Mon, 9 Sep 2024 20:33:38 +0200 Subject: [PATCH 1/2] allow using constraint in the config which sets vector marginalized parameters --- pycbc/inference/models/base.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pycbc/inference/models/base.py b/pycbc/inference/models/base.py index a9be9e46781..6010bea9ca4 100644 --- a/pycbc/inference/models/base.py +++ b/pycbc/inference/models/base.py @@ -563,7 +563,13 @@ def logprior(self): def _logprior(self): """Calculates the log prior at the current parameters.""" logj = self.logjacobian - logp = self.prior_distribution(**self.current_params) + logj + # allow using constraint in the config which sets vector marginalized parameters + if hasattr(self, 'marginalize_vector_params'): + self.current_params_no_vec_margin = { + k: v for k, v in self.current_params.items() + if k not in self.marginalize_vector_params + } + logp = self.prior_distribution(**self.current_params_no_vec_margin) + logj if numpy.isnan(logp): logp = -numpy.inf return logp From 198c9fdffda86eaf02475418ebb25922c8e13a64 Mon Sep 17 00:00:00 2001 From: Shichao Wu Date: Mon, 9 Sep 2024 22:32:46 +0200 Subject: [PATCH 2/2] fix cc issues --- pycbc/inference/models/base.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pycbc/inference/models/base.py b/pycbc/inference/models/base.py index 6010bea9ca4..798ccb4dde7 100644 --- a/pycbc/inference/models/base.py +++ b/pycbc/inference/models/base.py @@ -563,13 +563,16 @@ def logprior(self): def _logprior(self): """Calculates the log prior at the current parameters.""" logj = self.logjacobian - # allow using constraint in the config which sets vector marginalized parameters + # allow using constraint in the config which sets + # vector marginalized parameters if hasattr(self, 'marginalize_vector_params'): - self.current_params_no_vec_margin = { + current_params_no_vec_margin = { k: v for k, v in self.current_params.items() if k not in self.marginalize_vector_params } - logp = self.prior_distribution(**self.current_params_no_vec_margin) + logj + else: + current_params_no_vec_margin = self.current_params + logp = self.prior_distribution(**current_params_no_vec_margin) + logj if numpy.isnan(logp): logp = -numpy.inf return logp