Skip to content

Commit 58f4eab

Browse files
committed
Add initial parameters for multiple chains
1 parent 57868da commit 58f4eab

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

usage/sampling-options/index.qmd

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ typeof(transitions)
108108

109109
In Turing.jl, initial parameters for MCMC sampling can be specified using the `initial_params` keyword argument.
110110

111-
For single-chain sampling, the AbstractMCMC interface generally expects that you provide a completely flattened vector of parameters.
111+
For **single-chain sampling**, the AbstractMCMC interface generally expects that you provide a completely flattened vector of parameters.
112112

113113
```{julia}
114114
chn = sample(demo_model(), MH(), 5; initial_params=[1.0, -5.0])
@@ -148,6 +148,17 @@ init_x, init_y = rand(LKJCholesky(3, 0.5)), rand(MvNormal(zeros(3), I))
148148
chn = sample(demo_complex(), MH(), 5; initial_params=(x=init_x, y=init_y));
149149
```
150150

151+
For **multiple-chain sampling**, the `initial_params` keyword argument should be a vector with length equal to the number of chains being sampled.
152+
Each element of this vector should be the initial parameters for the corresponding chain, as described above.
153+
Thus, for example, a vector of vectors, or a vector of `NamedTuple`s, can be used.
154+
If you want to use the same initial parameters for all chains, you can use `fill`:
155+
156+
```{julia}
157+
initial_params = fill((x=1.0, y=-5.0), 3)
158+
chn = sample(demo_model(), MH(), MCMCThreads(), 5, 3; initial_params=initial_params)
159+
chn[:x][1,:], chn[:y][1,:]
160+
```
161+
151162
::: {.callout-important}
152163
## Upcoming changes in Turing v0.41
153164

0 commit comments

Comments
 (0)