Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ using DynamicPPL: AbstractPPL
# consistent with that.
using Distributions
using DocumenterMermaid
# load MCMCChains package extension to make `predict` available
using MCMCChains

# Doctest setup
DocMeta.setdocmeta!(DynamicPPL, :DocTestSetup, :(using DynamicPPL); recursive=true)
DocMeta.setdocmeta!(
DynamicPPL, :DocTestSetup, :(using DynamicPPL, MCMCChains); recursive=true
)

makedocs(;
sitename="DynamicPPL",
Expand Down
26 changes: 26 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,32 @@ Similarly, we can [`unfix`](@ref) variables, i.e. return them to their original
unfix
```

## Predicting

DynamicPPL provides functionality for generating samples from the posterior predictive distribution through the `predict` function. This allows you to use posterior parameter samples to generate predictions for unobserved data points.

```@docs
predict
```

The `predict` function has two main methods:

1. For `AbstractVector{<:AbstractVarInfo}` - useful when you have a collection of `VarInfo` objects representing posterior samples.
2. For `MCMCChains.Chains` - useful when you have posterior samples in the form of a `Chains` object from MCMCChains.jl.

### Basic Usage

The typical workflow for posterior prediction involves:

1. Fitting a model to observed data to obtain posterior samples
2. Creating a new model instance with some variables marked as missing (unobserved)
3. Using `predict` to generate samples for these missing variables based on the posterior parameter samples

When using `predict` with `MCMCChains.Chains`, you can control which variables are included in the output with the `include_all` parameter:

- `include_all=false` (default): Include only newly predicted variables
- `include_all=true`: Include both parameters from the original chain and predicted variables

## Models within models

One can include models and call another model inside the model function with `left ~ to_submodel(model)`.
Expand Down
1 change: 1 addition & 0 deletions src/DynamicPPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export AbstractVarInfo,
decondition,
fix,
unfix,
predict,
prefix,
returned,
to_submodel,
Expand Down
Loading