Skip to content

Commit b3c1ef6

Browse files
committed
address comments
1 parent c46c20c commit b3c1ef6

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

docs/src/manuals/inference/nonconjugate.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ We also assume that `m` and `p` are jointly independent with the `q(m, p) = q(m)
7373
Dropping the assumption of joint independence would require initializing messages for `m` and `p` without guarantees of convergence.
7474
Read more about factorization constraints in the [Constraints Specification](@ref user-guide-constraints-specification) guide.
7575

76-
The `ProjectedTo` structure is defined in the `ExponentialFamilyProjection` package. To fully explore its capabilities and hyper-parameters, we invite you to read the detailed [documentation](https://github.com/ReactiveBayes/ExponentialFamilyProjection.jl).
76+
!!! note
77+
The `ProjectedTo` structure is defined in the `ExponentialFamilyProjection` package. To fully explore its capabilities and hyper-parameters, we invite you to read the detailed [documentation](https://github.com/ReactiveBayes/ExponentialFamilyProjection.jl).
7778

7879
### Initialization
7980

@@ -96,33 +97,37 @@ result = infer(
9697
data = (y = data,),
9798
constraints = non_conjugate_model_constraints(),
9899
initialization = initialization,
99-
returnvars = KeepLast(),
100-
iterations = 5,
100+
iterations = 25,
101101
free_energy = true
102102
)
103103
```
104104

105105
### Analyzing the Results
106106

107-
Let's analyze the results using the `StatsPlots` package to visualize the resulting posteriors:
107+
Let's analyze the results using the `StatsPlots` package to visualize the resulting posteriors over individual VMP iterations:
108108

109109
```@example non-conjugacy-prior-likelihood
110110
using StatsPlots
111111
using Test #hide
112112
113-
p1 = plot(result.posteriors[:m], label = "Inferred `m`", fill = 0, fillalpha = 0.2)
114-
p1 = vline!(p1, [hidden_mean], label = "Hidden `m`")
113+
@test isapprox(mean(result.posteriors[:m][end]), hidden_mean, atol = 1e-1) #hide
114+
@test isapprox(mean(result.posteriors[:p][end]), hidden_precision, atol = 1e-1) #hide
115+
116+
@gif for (i, q) in enumerate(zip(result.posteriors[:m], result.posteriors[:p]))
117+
q_m = q[1]
118+
q_p = q[2]
115119
116-
p2 = plot(result.posteriors[:p], label = "Inferred `p`", fill = 0, fillalpha = 0.2)
117-
p2 = vline!(p2, [hidden_precision], label = "Hidden `p`")
120+
p1 = plot(q_m, label = "Inferred `m`", fill = 0, fillalpha = 0.2)
121+
p1 = vline!(p1, [hidden_mean], label = "Hidden `m`")
118122
119-
@test isapprox(mean(result.posteriors[:m]), hidden_mean, atol = 1e-1) #hide
120-
@test isapprox(mean(result.posteriors[:p]), hidden_precision, atol = 1e-1) #hide
123+
p2 = plot(q_p, label = "Inferred `p`", fill = 0, fillalpha = 0.2)
124+
p2 = vline!(p2, [hidden_precision], label = "Hidden `p`")
121125
122-
plot(p1, p2)
126+
plot(p1, p2; title = "Iteration $i")
127+
end fps = 15
123128
```
124129

125-
As we can see, the inference runs without any problems, and the estimated posteriors are quite close to the actual hidden parameters used to generate our dataset. We can also verify the [Bethe Free Energy](@ref lib-bethe-free-energy) values to ensure our result has converged:
130+
As we can see, the estimated posteriors are quite close to the actual hidden parameters used to generate our dataset. We can also verify the [Bethe Free Energy](@ref lib-bethe-free-energy) values to ensure our result has converged:
126131

127132
```@example non-conjugacy-prior-likelihood
128133
@test first(result.free_energy) > last(result.free_energy) #hide

0 commit comments

Comments
 (0)