Skip to content

Commit

Permalink
Small improvements to probability docs
Browse files Browse the repository at this point in the history
  • Loading branch information
penelopeysm committed Oct 1, 2024
1 parent 51064ee commit dc65293
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions docs/src/tutorials/prob-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,19 @@ nothing # hide
We often want to calculate the (unnormalized) probability density for an event.
This probability might be a prior, a likelihood, or a posterior (joint) density.
DynamicPPL provides convenient functions for this.
For example, we can calculate the joint probability of a set of samples (here drawn from the prior) with [`logjoint`](@ref):
To begin, let's define a model `gdemo`, condition it on a dataset, and draw a sample.
The returned sample only contains `μ`, since the value of `x` has already been fixed:

```@example probinterface
model = gdemo(length(dataset)) | (x=dataset,)
Random.seed!(124)
sample = rand(model)
```

We can then calculate the joint probability of a set of samples (here drawn from the prior) with [`logjoint`](@ref).

```@example probinterface
logjoint(model, sample)
```

Expand All @@ -90,7 +96,8 @@ sample_dict = rand(OrderedDict, model)
logjoint(model, sample_dict)
```

The prior probability and the likelihood of a set of samples can be calculated with the functions [`loglikelihood`](@ref) and [`logjoint`](@ref), respectively:
The prior probability and the likelihood of a set of samples can be calculated with the functions [`logprior`](@ref) and [`loglikelihood`](@ref) respectively.
The log joint probability is the sum of these two quantities:

```@example probinterface
logjoint(model, sample) ≈ loglikelihood(model, sample) + logprior(model, sample)
Expand Down

0 comments on commit dc65293

Please sign in to comment.