Skip to content
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
10 changes: 10 additions & 0 deletions ext/DynamicPPLMCMCChainsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,16 @@ If `include_all` is `false`, the returned `Chains` will contain only those varia
the samples in `chain`. This is useful when you want to sample only new variables from the posterior
predictive distribution.

!!! warning "Variables are treated as they occur in the model"
A variable drawn from a multivariate distribution in a single tilde-statement
(e.g. `x ~ MvNormal(...)` or `x ~ filldist(Normal(), n)`) is a *single* random
variable, not a collection of i.i.d. components. `predict` cannot fix a subset of
such a variable's components while resampling the rest; if `chain` supplies only
some components, the whole variable is silently resampled from the prior — the
predictions will look plausible but ignore what the chain says about that variable.
To treat components individually, declare them in a loop, e.g.
`for i in eachindex(x); x[i] ~ Normal(); end`.

# Examples
```jldoctest
using AbstractMCMC, Distributions, DynamicPPL, Random
Expand Down
17 changes: 14 additions & 3 deletions src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,11 @@ part of the variable should not be conditioned on.

However, note that in this case each element of the multivariate random variable must be on
its own tilde-statement. In other words, if we write `m ~ MvNormal(...)`, then we cannot
condition on only `m[1]`. (In principle, for some distributions this can be possible,
specifically when the distribution can be factorised into independent components, like an
MvNormal with a diagonal covariance matrix. However, this is not currently implemented.)
condition on only `m[1]`. Attempting to do so may abort model evaluation with an unrelated
`DimensionMismatch`, or the conditioning may be silently ignored, with `m` sampled afresh.
(In principle, for some distributions this can be possible, specifically when the
distribution can be factorised into independent components, like an MvNormal with a
diagonal covariance matrix. However, this is not currently implemented.)

```jldoctest condition
julia> @model function demo_mv(::Type{TV}=Float64) where {TV}
Expand Down Expand Up @@ -522,6 +524,15 @@ Return a `Model` which now treats the variables in `values` as fixed.

See also: [`unfix`](@ref), [`fixed`](@ref)

!!! warning "Fixing applies to whole variables"
Variables are treated as they occur in the model. A variable drawn from a multivariate
distribution in a single tilde-statement (e.g. `x ~ MvNormal(...)`) is a *single* random
variable, so a subset of its components cannot be fixed independently; only fixing the
variable in its entirety is supported. Attempting to fix a subset may silently collapse
the variable to just the supplied components, or leave it entirely unfixed and sampled
from the prior. Declare components in a loop (`x[i] ~ ...`) if you need to fix them
individually.

# Examples
## Simple univariate model
```jldoctest fix
Expand Down
Loading