Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmetic changes to twisted gaussian #806

Merged
merged 3 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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