In [48]:
from collections import namedtuple
from pprint import pprint
import matplotlib
import numpy as np
import spacepy.plot as spp
import pymc as mc
%matplotlib inline
matplotlib.rcParams['savefig.dpi']=100
In [49]:
Data = namedtuple('Data', ['obstot', 'obsbkg', 'nbox', 'C'])
In [50]:
obs = {2:Data(35, 269, 22, 41.49),
6:Data(156, 325, 52, 41.77),
9:Data(415, 3827, 10, 39.67)}
pprint(obs)
In [55]:
nclus = mc.Uniform('nclus', 0, 1e7)
nbkg = mc.Uniform('nbkg', 1, 1e7)
@mc.deterministic(plot=False)
def log_nbkg(nbkg=nbkg):
return np.log10(nbkg)
obsbkg = mc.Poisson('obsbkg',nbkg)
nbkgind = mc.Lognormal('nbkgind',mu=log_nbkg, tau=0.2**(-2))
obstot = mc.Poisson('obstot',nclus + nbkgind/obs[2].nbox, observed=True, value=obs[2].obstot)
@mc.deterministic(plot=True)
def lgLx(val=nclus, c=obs[2].C):
return np.log10(val)/2.30258 + c
In [56]:
model = mc.MCMC((nclus, nbkg, log_nbkg, obsbkg, nbkgind, obstot, lgLx))
In [63]:
model.sample(1000000, burn=1000, burn_till_tuned=True, thin=40)
In [65]:
mc.Matplot.plot(lgLx)
In [ ]:
In [ ]: