Created
April 9, 2015 16:12
-
-
Save sangheestyle/3527dcf1257f13a674f7 to your computer and use it in GitHub Desktop.
Variational Bayes(not implemented yet). Just part.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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