Esempio n. 1
0
 def logp(value, n, p):
     return bound(
         factln(n) - factln(value).sum() + (value * at.log(p)).sum(),
         value >= 0,
         0 <= p,
         p <= 1,
         at.isclose(p.sum(), 1),
         broadcast_conditions=False,
     )
Esempio n. 2
0
    def logp(self, value):
        n = self.n
        p = self.p

        return bound(
            factln(n) - factln(value).sum() + (value * at.log(p)).sum(),
            at.all(value >= 0),
            at.all(0 <= p),
            at.all(p <= 1),
            at.isclose(p.sum(), 1),
            broadcast_conditions=False,
        )
    def logp(self, x):
        n = self.n
        p = self.p

        return bound(tt.sum(factln(n)) - tt.sum(factln(x)) +
                     tt.sum(x * tt.log(p)),
                     tt.all(x >= 0),
                     tt.all(tt.eq(tt.sum(x, axis=-1, keepdims=True), n)),
                     tt.all(p <= 1),
                     tt.all(tt.eq(tt.sum(p, axis=-1), 1)),
                     tt.all(tt.ge(n, 0)),
                     broadcast_conditions=False)
Esempio n. 4
0
    def logp(self, value):
        n = self.n
        p = self.p

        return bound(
            factln(n) - factln(value).sum() + (value * aet.log(p)).sum(),
            value >= 0,
            0 <= p,
            p <= 1,
            aet.isclose(p.sum(), 1),
            broadcast_conditions=False,
        )
Esempio n. 5
0
    def logp(self, value):
        value_x = value[0][0]
        value_y = value[0][1]
        mu_x = self.mu_x
        mu_y = self.mu_y

        log_prob_x = bound(
            logpow(mu_x, value_x) - factln(value_x) - mu_x,
            mu_x >= 0, value_x >= 0)
        log_prob_y = bound(
            logpow(mu_y, value_y) - factln(value_y) - mu_y,
            mu_y >= 0, value_y >= 0)
        out = T.switch(1 * T.eq(mu_x, 0) * T.eq(value_x, 0), 0, log_prob_x)
        out += T.switch(1 * T.eq(mu_x, 0) * T.eq(value_x, 0), 0, log_prob_y)
        return out
 def logp(self, value):
     mu = self.mu
     #              mu^k
     #     PDF = ------------
     #            k! (e^mu - 1)
     # log(PDF) = log(mu^k) - (log(k!) + log(e^mu - 1))
     #
     # See https://en.wikipedia.org/wiki/Zero-truncated_Poisson_distribution
     p = logpow(mu,
                value) - (factln(value) + pm.math.log(pm.math.exp(mu) - 1))
     log_prob = bound(p, mu >= 0, value >= 0)
     # Return zero when mu and value are both zero
     return tt.switch(1 * tt.eq(mu, 0) * tt.eq(value, 0), 0, log_prob)
 def logp_Poisson(self, value):
     r"""
     Calculate log-probability of Poisson distribution at specified value. 
     Switches to Gamma distribution when mu gets large (> 1000)
     Parameters
     ----------
     value: numeric
         Value(s) for which log-probability is calculated. If the log probabilities for multiple
         values are desired the values must be provided in a numpy array or theano tensor
     Returns
     -------
     TensorVariable
     """
     # Return zero when mu and value are both zero, return Gamma log-probability when mu is > 1000,
     # otherwise return Poisson log-probability
     return tt.switch(
         tt.gt(self.mu_biol, 1e3),
         pm.Gamma.dist(mu=self.mu_biol,
                       sd=tt.sqrt(self.mu_biol)).logp(value),
         tt.switch(
             tt.eq(self.mu_biol, 0) * tt.eq(value, 0), 0,
             bound(
                 logpow(self.mu_biol, value) - factln(value) - self.mu_biol,
                 self.mu_biol >= 0, value >= 0)))