Skip to content

Commit

Permalink
Merge pull request #806 from pints-team/twisted-gaussian
Browse files Browse the repository at this point in the history
Cosmetic changes to twisted gaussian
  • Loading branch information
MichaelClerx authored Apr 25, 2019
2 parents 455511c + 41586ad commit 816bed2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
1 change: 1 addition & 0 deletions pints/tests/test_toy_twisted_gaussian_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def test_sampling_and_kl_divergence(self):
s13 = log_pdf1.kl_divergence(samples3)
self.assertLess(s11, s12)
self.assertLess(s11, s13)
self.assertAlmostEqual(s11, 0.0012248323505286152)

s21 = log_pdf2.kl_divergence(samples1)
s22 = log_pdf2.kl_divergence(samples2)
Expand Down
16 changes: 6 additions & 10 deletions pints/toy/_twisted_gaussian_banana.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,18 @@ def kl_divergence(self, samples):
# - k
# )
#
# For this distribution, s1 is the identify matrix, and m1 is zero,
# so it simplifies to
#
# dkl = 0.5 * (trace(s0) + m0.dot(m0) - log(det(s0)) - k))
#
m0 = np.mean(y, axis=0)
s0 = np.cov(y.T)
s1 = self._sigma
m1 = np.zeros(self.n_parameters())
s1_inv = np.linalg.inv(s1)
return 0.5 * (
np.trace(np.matmul(s1_inv, s0)) +
np.matmul(np.matmul(m1 - m0, s1_inv), m1 - m0) -
np.log(np.linalg.det(s0)) +
np.log(np.linalg.det(s1)) -
self._n_parameters)
np.trace(np.matmul(s1_inv, s0))
+ np.matmul(np.matmul((m1 - m0).T, s1_inv), m1 - m0)
+ np.log(np.linalg.det(s1))
- np.log(np.linalg.det(s0))
- self._n_parameters
)

def n_parameters(self):
""" See :meth:`pints.LogPDF.n_parameters()`. """
Expand Down

0 comments on commit 816bed2

Please sign in to comment.