Skip to content

Instantly share code, notes, and snippets.

@DFoly
Last active March 2, 2019 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DFoly/f5e095fda89784c926ddd502a562b317 to your computer and use it in GitHub Desktop.
Save DFoly/f5e095fda89784c926ddd502a562b317 to your computer and use it in GitHub Desktop.
def _compute_loss_function(self, X, pi, mu, sigma):
"""Computes lower bound loss function
Parameters:
-----------
X: (N x d), data
Returns:
---------
pi: (C)
mu: (C x d)
sigma: (C x d x d)
"""
N = X.shape[0]
C = self.gamma.shape[1]
self.loss = np.zeros((N, C))
for c in range(C):
dist = mvn(self.mu[c], self.sigma[c],allow_singular=True)
self.loss[:,c] = self.gamma[:,c] * (np.log(self.pi[c]+0.00001)+dist.logpdf(X)-np.log(self.gamma[:,c]+0.000001))
self.loss = np.sum(self.loss)
return self.loss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment