MCPcopy Index your code
hub / github.com/ddbourgin/numpy-ml / VLB

Method VLB

numpy_ml/lda/lda.py:151–187  ·  view source on GitHub ↗

Return the variational lower bound associated with the current model parameters.

(self)

Source from the content-addressed store, hash-verified

149 self.alpha = self._maximize_alpha()
150
151 def VLB(self):
152 """
153 Return the variational lower bound associated with the current model
154 parameters.
155 """
156 phi = self.phi
157 alpha = self.alpha
158 beta = self.beta
159 gamma = self.gamma
160 corpus = self.corpus
161
162 D = self.D
163 T = self.T
164 N = self.N
165
166 a, b, c, _d = 0, 0, 0, 0
167 for d in range(D):
168 a += (
169 gammaln(np.sum(alpha))
170 - np.sum(gammaln(alpha))
171 + np.sum([(alpha[t] - 1) * dg(gamma, d, t) for t in range(T)])
172 )
173
174 _d += (
175 gammaln(np.sum(gamma[d, :]))
176 - np.sum(gammaln(gamma[d, :]))
177 + np.sum([(gamma[d, t] - 1) * dg(gamma, d, t) for t in range(T)])
178 )
179
180 for n in range(N[d]):
181 w_n = int(corpus[d][n])
182
183 b += np.sum([phi[d][n, t] * dg(gamma, d, t) for t in range(T)])
184 c += np.sum([phi[d][n, t] * np.log(beta[w_n, t]) for t in range(T)])
185 _d += np.sum([phi[d][n, t] * np.log(phi[d][n, t]) for t in range(T)])
186
187 return a + b + c - _d
188
189 def initialize_parameters(self):
190 """

Callers 1

trainMethod · 0.95

Calls 1

dgFunction · 0.85

Tested by

no test coverage detected