Exemplo n.º 1
0
 def remove_value(self, shared, value):
     count_sum = 0
     for i, xi in value:
         count_sum += xi
         self._counts[i] -= xi
         self._ratio += gammaln(xi + 1)
     self._ratio -= gammaln(count_sum + 1)
Exemplo n.º 2
0
 def score_data(self, shared):
     a_sum = sum(shared._alphas)
     n_sum = sum(self._counts)
     score = self._ratio
     for ai, ni in zip(self._alphas, self._counts):
         score += gammaln(ni + ai) - gammaln(ai)
     score += gammaln(a_sum) - gammaln(a_sum + n_sum)
     return score
Exemplo n.º 3
0
def score_student_t(x, nu, mu, sigmasq):
    """
    \cite{murphy2007conjugate}, Eq. 304
    """
    score = gammaln(.5 * (nu + 1.)) - gammaln(.5 * nu)
    score -= .5 * log(nu * pi * sigmasq)
    xt = (x - mu)
    s = xt * xt / sigmasq
    score += -(.5 * (nu + 1.)) * log(1. + s / nu)
    return score
Exemplo n.º 4
0
 def score_data(self, shared):
     """
     \cite{murphy2007conjugate}, Eq. 171
     """
     post = shared.plus_group(self)
     return gammaln(post.nu / 2.) - gammaln(shared.nu / 2.) \
         + 0.5 * log(shared.kappa / post.kappa) \
         + (0.5 * shared.nu) * log(shared.nu * shared.sigmasq) \
         - (0.5 * post.nu) * log(post.nu * post.sigmasq) \
         - self.count / 2. * 1.1447298858493991
Exemplo n.º 5
0
def score_student_t(x, nu, mu, sigmasq):
    """
    \cite{murphy2007conjugate}, Eq. 304
    """
    score = gammaln(.5 * (nu + 1.)) - gammaln(.5 * nu)
    score -= .5 * log(nu * pi * sigmasq)
    xt = (x - mu)
    s = xt * xt / sigmasq
    score += -(.5 * (nu + 1.)) * log(1. + s / nu)
    return score
Exemplo n.º 6
0
 def score_group(self, group):
     """
     \cite{murphy2007conjugate}, Eq. 171
     """
     post = self.plus_group(group)
     return gammaln(post.nu / 2.) - gammaln(self.nu / 2.) \
         + 0.5 * log(self.kappa / post.kappa) \
         + (0.5 * self.nu) * log(self.nu * self.sigmasq) \
         - (0.5 * post.nu) * log(post.nu * post.sigmasq) \
         - group.count / 2. * 1.1447298858493991
Exemplo n.º 7
0
 def score_data(self, shared):
     """
     \cite{murphy2007conjugate}, Eq. 171
     """
     post = shared.plus_group(self)
     return gammaln(post.nu / 2.) - gammaln(shared.nu / 2.) \
         + 0.5 * log(shared.kappa / post.kappa) \
         + (0.5 * shared.nu) * log(shared.nu * shared.sigmasq) \
         - (0.5 * post.nu) * log(post.nu * post.sigmasq) \
         - self.count / 2. * 1.1447298858493991
Exemplo n.º 8
0
 def score_data(self, shared):
     assert len(shared.betas), 'betas is empty'
     """
     See doc/dpd.pdf Equation (3)
     """
     score = 0.
     for i, count in self.counts.iteritems():
         prior_i = shared.betas[i] * shared.alpha
         score += gammaln(prior_i + count) - gammaln(prior_i)
     score += gammaln(shared.alpha) - gammaln(shared.alpha + self.total)
     return score
Exemplo n.º 9
0
 def score_group(self, group):
     assert len(self.betas), 'betas is empty'
     """
     See doc/dpd.pdf Equation (3)
     """
     score = 0.
     for i, count in group.counts.iteritems():
         prior_i = self.betas[i] * self.alpha
         score += gammaln(prior_i + count) - gammaln(prior_i)
     score += gammaln(self.alpha) - gammaln(self.alpha + group.total)
     return score
Exemplo n.º 10
0
 def score_data(self, shared):
     assert len(shared.betas), 'betas is empty'
     """
     See doc/dpd.pdf Equation (3)
     """
     score = 0.
     for i, count in self.counts.iteritems():
         assert count >= 0, "cannot score while in debt"
         prior_i = shared.betas[i] * shared.alpha
         score += gammaln(prior_i + count) - gammaln(prior_i)
     score += gammaln(shared.alpha) - gammaln(shared.alpha + self.total)
     return score
Exemplo n.º 11
0
    def score_data(self, shared):
        """
        \cite{jordan2001more} Eqn 22.
        Michael Jordan's CS281B/Stat241B
        Advanced Topics in Learning and Decision Making course,
        'More on Marginal Likelihood'
        """

        dim = shared.dim
        a = shared.alphas
        m = self.counts

        score = sum(gammaln(a[k] + m[k]) - gammaln(a[k]) for k in xrange(dim))
        score += gammaln(a.sum())
        score -= gammaln(a.sum() + m.sum())
        return score
Exemplo n.º 12
0
    def score_data(self, shared):
        """
        \cite{jordan2001more} Eqn 22.
        Michael Jordan's CS281B/Stat241B
        Advanced Topics in Learning and Decision Making course,
        'More on Marginal Likelihood'
        """

        dim = shared.dim
        a = shared.alphas
        m = self.counts

        score = sum(gammaln(a[k] + m[k]) - gammaln(a[k]) for k in xrange(dim))
        score += gammaln(a.sum())
        score -= gammaln(a.sum() + m.sum())
        return score
Exemplo n.º 13
0
 def score_data(self, shared):
     post = shared.plus_group(self)
     score = gammaln(shared.alpha + shared.beta)
     score -= gammaln(post.alpha + post.beta)
     score += gammaln(post.alpha) - gammaln(shared.alpha)
     score += gammaln(post.beta) - gammaln(shared.beta)
     return score
Exemplo n.º 14
0
 def score_data(self, shared):
     post = shared.plus_group(self)
     score = gammaln(shared.alpha + shared.beta)
     score -= gammaln(post.alpha + post.beta)
     score += gammaln(post.alpha) - gammaln(shared.alpha)
     score += gammaln(post.beta) - gammaln(shared.beta)
     return score
Exemplo n.º 15
0
 def score_value(self, shared, value):
     post = shared.plus_group(self)
     alpha = post.alpha + shared.r
     beta = post.beta + value
     score = gammaln(post.alpha + post.beta)
     score -= gammaln(alpha + beta)
     score += gammaln(alpha) - gammaln(post.alpha)
     score += gammaln(beta) - gammaln(post.beta)
     return score
Exemplo n.º 16
0
 def score_value(self, shared, value):
     post = shared.plus_group(self)
     alpha = post.alpha + shared.r
     beta = post.beta + value
     score = gammaln(post.alpha + post.beta)
     score -= gammaln(alpha + beta)
     score += gammaln(alpha) - gammaln(post.alpha)
     score += gammaln(beta) - gammaln(post.beta)
     return score
Exemplo n.º 17
0
 def score_data(self, shared):
     """
     \cite{jordan2001more} Eqn 22.
     Michael Jordan's CS281B/Stat241B
     Advanced Topics in Learning and Decision Making course,
     'More on Marginal Likelihood'
     """
     alpha = shared.alpha + self.heads
     beta = shared.beta + self.tails
     score = gammaln(shared.alpha + shared.beta) - gammaln(alpha + beta)
     score += gammaln(alpha) - gammaln(shared.alpha)
     score += gammaln(beta) - gammaln(shared.beta)
     return score
Exemplo n.º 18
0
 def score_data(self, shared):
     """
     \cite{jordan2001more} Eqn 22.
     Michael Jordan's CS281B/Stat241B
     Advanced Topics in Learning and Decision Making course,
     'More on Marginal Likelihood'
     """
     alpha = shared.alpha + self.heads
     beta = shared.beta + self.tails
     score = gammaln(shared.alpha + shared.beta) - gammaln(alpha + beta)
     score += gammaln(alpha) - gammaln(shared.alpha)
     score += gammaln(beta) - gammaln(shared.beta)
     return score
Exemplo n.º 19
0
 def score_data(self, shared):
     post = shared.plus_group(self)
     return gammaln(post.alpha) - gammaln(shared.alpha) \
         - post.alpha * log(post.inv_beta) \
         + shared.alpha * log(shared.inv_beta) \
         - self.log_prod
Exemplo n.º 20
0
 def score_value(self, shared, value):
     post = shared.plus_group(self)
     return gammaln(post.alpha + value) - gammaln(post.alpha) \
         + post.alpha * log(post.inv_beta) \
         - (post.alpha + value) * log(1. + post.inv_beta) \
         - log(factorial(value))
Exemplo n.º 21
0
 def score_value(self, shared, value):
     post = shared.plus_group(self)
     return gammaln(post.alpha + value) - gammaln(post.alpha) \
         + post.alpha * log(post.inv_beta) \
         - (post.alpha + value) * log(1. + post.inv_beta) \
         - log(factorial(value))
Exemplo n.º 22
0
 def score_data(self, shared):
     post = shared.plus_group(self)
     return gammaln(post.alpha) - gammaln(shared.alpha) \
         - post.alpha * log(post.inv_beta) \
         + shared.alpha * log(shared.inv_beta) \
         - self.log_prod