Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rerun tutorials #117

Merged
merged 5 commits into from
May 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1,073 changes: 1,073 additions & 0 deletions html/03-bayesian-neural-network/03_bayesian-neural-network.html

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions markdown/00-introduction/00_introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ data[1:5]
```

```
5-element Vector{Bool}:
5-element Array{Bool,1}:
1
0
1
Expand Down Expand Up @@ -245,14 +245,14 @@ TuringTutorials.weave_file("00-introduction", "00_introduction.jmd")

Computer Information:
```
Julia Version 1.6.0
Commit f9720dc2eb (2021-03-24 12:55 UTC)
Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
JULIA_CMDSTAN_HOME = /home/cameron/stan/
JULIA_NUM_THREADS = 16
Expand All @@ -262,12 +262,12 @@ Environment:
Package Information:

```
Status `~/.julia/dev/TuringTutorials/tutorials/00-introduction/Project.toml`
[31c24e10] Distributions v0.24.15
[c7f686f2] MCMCChains v4.7.3
[91a5bcdd] Plots v1.11.1
Status `~/.julia/dev/TuringTutorials/tutorials/00-introduction/Project.toml`
[31c24e10] Distributions v0.24.18
[c7f686f2] MCMCChains v4.9.0
[91a5bcdd] Plots v1.12.0
[f3b207a7] StatsPlots v0.14.19
[fce5fe82] Turing v0.15.1
[fce5fe82] Turing v0.15.18
[9a3f8284] Random

```
Binary file modified markdown/00-introduction/figures/00_introduction_10_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified markdown/00-introduction/figures/00_introduction_5_1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified markdown/00-introduction/figures/00_introduction_9_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ Package Information:

```
Status `~/.julia/dev/TuringTutorials/tutorials/01-gaussian-mixture-model/Project.toml`
[31c24e10] Distributions v0.24.15
[c7f686f2] MCMCChains v4.7.3
[91a5bcdd] Plots v1.11.1
[31c24e10] Distributions v0.24.18
[c7f686f2] MCMCChains v4.9.0
[91a5bcdd] Plots v1.12.0
[f3b207a7] StatsPlots v0.14.19
[fce5fe82] Turing v0.15.12
[fce5fe82] Turing v0.15.18
[9a3f8284] Random

```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 15 additions & 15 deletions markdown/02-logistic-regression/02_logistic-regression.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe(chain)
```

```
2-element Vector{MCMCChains.ChainDataFrame}:
2-element Array{MCMCChains.ChainDataFrame,1}:
Summary Statistics (4 x 7)
Quantiles (4 x 6)
```
Expand Down Expand Up @@ -334,14 +334,14 @@ TuringTutorials.weave_file("02-logistic-regression", "02_logistic-regression.jmd

Computer Information:
```
Julia Version 1.6.0
Commit f9720dc2eb (2021-03-24 12:55 UTC)
Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
JULIA_CMDSTAN_HOME = /home/cameron/stan/
JULIA_NUM_THREADS = 16
Expand All @@ -351,20 +351,20 @@ Environment:
Package Information:

```
Status `~/.julia/dev/TuringTutorials/tutorials/02-logistic-regression/Project.toml`
[a93c6f00] DataFrames v0.22.6
Status `~/.julia/dev/TuringTutorials/tutorials/02-logistic-regression/Project.toml`
[a93c6f00] DataFrames v1.0.1
[b4f34e82] Distances v0.10.2
[31c24e10] Distributions v0.24.15
[5789e2e9] FileIO v1.6.5
[31c24e10] Distributions v0.24.18
[5789e2e9] FileIO v1.8.0
[38e38edf] GLM v1.4.1
[c7f686f2] MCMCChains v4.7.3
[cc2ba9b6] MLDataUtils v0.5.3
[872c559c] NNlib v0.7.17
[91a5bcdd] Plots v1.11.1
[ce6b1742] RDatasets v0.7.4
[4c63d2b9] StatsFuns v0.9.7
[c7f686f2] MCMCChains v4.9.0
[cc2ba9b6] MLDataUtils v0.5.4
[872c559c] NNlib v0.7.19
[91a5bcdd] Plots v1.12.0
[ce6b1742] RDatasets v0.7.5
[4c63d2b9] StatsFuns v0.9.8
[f3b207a7] StatsPlots v0.14.19
[fce5fe82] Turing v0.15.1
[fce5fe82] Turing v0.15.18
[9a3f8284] Random

```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
110 changes: 19 additions & 91 deletions markdown/03-bayesian-neural-network/03_bayesian-neural-network.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ The end of this tutorial provides some code that can be used to generate more ge
# Turn a vector into a set of weights and biases.
function unpack(nn_params::AbstractVector)
W₁ = reshape(nn_params[1:6], 3, 2);
b₁ = reshape(nn_params[7:9], 3)
b₁ = nn_params[7:9]

W₂ = reshape(nn_params[10:15], 2, 3);
b₂ = reshape(nn_params[16:17], 2)
b₂ = nn_params[16:17]

Wₒ = reshape(nn_params[18:19], 1, 2);
bₒ = reshape(nn_params[20:20], 1)
bₒ = nn_params[20:20]
return W₁, b₁, W₂, b₂, Wₒ, bₒ
end

Expand Down Expand Up @@ -146,20 +146,6 @@ N = 5000
ch = sample(bayes_nn(hcat(xs...), ts), HMC(0.05, 4), N);
```

```
Error: MethodError: ReverseDiff.TrackedReal{Float64, Float64, ReverseDiff.T
rackedArray{Float64, Float64, 2, Matrix{Float64}, Matrix{Float64}}}(::Forwa
rdDiff.Dual{ForwardDiff.Tag{ReverseDiff.var"#105#107"{DataType, Tuple{}, Va
l{(1,)}}, Float64}, Float64, 1}) is ambiguous. Candidates:
(T::Type{var"#s31"} where var"#s31"<:Real)(x::ForwardDiff.Dual) in Tracke
r at /home/cameron/.julia/packages/Tracker/YNNTM/src/lib/real.jl:111
ReverseDiff.TrackedReal{V, D, O}(value) where {V, D, O} in ReverseDiff at
/home/cameron/.julia/packages/ReverseDiff/iHmB4/src/tracked.jl:56
Possible fix, define
ReverseDiff.TrackedReal{V, D, O}(::ForwardDiff.Dual) where {V, D, O}
```





Expand All @@ -170,11 +156,6 @@ Now we extract the weights and biases from the sampled chain. We'll use these pr
theta = MCMCChains.group(ch, :nn_params).value;
```

```
Error: UndefVarError: ch not defined
```





Expand All @@ -200,11 +181,7 @@ Z = [nn_forward([x, y], theta[i, :])[1] for x=x_range, y=y_range]
contour!(x_range, y_range, Z)
```

```
Error: UndefVarError: ch not defined
```


![](figures/03_bayesian-neural-network_7_1.png)



Expand Down Expand Up @@ -242,11 +219,7 @@ Z = [nn_predict([x, y], theta, n_end)[1] for x=x_range, y=y_range]
contour!(x_range, y_range, Z)
```

```
Error: UndefVarError: theta not defined
```


![](figures/03_bayesian-neural-network_9_1.png)



Expand All @@ -263,11 +236,7 @@ anim = @gif for i=1:n_end
end every 5
```

```
Error: UndefVarError: theta not defined
```


![](figures/03_bayesian-neural-network_10_1.gif)



Expand All @@ -294,20 +263,6 @@ advi = ADVI(10, 5_000)
q_hat = vi(m, advi, q);
```

```
Error: MethodError: ReverseDiff.TrackedReal{Float64, Float64, ReverseDiff.T
rackedArray{Float64, Float64, 2, Matrix{Float64}, Matrix{Float64}}}(::Forwa
rdDiff.Dual{ForwardDiff.Tag{ReverseDiff.var"#105#107"{DataType, Tuple{}, Va
l{(1,)}}, Float64}, Float64, 1}) is ambiguous. Candidates:
(T::Type{var"#s31"} where var"#s31"<:Real)(x::ForwardDiff.Dual) in Tracke
r at /home/cameron/.julia/packages/Tracker/YNNTM/src/lib/real.jl:111
ReverseDiff.TrackedReal{V, D, O}(value) where {V, D, O} in ReverseDiff at
/home/cameron/.julia/packages/ReverseDiff/iHmB4/src/tracked.jl:56
Possible fix, define
ReverseDiff.TrackedReal{V, D, O}(::ForwardDiff.Dual) where {V, D, O}
```



```julia
samples = transpose(rand(q_hat, 5000))
Expand All @@ -317,11 +272,6 @@ ch_vi = Chains(reshape(samples, size(samples)..., 1), string.(MCMCChains.namesin
theta = MCMCChains.group(ch_vi, :nn_params).value;
```

```
Error: UndefVarError: q_hat not defined
```



```julia
# Plot the average prediction.
Expand All @@ -334,11 +284,7 @@ Z = [nn_predict([x, y], theta, n_end)[1] for x=x_range, y=y_range]
contour!(x_range, y_range, Z)
```

```
Error: UndefVarError: theta not defined
```


![](figures/03_bayesian-neural-network_13_1.png)



Expand Down Expand Up @@ -408,20 +354,6 @@ num_samples = 500
ch2 = sample(bayes_nn_general(hcat(xs...), ts, network_shape, num_params), NUTS(0.65), num_samples);
```

```
Error: MethodError: ReverseDiff.TrackedReal{Float64, Float64, ReverseDiff.T
rackedArray{Float64, Float64, 2, Matrix{Float64}, Matrix{Float64}}}(::Forwa
rdDiff.Dual{ForwardDiff.Tag{ReverseDiff.var"#105#107"{DataType, Tuple{}, Va
l{(1,)}}, Float64}, Float64, 1}) is ambiguous. Candidates:
(T::Type{var"#s31"} where var"#s31"<:Real)(x::ForwardDiff.Dual) in Tracke
r at /home/cameron/.julia/packages/Tracker/YNNTM/src/lib/real.jl:111
ReverseDiff.TrackedReal{V, D, O}(value) where {V, D, O} in ReverseDiff at
/home/cameron/.julia/packages/ReverseDiff/iHmB4/src/tracked.jl:56
Possible fix, define
ReverseDiff.TrackedReal{V, D, O}(::ForwardDiff.Dual) where {V, D, O}
```



```julia
# This function makes predictions based on network shape.
Expand All @@ -440,11 +372,7 @@ Z = [nn_predict([x, y], params2, length(ch2), network_shape)[1] for x=x_range, y
contour!(x_range, y_range, Z)
```

```
Error: UndefVarError: ch2 not defined
```


![](figures/03_bayesian-neural-network_15_1.png)



Expand All @@ -457,19 +385,19 @@ This has been an introduction to the applications of Turing and Flux in defining
To locally run this tutorial, do the following commands:
```julia, eval = false
using TuringTutorials
TuringTutorials.weave_file("03-bayesian-neural-network", "03_bayesian-neural-network.jmd")
TuringTutorials.weave_file("03-bayesian-neural-network/", "03_bayesian-neural-network.jmd")
```

Computer Information:
```
Julia Version 1.6.0
Commit f9720dc2eb (2021-03-24 12:55 UTC)
Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
JULIA_CMDSTAN_HOME = /home/cameron/stan/
JULIA_NUM_THREADS = 16
Expand All @@ -479,13 +407,13 @@ Environment:
Package Information:

```
Status `~/.julia/dev/TuringTutorials/tutorials/03-bayesian-neural-network/Project.toml`
[b5ca4192] AdvancedVI v0.1.1
[76274a88] Bijectors v0.8.13
[587475ba] Flux v0.12.0
[91a5bcdd] Plots v1.11.1
[37e2e3b7] ReverseDiff v1.7.0
[fce5fe82] Turing v0.15.1
Status `~/.julia/dev/TuringTutorials/tutorials/03-bayesian-neural-network/Project.toml`
[b5ca4192] AdvancedVI v0.1.2
[76274a88] Bijectors v0.9.1
[587475ba] Flux v0.12.1
[91a5bcdd] Plots v1.12.0
[37e2e3b7] ReverseDiff v1.8.0
[fce5fe82] Turing v0.15.18
[9a3f8284] Random

```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading