In [1]:
!date
In [2]:
# http://matpalm.com/blog/2012/12/27/dead_simple_pymc/
In [3]:
# simple_normal_model.py
import pymc
import numpy as np
import spacepy.plot as plt
import matplotlib.pyplot as plt
from pprint import pprint
%matplotlib inline
In [4]:
data = np.random.normal(loc=10, scale=2.0, size=100)
plt.hist(data, 10)
Out[4]:
In [5]:
mean = pymc.Uniform('mean', lower=min(data), upper=max(data))
precision = pymc.Uniform('precision', lower=0.0001, upper=1.0)
process = pymc.Normal('process', mu=mean, tau=precision, value=data, observed=True)
In [6]:
model = pymc.MCMC([mean, precision, process])
model.sample(iter=5e4, burn=1e3, thin=3)
pymc.Matplot.plot(model)
In [ ]:
In [7]:
pprint(model.stats())
In [8]:
mean = pymc.Uniform('mean', lower=min(data), upper=max(data))
std_dev = pymc.Uniform('std_dev', lower=0, upper=50)
@pymc.deterministic(plot=False)
def precision(std_dev=std_dev):
return 1.0 / (std_dev * std_dev)
process = pymc.Normal('process', mu=mean, tau=precision, value=data, observed=True)
In [9]:
model = pymc.MCMC([mean, std_dev, process])
model.sample(iter=5e4, burn=1e3, thin=3)
pymc.Matplot.plot(model)
In [ ]: