Skip to content

Commit 1dec7a1

Browse files
sunxd3github-actions[bot]penelopeysm
authored
Export predict with 0.35 (#821)
* export `predict` * use mcmcchains when build doc * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Add MCMCChainsExt to docs build (#822) --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Penelope Yong <penelopeysm@gmail.com>
1 parent a765af3 commit 1dec7a1

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

docs/make.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@ using DynamicPPL: AbstractPPL
99
# consistent with that.
1010
using Distributions
1111
using DocumenterMermaid
12+
# load MCMCChains package extension to make `predict` available
13+
using MCMCChains
1214

1315
# Doctest setup
14-
DocMeta.setdocmeta!(DynamicPPL, :DocTestSetup, :(using DynamicPPL); recursive=true)
16+
DocMeta.setdocmeta!(
17+
DynamicPPL, :DocTestSetup, :(using DynamicPPL, MCMCChains); recursive=true
18+
)
1519

1620
makedocs(;
1721
sitename="DynamicPPL",
1822
# The API index.html page is fairly large, and violates the default HTML page size
1923
# threshold of 200KiB, so we double that.
2024
format=Documenter.HTML(; size_threshold=2^10 * 400),
21-
modules=[DynamicPPL],
25+
modules=[DynamicPPL, Base.get_extension(DynamicPPL, :DynamicPPLMCMCChainsExt)],
2226
pages=[
2327
"Home" => "index.md", "API" => "api.md", "Internals" => ["internals/varinfo.md"]
2428
],

docs/src/api.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,32 @@ Similarly, we can [`unfix`](@ref) variables, i.e. return them to their original
104104
unfix
105105
```
106106

107+
## Predicting
108+
109+
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.
110+
111+
The `predict` function has two main methods:
112+
113+
1. For `AbstractVector{<:AbstractVarInfo}` - useful when you have a collection of `VarInfo` objects representing posterior samples.
114+
2. For `MCMCChains.Chains` (only available when `MCMCChains.jl` is loaded) - useful when you have posterior samples in the form of an `MCMCChains.Chains` object.
115+
116+
```@docs
117+
predict
118+
```
119+
120+
### Basic Usage
121+
122+
The typical workflow for posterior prediction involves:
123+
124+
1. Fitting a model to observed data to obtain posterior samples
125+
2. Creating a new model instance with some variables marked as missing (unobserved)
126+
3. Using `predict` to generate samples for these missing variables based on the posterior parameter samples
127+
128+
When using `predict` with `MCMCChains.Chains`, you can control which variables are included in the output with the `include_all` parameter:
129+
130+
- `include_all=false` (default): Include only newly predicted variables
131+
- `include_all=true`: Include both parameters from the original chain and predicted variables
132+
107133
## Models within models
108134

109135
One can include models and call another model inside the model function with `left ~ to_submodel(model)`.

src/DynamicPPL.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export AbstractVarInfo,
115115
decondition,
116116
fix,
117117
unfix,
118+
predict,
118119
prefix,
119120
returned,
120121
to_submodel,

0 commit comments

Comments
 (0)