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 067ac4c commit e4f6ee1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions docs/src/tutorials/prob-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,18 @@ 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:

```@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 +95,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 e4f6ee1

Please sign in to comment.