From 11a58ee6216eecf0e25dcd4436e2d6951462f56e Mon Sep 17 00:00:00 2001 From: Theo Steininger Date: Thu, 7 Dec 2017 11:38:35 +0100 Subject: [PATCH] Added determinant regularization in EnsembleLikelihood. --- .../ensemble_likelihood/ensemble_likelihood.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/imagine/likelihoods/ensemble_likelihood/ensemble_likelihood.py b/imagine/likelihoods/ensemble_likelihood/ensemble_likelihood.py index 719b7b7..3b75090 100644 --- a/imagine/likelihoods/ensemble_likelihood/ensemble_likelihood.py +++ b/imagine/likelihoods/ensemble_likelihood/ensemble_likelihood.py @@ -113,9 +113,19 @@ class EnsembleLikelihood(Likelihood): result_1 = np.vdot(c_val, first_summand_val) result_2 = -np.vdot(c_val, second_summand_val) - result = -(result_1 + result_2) - self.logger.info("Calculated (%s): -(%f + %f) = %f" % - (self.observable_name, result_1, result_2, result)) + + # compute regularizing determinant of the covariance + # det(A + UV^T) = det(A) det(I + V^T A^-1 U) + log_det_1 = np.sum(np.log(A_diagonal_val)) + (sign, log_det_2) = np.slogdet(middle) + if sign < 0: + self.logger.error("Negative determinant of covariance!") + + result = -0.5*(result_1 + result_2 + log_det_1 + log_det_2) + + self.logger.info("Calculated (%s): -(%g + %g + %g + %g) = %f" % + (self.observable_name, + result_1, result_2, log_det_1, log_det_2)) # result_array[i] = result # total_result = result_array.mean() -- GitLab