You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/tutorials/prob-interface.md
+14-2Lines changed: 14 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,13 +69,19 @@ nothing # hide
69
69
We often want to calculate the (unnormalized) probability density for an event.
70
70
This probability might be a prior, a likelihood, or a posterior (joint) density.
71
71
DynamicPPL provides convenient functions for this.
72
-
For example, we can calculate the joint probability of a set of samples (here drawn from the prior) with [`logjoint`](@ref):
72
+
To begin, let's define a model `gdemo`, condition it on a dataset, and draw a sample.
73
+
The returned sample only contains `μ`, since the value of `x` has already been fixed:
73
74
74
75
```@example probinterface
75
76
model = gdemo(length(dataset)) | (x=dataset,)
76
77
77
78
Random.seed!(124)
78
79
sample = rand(model)
80
+
```
81
+
82
+
We can then calculate the joint probability of a set of samples (here drawn from the prior) with [`logjoint`](@ref).
83
+
84
+
```@example probinterface
79
85
logjoint(model, sample)
80
86
```
81
87
@@ -87,10 +93,16 @@ using DataStructures
87
93
88
94
Random.seed!(124)
89
95
sample_dict = rand(OrderedDict, model)
96
+
```
97
+
98
+
`logjoint` can also be used on this sample:
99
+
100
+
```@example probinterface
90
101
logjoint(model, sample_dict)
91
102
```
92
103
93
-
The prior probability and the likelihood of a set of samples can be calculated with the functions [`loglikelihood`](@ref) and [`logjoint`](@ref), respectively:
104
+
The prior probability and the likelihood of a set of samples can be calculated with the functions [`logprior`](@ref) and [`loglikelihood`](@ref) respectively.
105
+
The log joint probability is the sum of these two quantities:
0 commit comments