def disasters(value=disasters_array,
              early_mean=early_mean,
              late_mean=late_mean,
              switchpoint=switchpoint):
    """Annual occurences of coal mining disasters."""
    return pm.poisson_like(
        value[:switchpoint], early_mean) + pm.poisson_like(value[switchpoint:], late_mean)
Example #2
0
def disasters(value=disasters_array,
              early_mean=early_mean,
              late_mean=late_mean,
              switchpoint=switchpoint):
    """Annual occurences of coal mining disasters."""
    return pm.poisson_like(value[:switchpoint], early_mean) + pm.poisson_like(
        value[switchpoint:], late_mean)
Example #3
0
def data_likelihood(value=data.deaths, mu=predicted, alpha=omega):
    if alpha >= 10**10:
        return mc.poisson_like(value, mu)
    else:
        if mu.min() <= 0.:
            mu = mu + 10.**-10
        return mc.negative_binomial_like(value, mu, alpha)
Example #4
0
 def data_likelihood(value=np.round(self.training_data.cf * self.training_data.sample_size), mu=param_pred, alpha=alpha):
     if alpha >= 10**10:
         return mc.poisson_like(value, mu)
     else:
         if mu.min() <= 0.:
             mu = mu + 10**-10
         return mc.negative_binomial_like(value, mu, alpha)
Example #5
0
def logpoissonlike(n,mu):
    """Likelihood function for single bin counting experiment
        Args:
        n - observed number of counts
        mu - expected number of counts
    """
    if n==None: return -1e300
    return pymc.poisson_like(n,mu)
Example #6
0
def zip(value=data, mu=mu, psi=psi):
    """ Zero-inflated Poisson likelihood """

    # Initialize likeihood
    like = 0.0

    # Loop over data
    for x in value:

        if not x:
            # Zero values
            like += np.log((1. - psi) + psi * np.exp(-mu))

        else:
            # Non-zero values
            like += np.log(psi) + poisson_like(x, mu)

    return like
Example #7
0
def zip(value=data, mu=mu, psi=psi):
    """ Zero-inflated Poisson likelihood """

    # Initialize likeihood
    like = 0.0

    # Loop over data
    for x in value:

        if not x:
            # Zero values
            like += np.log((1. - psi) + psi * np.exp(-mu))

        else:
            # Non-zero values
            like += np.log(psi) + poisson_like(x, mu)

    return like
def arrivals(value=y, change_point=change_point,\
             early_rate=early_rate, late_rate=late_rate):
    return pm.poisson_like(value[:change_point], early_rate) +\
           pm.poisson_like(value[change_point:], late_rate)
Example #9
0
 def p_obs(value=p, pi=pi, n=n):
     return mc.poisson_like((value * n)[i_nonzero], (pi * n)[i_nonzero])
Example #10
0
 def p_obs(value=p, pi=pi, n=n):
     return mc.poisson_like((value * n)[i_nonzero], (pi * n)[i_nonzero])
Example #11
0
def obs(pi=pi):
    return mc.poisson_like(r * n, pi * n)
Example #12
0
thin = 10
results = {}
xmax = .07

### @export 'distribution-comparison'
pl.figure(**book_graphics.quarter_page_params)

ax = pl.axes([.1, .3, .85, .65])
x = pl.arange(0, n_small * pi_true * 4, .1)

# plot binomial distribution
y1 = [pl.exp(mc.binomial_like(x_i, n_small, pi_true)) for x_i in x]
pl.step(x, y1, 'k', linewidth=1, linestyle='step:', alpha=.8, label='Binomial')

# plot poisson distribution
y2 = [pl.exp(mc.poisson_like(x_i, n_small * pi_true)) for x_i in x]
pl.plot(x,
        y2,
        'k',
        linewidth=1,
        linestyle='steps--',
        alpha=.8,
        label='Poisson')

pl.legend(loc='upper right', fancybox=True, shadow=True)
pl.yticks([0, .05])
pl.xticks([25, 50, 75], ['', '', ''])
pl.axis([-.1, n_small * pi_true * 4, -.02, 1.1 * max(y1)])
pl.xlabel('Count')
#pl.figtext(.11, .94, 'Distribution', ha='left', va='top')
def G(value=D_array * 0.5, s=s, e=e, l=l):
    """Annual occurences of coal mining disasters."""
    return poisson_like(value[:s], e) + poisson_like(value[s:], l)
Example #14
0
def obs(pi=pi):
    return mc.poisson_like(r*n, pi*n)
Example #15
0
 def y_cc(mu=mu_cc, value=np.clip(data.n_cc, 0, data.n_pop)):
     return pm.poisson_like(value[10:], mu[10:])
Example #16
0
xmax = .07

### @export 'distribution-comparison'
pl.figure(**book_graphics.quarter_page_params)

ax = pl.axes([.1, .3, .85, .65])
x = pl.arange(0, n_small*pi_true*4, .1)

# plot binomial distribution
y1 = [pl.exp(mc.binomial_like(x_i, n_small, pi_true)) for x_i in x]
pl.step(x, y1, 'k',
        linewidth=1, linestyle='step:', alpha=.8,
        label='Binomial')

# plot poisson distribution
y2 = [pl.exp(mc.poisson_like(x_i, n_small*pi_true)) for x_i in x]
pl.plot(x, y2, 'k',
        linewidth=1, linestyle='steps--', alpha=.8,
        label='Poisson')

pl.legend(loc='upper right', fancybox=True, shadow=True)
pl.yticks([0, .05])
pl.xticks([25, 50, 75], ['','',''])
pl.axis([-.1, n_small*pi_true*4, -.02, 1.1*max(y1)])
pl.xlabel('Count')
#pl.figtext(.11, .94, 'Distribution', ha='left', va='top')

ax = pl.axes([.1, .15, .85, .20])
pl.step(x, pl.array(y1)-y2, color='k')
pl.xticks([0, 25, 50, 75])
pl.yticks([-.001, .001])
Example #17
0
def G(value=D_array * .5, s=s, e=e, l=l):
    """Annual occurences of coal mining disasters."""
    return poisson_like(value[:s], e) + poisson_like(value[s:], l)
Example #18
0
def data_likelihood(value=data.deaths, mu=estimate):
    return mc.poisson_like(value, mu)
Example #19
0
 def y_symp(mu=mu_symp, value=data.n_symp):
     return pm.poisson_like(value[10:], mu[10:])