@@ -16,7 +16,8 @@ class NormalInverseWishart(AbstractPrior):
1616 Reference: MURPHY, Kevin P.
1717 Conjugate Bayesian analysis of the Gaussian distribution.
1818 def, v. 1, n. 2σ2, p. 16, 2007.
19- https://www.cse.iitk.ac.in/users/piyush/courses/tpmi_winter19/readings/bayesGauss.pdf
19+ https://www.cse.iitk.ac.in/users/piyush/courses/
20+ tpmi_winter19/readings/bayesGauss.pdf
2021 """
2122
2223 def __init__ (self , s_mat , r , v , m ):
@@ -42,13 +43,16 @@ def row_of_log_likelihood_for_pairs(
4243 i , # index of the row you want (int)
4344 ):
4445 """
45- Returns 1D array containing the log-likelihoods for pairs of points needed for the
46- initialization of bhc. This function combines i with all other points j > i and returns
47- the log-likelihood of those clusters (containing two points each).
46+ Returns 1D array containing the log-likelihoods for pairs of points
47+ needed for the initialization of bhc. This function combines i with
48+ all other points j > i and returns the log-likelihood of those
49+ clusters (containing two points each).
4850 """
4951 N , d = X .shape
5052 if d != self .s_mat .shape [0 ]:
51- raise ValueError ("data dimension and prior scale matrix do not match" )
53+ raise ValueError (
54+ "data dimension and prior scale matrix do not match"
55+ )
5256
5357 # ------------------------------------------------------------------
5458 # Pairwise sufficient statistics – only for j > i (batched)
@@ -72,7 +76,7 @@ def row_of_log_likelihood_for_pairs(
7276 # ------------------------------------------------------------------
7377 rp = self .r + 2.0 # each cluster has two points
7478 vp = self .v + 2.0
75- sign , logdet = slogdet (s_mat_p ) # (N-i-1,)
79+ sign , logdet = np . linalg . slogdet (s_mat_p ) # (N-i-1,)
7680 log_prior_post = (
7781 LOG2 * (vp * d / 2.0 )
7882 + (d / 2.0 ) * np .log (2.0 * np .pi / rp )
@@ -87,7 +91,9 @@ def row_of_log_likelihood_for_pairs(
8791 def __calc_log_prior (s_mat , r , v ):
8892 d = s_mat .shape [0 ]
8993 log_prior = LOG2 * (v * d / 2.0 ) + (d / 2.0 ) * np .log (2.0 * np .pi / r )
90- log_prior += multigammaln (v / 2.0 , d ) - (v / 2.0 ) * np .log (np .linalg .det (s_mat ))
94+ log_prior += multigammaln (v / 2.0 , d ) - (v / 2.0 ) * np .log (
95+ np .linalg .det (s_mat )
96+ )
9197 return log_prior
9298
9399 @staticmethod
@@ -96,7 +102,9 @@ def __calc_posterior(x_mat, s_mat, r, v, m):
96102 x_bar = np .mean (x_mat , axis = 0 )
97103 rp = r + n
98104 vp = v + n
99- s_mat_t = np .zeros (s_mat .shape ) if n == 1 else (n - 1 ) * np .cov (x_mat .T )
105+ s_mat_t = (
106+ np .zeros (s_mat .shape ) if n == 1 else (n - 1 ) * np .cov (x_mat .T )
107+ )
100108 dt = (x_bar - m )[np .newaxis ]
101109 s_mat_p = s_mat + s_mat_t + (r * n / rp ) * np .dot (dt .T , dt )
102110 return s_mat_p , rp , vp
0 commit comments