Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
ac71f50
Make last to last!
xukai92 May 11, 2017
557df1a
Remove old comments
xukai92 May 11, 2017
f4ebf85
Improve transformation interface
xukai92 May 11, 2017
2daf6cc
Make VarInfo.trans a vector-of-vector
xukai92 May 11, 2017
0b201d2
Remove deepcopy from link/invlink
xukai92 May 11, 2017
478d9fd
Use realpart in expand
xukai92 May 11, 2017
3e7178b
Merge branch 'master' into reduce-deepcopy
xukai92 May 11, 2017
9d1c211
Improve last!
xukai92 May 11, 2017
efe151a
Make VarInfo.logp into a vector
xukai92 May 11, 2017
817ffc3
Remove deepcopy from ad.jl
xukai92 May 11, 2017
1738812
Remove duplicated expand from ad.jl
xukai92 May 11, 2017
ab444cb
Remove expand in runmodel
xukai92 May 11, 2017
6b78abd
Rename varibales in ad.jl
xukai92 May 11, 2017
e47fb3e
Give up improve AD
xukai92 May 11, 2017
04dfeff
Change link and invlink to in-place
xukai92 May 11, 2017
029a3f7
Fix HMC accept reate log
xukai92 May 11, 2017
e1a43a4
Remove expand in ad.jl
xukai92 May 11, 2017
59b7521
Remove deepcopy from leapfrog
xukai92 May 11, 2017
2d3daf9
Reduce deepcopy in HMCDA and NUTS
xukai92 May 11, 2017
6b0c2ac
Fix benchmark path bug
xukai92 May 11, 2017
d3cf32b
Fix model bug
xukai92 May 11, 2017
1fc34dc
Improve inv/link
xukai92 May 11, 2017
91e5f43
Remove deepcopy from hmcda
xukai92 May 11, 2017
a08f29c
Fix model name
xukai92 May 11, 2017
99a8be4
Remove expand! in leapfrog
xukai92 May 11, 2017
1854e01
Pass vi into recursion
xukai92 May 12, 2017
d5cd278
Reorder params
xukai92 May 12, 2017
0fdc4be
Use new leapfrog in HMCDA
xukai92 May 12, 2017
47f6342
Improve HMCDA
xukai92 May 12, 2017
63b4b02
Improve HMCDA code
xukai92 May 12, 2017
5c09dd8
Add info log to HMCDA
xukai92 May 12, 2017
f003531
Better alignment
xukai92 May 12, 2017
289b004
One more LDA run
xukai92 May 12, 2017
f13ac66
Make default chunksize setting only change in one run
xukai92 May 12, 2017
3a0b618
Better time recording and remove new find_H
xukai92 May 12, 2017
a023e20
Use new leapfrog in NUTS
xukai92 May 12, 2017
0be5254
Fix #245
xukai92 May 12, 2017
7bf7e65
Cache logp in NUTS
xukai92 May 12, 2017
ee500c0
Cache grad
xukai92 May 12, 2017
410634d
Merge observe of HMC and Void
xukai92 May 12, 2017
b68b60a
Improve observe code
xukai92 May 12, 2017
5e745da
Fix setchunksize
xukai92 May 12, 2017
bb25da0
Vectorize observe #255
xukai92 May 12, 2017
81f77a8
Much faster LDA (#117, #255)
May 13, 2017
b1f3c51
Increase max_treedepth for NUTS.
May 13, 2017
d8c2d41
Add NUTS to lda.run.
May 13, 2017
2278d1b
Faster MoC.
May 13, 2017
f958da2
Add a quick test
xukai92 May 13, 2017
7319a55
Merge branch 'reduce-deepcopy' of https://github.com/yebai/Turing.jl …
xukai92 May 13, 2017
4102830
Fix cache for win32
xukai92 May 13, 2017
a9be13d
Support new syntax for vec obs
xukai92 May 13, 2017
76b8917
sync model
xukai92 May 13, 2017
a1afe04
Assume vec for HMC
xukai92 May 13, 2017
af2b6c6
Vectorize construct for uni
xukai92 May 13, 2017
78abffb
Improve vec test
xukai92 May 13, 2017
3cabb33
Prepare test for vec Mv
xukai92 May 13, 2017
3f8a1fd
Remove another copy()
xukai92 May 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ matrix:
env: GROUP=MOC
- os: osx
env: GROUP=SV

allow_failures:
- env: GROUP=Test
os: osx
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ using Stan
CONFIG = Dict(
"model-list" => [
"gdemo-geweke",
"MoC",
# "MoC",
#"normal-loc",
"normal-mixture",
"simplegauss",
"gdemo",
"gauss",
"bernoulli",
#"negative-binomial",
"lda"
# "lda"
],

"test-level" => 2 # 1 = model lang, 2 = whole interface
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bernoulli-stan.run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using Stan

include(Pkg.dir("Turing")*"/benchmarks/benchmarkhelper.jl")
include(Pkg.dir("Turing")*"/example-models/stan-models/bernoulli-stan.data.jl")
include(Pkg.dir("Turing")*"/example-models/stan-models/bernoulli-stan..model.jl")
include(Pkg.dir("Turing")*"/example-models/stan-models/bernoulli-stan.model.jl")

stan_model_name = "bernoulli"
berstan = Stanmodel(name=stan_model_name, model=berstanmodel, nchains=1);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bernoulli.run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using Stan

include(Pkg.dir("Turing")*"/benchmarks/benchmarkhelper.jl")
include(Pkg.dir("Turing")*"/example-models/stan-models/bernoulli.data.jl")
include(Pkg.dir("Turing")*"/example-models/stan-models/bernoulli..model.jl")
include(Pkg.dir("Turing")*"/example-models/stan-models/bernoulli.model.jl")

bench_res = tbenchmark("HMC(1000, 0.25, 5)", "bermodel", "berdata")
logd = build_logd("Bernoulli Model", bench_res...)
Expand Down
17 changes: 10 additions & 7 deletions benchmarks/lda.run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ include(Pkg.dir("Turing")*"/benchmarks/benchmarkhelper.jl")
include(Pkg.dir("Turing")*"/example-models/stan-models/lda-stan.data.jl")
include(Pkg.dir("Turing")*"/example-models/stan-models/lda.model.jl")

bench_res = tbenchmark("HMCDA(1000, 0.65, 1.5)", "ldamodel", "data=ldastandata[1]")
bench_res[4].names = ["phi[1]", "phi[2]"]
logd = build_logd("LDA", bench_res...)

include(Pkg.dir("Turing")*"/benchmarks/"*"lda-stan.run.jl")
logd["stan"] = lda_stan_d
logd["time_stan"] = lda_time

print_log(logd)
setchunksize(60)

for alg in ["HMC(1000, 0.25, 6)", "HMCDA(1000, 0.65, 1.5)", "NUTS(2000, 1000, 0.65)"]
bench_res = tbenchmark(alg, "ldamodel", "data=ldastandata[1]")
bench_res[4].names = ["phi[1]", "phi[2]"]
logd = build_logd("LDA", bench_res...)
logd["stan"] = lda_stan_d
logd["time_stan"] = lda_time
print_log(logd)
end
2 changes: 1 addition & 1 deletion example-models/benchmarks/gauss.model.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@model gaussmodel(x) = begin
N = length(x)
lam = tzeros(Float64,N)
lam = tzeros(Real,N)
mu ~ Normal(0, sqrt(1000));
for i = 1:N
lam[i] ~ Gamma(1, 1)
Expand Down
110 changes: 110 additions & 0 deletions example-models/notebooks/.ipynb_checkpoints/BayesHmm-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"using Turing, Distributions\n",
"using PyPlot, PyCall"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"y = [ 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 2.0, 2.0, 2.0, 1.0, 1.0 ];\n",
"N = length(y); K = 3;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"@model BayesHmm(y) = begin\n",
" s = tzeros(Int64, N)\n",
" m = tzeros(Real, K)\n",
" T = Array{Array}(K)\n",
" for i = 1:K\n",
" T[i] ~ Dirichlet(ones(K)/K)\n",
" # m[i] ~ Normal(1, 0.1) # Defining m this way causes label-switching problem.\n",
" m[i] ~ Normal(i, 0.01)\n",
" end\n",
" s[1] ~ Categorical(ones(Float64, K)/K)\n",
" for i = 2:N\n",
" s[i] ~ Categorical(vec(T[s[i-1]]))\n",
" y[i] ~ Normal(m[s[i]], 0.01)\n",
" end\n",
" return(s, m)\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"g = Gibbs(300, HMC(1, 0.2, 5, :m, :T), PG(50, 1, :s))\n",
"c = sample(BayesHmm(y), g);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"describe(c)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"m = c[:m][111];\n",
"s = c[:s][111];\n",
"PyPlot.plot(y, linestyle=\"None\", marker=\"+\", color = \"r\")\n",
"PyPlot.plot(m[s], linestyle=\"-\", marker=\"*\", color = \"b\")"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernel_info": {
"name": "julia-0.5"
},
"kernelspec": {
"display_name": "Julia 0.5.0",
"language": "julia",
"name": "julia-0.5"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.5.0"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
210 changes: 210 additions & 0 deletions example-models/notebooks/BayesHmm2.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"using Turing, Distributions\n",
"using PyPlot, PyCall"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"y = [ 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 2.0, 2.0, 2.0, 1.0, 1.0 ];\n",
"N = length(y);\n",
"K = 3;"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Assume - `T` is a parameter\n",
" Assume - `m` is a parameter\n",
" Assume - `s` is a parameter\n",
" Observe - `y` is an observation\n"
]
},
{
"data": {
"text/plain": [
"BayesHmm (generic function with 4 methods)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"@model BayesHmm(y) = begin\n",
" s = tzeros(Int64, N)\n",
" m = tzeros(Dual, K)\n",
" T = Array{Array}(K)\n",
" for i = 1:K\n",
" T[i] ~ Dirichlet(ones(K)/K)\n",
" # m[i] ~ Normal(1, 0.1) # Defining m this way causes label-switching problem.\n",
" m[i] ~ Normal(i, 0.01)\n",
" end\n",
" s[1] ~ Categorical(ones(Float64, K)/K)\n",
" for i = 2:N\n",
" s[i] ~ Categorical(vec(T[s[i-1]]))\n",
" y[i] ~ Normal(m[s[i]], 0.01)\n",
" end\n",
" return(s, m, T)\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Turing.PG(50,1000,Turing.resampleSystematic,0.5,Set{Any}())"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"g1 = Gibbs(300, HMC(2, 0.2, 5, :m, :T), PG(50, 5, :s))\n",
"g2 = PG(50, 1000)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"T[1] = ForwardDiff.Dual{0,Float64}[Dual(0.117584),Dual(0.744224),Dual(0.138192)], T[1] ~ Distributions.Dirichlet{Float64}(alpha=[0.333333,0.333333,0.333333])\n",
"m[1] = Dual(0.9967711359430271), m[1] ~ Distributions.Normal{Float64}(μ=1.0, σ=0.01)\n",
"T[2] = ForwardDiff.Dual{0,Float64}[Dual(0.0064186),Dual(0.0065692),Dual(0.987012)], T[2] ~ Distributions.Dirichlet{Float64}(alpha=[0.333333,0.333333,0.333333])\n",
"m[2] = Dual(2.007863731847725), m[2] ~ Distributions.Normal{Float64}(μ=2.0, σ=0.01)\n",
"T[3] = ForwardDiff.Dual{0,Float64}[Dual(0.713092),Dual(0.234245),Dual(0.0526634)], T[3] ~ Distributions.Dirichlet{Float64}(alpha=[0.333333,0.333333,0.333333])\n",
"m[3] = Dual(2.9919946593762465), m[3] ~ Distributions.Normal{Float64}(μ=3.0, σ=0.01)\n",
"s[1] = Dual(3), s[1] ~ Distributions.Categorical{Float64}(K=3, p=[0.333333,0.333333,0.333333])\n"
]
}
],
"source": [
"s1 = @sample(BayesHmm(y), g1);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"describe(s1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"m = s1[:m][111];\n",
"s = s1[:s][111];\n",
"PyPlot.plot(y, linestyle=\"None\", marker=\"+\", color = \"r\")\n",
"PyPlot.plot(m[s], linestyle=\"-\", marker=\"*\", color = \"b\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"s2 = @sample(BayesHmm(y), g2);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"describe(s2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"m = s2[:m][150];\n",
"s = s2[:s][150];\n",
"PyPlot.plot(y, linestyle=\"None\", marker=\"+\", color = \"r\")\n",
"PyPlot.plot(m[s], linestyle=\"-\", marker=\"*\", color = \"b\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Julia 0.5.0",
"language": "julia",
"name": "julia-0.5"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.5.0"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Loading