Skip to content

Commit 84d395b

Browse files
trappmartinalecloudenbackrikhuijzer
authored
Replaces #1437 - additional documentation for filldist and arraydist (#1751)
* Add note for `filldist` and Index variables closes #1422 * updated docs for filldist and arraydist * Update docs/src/using-turing/guide.md Co-authored-by: Rik Huijzer <[email protected]> Co-authored-by: alecloudenback <[email protected]> Co-authored-by: Rik Huijzer <[email protected]>
1 parent 60b7d3f commit 84d395b

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

docs/src/using-turing/guide.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,41 @@ The `Gibbs` sampler can be used to specify unique automatic differentation backe
545545

546546
For more details of compositional sampling in Turing.jl, please check the corresponding [paper](http://proceedings.mlr.press/v84/ge18b.html).
547547

548+
### Working with filldist and arraydist
549+
550+
Turing provides `filldist(dist::Distribution, n::Int)` and `arraydist(dists::AbstractVector{<:Distribution})` as a simplified interface to construct product distributions, e.g., to model a set of variables that share the same structure but vary by group.
551+
552+
#### Constructing product distributions with filldist
553+
554+
The function `filldist` provides a general interface to construct product distributions over distributions of the same type and parameterisation.
555+
Note that, in contrast to the product distribution interface provided by Distributions.jl (`Product`), `filldist` supports product distributions over univariate or multivariate distributions.
556+
557+
Example usage:
558+
559+
```julia
560+
@model function demo(x, g)
561+
k = length(unique(g))
562+
a ~ filldist(Exponential(), k) # = Product(fill(Exponential(), k))
563+
mu = a[g]
564+
x .~ Normal.(mu)
565+
end
566+
```
567+
568+
#### Constructing product distributions with arraydist
569+
570+
The function `arraydist` provides a general interface to construct product distributions over distributions of varying type and parameterisation.
571+
Note that in contrast to the product distribution interface provided by Distributions.jl (`Product`), `arraydist` supports product distributions over univariate or multivariate distributions.
572+
573+
Example usage:
574+
575+
```julia
576+
@model function demo(x, g)
577+
k = length(unique(g))
578+
a ~ arraydist([Exponential(i) for i in 1:k])
579+
mu = a[g]
580+
x .~ Normal.(mu)
581+
end
582+
```
548583

549584
### Working with MCMCChains.jl
550585

@@ -638,3 +673,4 @@ In all other cases progress logs are displayed with
638673
[TerminalLoggers.jl](https://github.com/c42f/TerminalLoggers.jl). Alternatively,
639674
if you provide a custom visualization backend, Turing uses it instead of the
640675
default backend.
676+

0 commit comments

Comments
 (0)