1
using Distributions
xxxxxxxxxx
1
1
using Plots
xxxxxxxxxx
1
1
using Random
xxxxxxxxxx
1
1
using LaTeXStrings
0x00003039
-870096391
1072918504
-1812426662
1073255081
-733866021
1073404543
807620846
1073368448
1919433844
1072852359
-1314842017
1073052936
-914011144
1072968597
1597808632
1073364414
-945588292
1073128917
1585669299
1073044155
-362113007
1073100625
-166402106
1073460158
-1907020342
721295190
-750225566
-1300227565
382
0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
0x00000000000000000000000000000000
1002
0
xxxxxxxxxx
1
1
Random.seed!(12345)
1×5 Array{Float64,2}:
1.78268 -1.39893 -0.917769 -1.0372 -1.4627
xxxxxxxxxx
1
begin
2
# Initialize
3
nBurnin = 50 # burn in count
4
nChains = 5 # Markov Chains
5
6
# Define Transition Operator
7
P(x,chains) = rand(Normal(0.5*x,1),1,chains) # 1x5
8
nTransitions = 1000
9
x = zeros(nTransitions,nChains)
10
x[1,:] = randn(1,nChains) # 초기값 평균 0, 분산 1 인 정규분포에서 샘플링
11
end
-0.9210058061011899
x
1
begin
2
for iT in 2:nTransitions
3
x[iT,:] = P(x[iT-1],nChains)
4
end
5
x[end]
6
end
x
10
9
10
1
begin
2
minn = min(x...)
3
maxx = max(x...)
4
#https://discourse.julialang.org/t/plots-jl-layout-macro-usage/11024
5
l = [[a ; b] c ]
6
plot([nBurnin,nBurnin],[minn,maxx],linecolor=:black,linewidth=3,
7
label="~Burnin",legend=:bottomright)
8
p1=plot!(x[1:100,:],label="",title="First 100 Samples",titlefont=font(10))
9
plot([nBurnin,nBurnin],[minn,maxx],linecolor=:black,linewidth=3,
10
label="~Burnin",legend=:bottomright)
11
p2=plot!(x,label="",title="Entire Chain",titlefont=font(10))
12
13
# Display Samples from stationary distribution
14
samples = x[nBurnin+1:end,:]
15
μ = trunc(mean(samples),digits=6)
16
σ = trunc(std(samples),digits=6)
17
p3=histogram(samples[:],bins=100,label="Markov Chian\nSamples",
18
title=L"\mu=%$μ, \sigma=%$σ)",titlefont=font(10),alpha=0.5)
19
plot(p1,p2,p3,layout=l)
20
end