Skip to content

Instantly share code, notes, and snippets.

@sangheestyle
Created April 9, 2015 16:12
Show Gist options
  • Save sangheestyle/3527dcf1257f13a674f7 to your computer and use it in GitHub Desktop.
Save sangheestyle/3527dcf1257f13a674f7 to your computer and use it in GitHub Desktop.
Variational Bayes(not implemented yet). Just part.
from scipy import array
from scipy.special import psi as digam
from math import exp
words = ["cat", "dog", "hamburger", "iron", "pig"]
beta = array([[.26, .185, .185, .185, .185],
[.185, .185, .26, .185, .185],
[.185, .185, .185, .26, .185]])
gamma = [2.0, 2.0, 2.0]
alpha = [.1, .1, .1]
def cal_new_phi(word):
new_phi = []
for i, val in enumerate(gamma):
new_phi.append(beta[i][words.index(word)] * exp(digam(gamma[i]) - digam(sum(gamma))))
return new_phi
new_phi = []
doc = "dog cat cat pig".split()
for word in doc:
new_phi.append(cal_new_phi(word))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment