6. 6
Documents
¢ User's guide
C http://pymc-devs.github.io/pymc/
¢ Tutorial
C https://github.com/fonnesbeck/pymc_tutorial
¢ Probabilistic Programming and Bayesian Methods for
Hackers
C http://nbviewer.ipython.org/github/CamDavidsonPilon/Probabilistic-
Programming-and-Bayesian-Methods-for-Hackers/blob/master/Prologue/
Prologue.ipynb
12. 12
PyMCの聞い圭: 篳
#v方協xの念に@pm.deterministicを原ける
n_data_points = 5 # in CH1 we had ~70 data points
@pm.deterministic
def lambda_(tau=tau, lambda_1=lambda_1, lambda_2=lambda_2):
out = np.zeros(n_data_points)
out[:tau] = lambda_1 # lambda before tau is lambda1
out[tau:] = lambda_2 # lambda after tau is lambda2
return out
lambdaの、tauで俳り紋える。返Aき議峰
http://nbviewer.ipython.org/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayes
ian-Methods-for-Hackers/blob/master/Chapter2_MorePyMC/MorePyMC.ipynb
Stanのtransformed
parameter blockに
¢
Q協議篳
15. 15
PyMCの聞い圭: sampling
#MCMCのための兜豚ヘ洞
model = pm.Model( [p, assignment, taus, centers ] )
map_ = pm.MAP( model )
map_.fit() #stores the fitted variables'values in
foo.value
#MCMC
mcmc = pm.MCMC( model )
mcmc.sample( 100000, 50000 )
http://nbviewer.ipython.org/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayesi
an-Methods-for-Hackers/blob/master/Chapter3_MCMC/IntroMCMC.ipynb
16. 16
PyMCの聞い圭: histogram, random
samples = [lambda_1.random() for i in range(20000)]
plt.hist(samples, bins=70, normed=True,
histtype="stepfilled")
http://nbviewer.ipython.org/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayes
ian-Methods-for-Hackers/blob/master/Chapter2_MorePyMC/MorePyMC.ipynb
17. 17
PyMCの聞い圭: traceplot
with pm.Model() as model:
x = pm.Normal('x', mu=0., sd=1)
y = pm.Normal('y', mu=pm.exp(x), sd=2., shape=(ndims, 1)) # here,
shape is telling us it's a vector rather than a scalar.
z = pm.Normal('z', mu=x + y, sd=.75, observed=zdata) # shape is
inferred from zdata
with model:
start = pm.find_MAP()
step = pm.NUTS()
trace = pm.sample(3000, step, start)
pm.traceplot(trace)
http://nbviewer.ipython.org/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayes
ian-Methods-for-Hackers/blob/master/Chapter2_MorePyMC/MorePyMC.ipynb
32. 32
Appendix: Theanoについて
¢ PythonでDeep learningvSのアルゴリズムg廾が竃栖る
ライブラリ(http://deeplearning.net/software/theano/)
C (Stacked) Auto Denoising Encoder, RBMなどのg廾巷_
C 協xした塀を催裏蛍で簧里気察▲灰鵐僖ぅ襪垢誂諒
C GPU(Nvidia CUDA)で麻をK双晒辛嬬
C 坪何でgcc, nvcc(CUDAのコンパイラ)を柵んでいる。
C HMCのサンプルg廾(http://deeplearning.net/tutorial/hmc.html)
33. 33
Appendix: HMC (Hamilton Monte-Carlo)
¢ Hamilton (Hyblid) Monte-Carlo
C ^\啻拭韻肇魯潺襯肇縫▲Hを協xして蛍下v方が
弌さい何蛍での卞啖を寄きくし、紳糞弔縫汽鵐廛
ング。
C e蛍が1w卞あたりの麻楚が宥械のMCMCより寄き
くなる。
http://xiangze.hatenablog.com/entry/2014/06/21/234930
34. 34
Appendix: HMC (Hamilton Monte-Carlo)
歌深:
¢ BDA 12.4 ^Hamiltonian Monte Carlo ̄のメモ
C http://ito-hi.blog.so-net.ne.jp/2014-06-12
¢ はじめてのMCMC (ハイブリッド?モンテカルロ)
C http://tatsyblog.wordpress.com/2014/03/22/%E3%81%AF%E3%81%98%
E3%82%81%E3%81%A6%E3%81%AEmcmc-%E3%83%8F%E3%82%A4%E3%83%96%E3
%83%AA%E3%83%83%E3%83%89%E3%83%BB%E3%83%A2%E3%83%B3%E3%83%86%
E3%82%AB%E3%83%AB%E3%83%AD/
¢ Theanog廾の盾h
C http://nbviewer.ipython.org/gist/xiangze/c2719235434bee796288