Skip to content

Commit ac0ce7a

Browse files
committed
updates to doc
1 parent c58b39a commit ac0ce7a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

docs/src/gibbs.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ end
116116

117117
where the model doesn't need to know the details of the `state` type, as long as it can access the `log_joint` function.
118118

119+
Additionally, we define a couple of helper functions to transform between the sampler representation and the model representation of the parameters values.
120+
In this simple example, the model representation is a vector, and the sampler representation is a named tuple.
121+
122+
```julia
123+
function flatten(nt::NamedTuple)
124+
return only(values(nt))
125+
end
126+
127+
function unflatten(vec::AbstractVector, group::Tuple)
128+
return NamedTuple((only(group) => vec,))
129+
end
130+
```
131+
119132
## Sampler Packages
120133

121134
To illustrate the `AbstractMCMC` interface, we will first implement two very simple Metropolis-Hastings samplers: random walk and static proposal.
@@ -358,15 +371,13 @@ tau2_true = 2.0 # True variance
358371
x_data = rand(Normal(mu_true, sqrt(tau2_true)), N)
359372
```
360373

361-
```
362-
363-
Then we can create a `HierNormal` model with the data.
374+
Then we can create a `HierNormal` model, with the data we just generated.
364375

365376
```julia
366377
hn = HierNormal((x=x_data,))
367378
```
368379

369-
sampling is easy: we use random walk MH for `mu` and prior MH for `tau2`, because `tau2` has support on positive real numbers.
380+
Using Gibbs sampling allows us to use random walk MH for `mu` and prior MH for `tau2`, because `tau2` has support only on positive real numbers.
370381

371382
```julia
372383
samples = sample(

0 commit comments

Comments
 (0)