docker pull jupyter/scipy-notebook
docker run -d -e GRANT_SUDO=yes -p 8888:8888 jupyter/scipy-notebook
sudo su -
apt-get install python-qt4
conda install pymc
source activate python2
source deactivate
exit
git clone https://github.com/psygrammer/bayesianPy.git
# 그냥 이 시스템에서(컨테이너에서) 쓸 것이다.
git config --global user.email "your@example.com" # 본인 이메일
git config --global user.name "Your Nmae" # 본인 아이디
git push # 자신의 깃헙 아이디와 비밀번호를 치면 (해당 저장소에 권한이 있다면) 성공한다.
!ls
figures pymc_intro_install.ipynb
%%writefile mymodel.py
# Import relevant modules
import pymc
import numpy as np
# Some data
n = 5*np.ones(4,dtype=int)
x = np.array([-.86,-.3,-.05,.73])
# Priors on unknown parameters
alpha = pymc.Normal('alpha',mu=0,tau=.01)
beta = pymc.Normal('beta',mu=0,tau=.01)
# Arbitrary deterministic function of parameters
@pymc.deterministic
def theta(a=alpha, b=beta):
"""theta = logit^{-1}(a+b)"""
return pymc.invlogit(a+b*x)
# Binomial likelihood for data
d = pymc.Binomial('d', n=n, p=theta, value=np.array([0.,1.,3.,5.]),\
observed=True)
Writing mymodel.py
!ls
figures mymodel.py pymc_intro_install.ipynb
apt-get install graphviz
conda install pydot
#Build a model out of these three variables
import pymc
import mymodel
model = pymc.Model(mymodel)
#Make a slightly pretty graph out of it
graph = pymc.graph.graph(model)
graph.write_png("graph.png")
True
from IPython.display import Image
Image(filename='graph.png')
%matplotlib inline
import pymc
import mymodel
S = pymc.MCMC(mymodel, db='pickle')
S.sample(iter=10000, burn=5000, thin=2)
pymc.Matplot.plot(S)
[-----------------100%-----------------] 10000 of 10000 complete in 0.9 secPlotting beta Plotting alpha Plotting theta_0 Plotting theta_1 Plotting theta_2 Plotting theta_3