Skip to content

Instantly share code, notes, and snippets.

@alextp
Created August 22, 2010 20:35
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 alextp/544251 to your computer and use it in GitHub Desktop.
Save alextp/544251 to your computer and use it in GitHub Desktop.
def hash_collapsed_likelihood(tprior, gmean, gvar, tcount, s1):
"Assumes a single hyperparameter"
p0 = np.log(gamma_pdf(tprior, gmean, gvar))
s0 = len(tcount)
p0 += s0*(gammaln(tprior*s1)-sum(gammaln(tprior) for i in xrange(s1)))
for d in xrange(s0):
for i,t in tcount[d].items():
p0 += gammaln(t + tprior)
p0 += (s1-len(tcount[d]))*gammaln(tprior)
p0 -= gammaln(sum(tcount[d]) + s1*tprior)
return p0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment