This file contains 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
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) |
This file contains 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
def single_collapsed_likelihood(tprior, gmean, gvar, tcount): | |
"Assumes tprior is a scalar" | |
p0 = np.log(gamma_pdf(tprior, gmean, gvar)) | |
p0 += tcount.shape[0]*(gammaln(tprior*tcount.shape[1])-gammaln(tprior)*tcount.shape[1]) | |
for d in xrange(tcount.shape[0]): | |
for i,t in enumerate(tcount[d]): | |
p0 += gammaln(t + tprior) | |
p0 -= gammaln(sum(tcount[d]) + tprior*tcount.shape[1]) | |
return p0 |
This file contains 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
def collapsed_likelihood(tprior, gmean, gvar, tcount): | |
p0 = sum(np.log(gamma_pdf(tp, gmean, gvar)) for tp in tprior) | |
p0 += tcount.shape[0]*(gammaln(sum(tprior))-sum(gammaln(tp) for tp in tprior)) | |
for d in xrange(tcount.shape[0]): | |
for i,t in enumerate(tcount[d]): | |
p0 += gammaln(t + tprior[i]) | |
p0 -= gammaln(sum(tcount[d]) + sum(tprior)) | |
return p0 |
This file contains 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
class OnlineLearner(object): | |
def __init__(self, **kwargs): | |
self.last_misses = 0. | |
self.iratio = 0. | |
self.it = 1. | |
self.l = kwargs["l"] | |
self.max_ratio = -np.inf | |
self.threshold = 500. | |
def hinge_loss(self, vector, cls, weight): |
NewerOlder