This example was automatically generated from a Jupyter notebook in the RxInferExamples.jl repository.
We welcome and encourage contributions! You can help by:
- Improving this example
- Creating new examples
- Reporting issues or bugs
- Suggesting enhancements
Visit our GitHub repository to get started. Together we can make RxInfer.jl even better! 💪
Precision without Mean Field
This example is part of the Universal Inference section, which runs inference in a broad class of models by approximating what has no closed form. Here every node has a closed form under mean field, and we drop the factorisation instead. The model is a Gaussian with unknown mean and precision,
\[\begin{aligned} x &\sim \mathcal{N}(m_0, v_0), \qquad \tau \sim \Gamma(a_0, b_0),\\ y_i &\sim \mathcal{N}(x, \tau^{-1}), \quad i = 1, \dots, N, \end{aligned}\]
where $\Gamma(a, b)$ is the Gamma distribution with shape $a$ and rate $b$. Under the mean-field factorisation $q(x, \tau) = q(x)\,q(\tau)$, variational message passing has closed-form updates and is known to be overconfident about $\tau$ (Bishop, 2006, Section 10.1.3). Belief propagation does not factorise the posterior, and its messages have no closed form. The message of an observation towards $\tau$ integrates the likelihood against the message of $x$, a Gaussian $\mathcal{N}(m_x, v_x)$:
\[\ell_{i \to \tau}(\tau) = \log \int \mathcal{N}(y_i \mid x, \tau^{-1})\, \mathcal{N}(x \mid m_x, v_x)\, dx = \log \mathcal{N}(y_i \mid m_x, v_x + \tau^{-1}).\]
This is not in the Gamma family: besides $\frac{1}{2}\log\tau$ it has the term $-\frac{1}{2}\log(1 + v_x\tau)$, which comes from the uncertainty of $x$ and which variational message passing leaves out. fallback = NaturalGradientPropagation(), natural-gradient message passing (Lukashchuk et al., 2026), gives each such message a Gamma site. At each iteration the site moves by a damped step towards its target $\eta^\star = G(q)^{-1}\,\mathrm{Cov}_q[T(\tau), \ell(\tau)]$, where $T(\tau) = (\log\tau, \tau)$ is the sufficient statistic of the Gamma and $G$ its Fisher information under the marginal $q(\tau)$. At the fixed point, each site equals its target. The paper uses this model as its example of vanishing edge uncertainty. We compare both schemes with the exact posterior on a grid.
using RxInfer, BayesBase, Distributions, LinearAlgebra, StableRNGs
using Plots, PrettyTables, Printf
Data
The priors are those of the paper, $x \sim \mathcal{N}(0, 25)$ and $\tau \sim \Gamma(2, 1)$. We draw a true mean and precision from them, and then ten observations.
m0, v0, a0, b0 = 0.0, 25.0, 2.0, 1.0
function draw(rng, N)
x = rand(rng, Normal(m0, sqrt(v0)))
τ = rand(rng, Gamma(a0, 1 / b0))
return (; x, τ, y = x .+ randn(rng, N) ./ sqrt(τ))
end
data = draw(StableRNG(7), 10)
y = data.y
@printf("true x = %.3f, true τ = %.3f, N = %d\n", data.x, data.τ, length(y))
true x = -10.134, true τ = 2.876, N = 10The exact posterior
On a grid of $(x, \log\tau)$ with 400 points in each direction, the joint log-density gives the exact marginals of $x$ and $\tau$ and the evidence $p(y)$. The grid spans ten standard deviations on each side of a first estimate of the posterior, computed from the sample mean and variance.
logjoint(x, τ, y) = logpdf(Normal(m0, sqrt(v0)), x) + logpdf(Gamma(a0, 1 / b0), τ) + sum(yi -> logpdf(Normal(x, 1 / sqrt(τ)), yi), y)
function exact_posterior(y; n = 400)
N, ȳ = length(y), sum(y) / length(y)
s² = sum(abs2, y .- ȳ) / N
a, b = a0 + N / 2, b0 + N * s² / 2
sd_u, τ̂ = 1 / sqrt(a), a / b
half = 10 / sqrt(1 / v0 + N * τ̂ * exp(-3sd_u))
xs = range(ȳ - half, ȳ + half, length = n)
us = range(log(τ̂) - 10sd_u, log(τ̂) + 10sd_u, length = n)
L = [logjoint(x, exp(u), y) + u for x in xs, u in us]
P = exp.(L .- maximum(L))
Z = sum(P)
hx, hu = step(xs), step(us)
px, pu = vec(sum(P; dims = 2)) ./ (Z * hx), vec(sum(P; dims = 1)) ./ (Z * hu)
τs = exp.(us)
Eτ = sum(pu .* τs) * hu
return (;
xs, us, px, pu, logevidence = maximum(L) + log(Z * hx * hu),
x = (mean = sum(px .* xs) * hx, sd = sqrt(sum(px .* xs .^ 2) * hx - (sum(px .* xs) * hx)^2)),
τ = (mean = Eτ, sd = sqrt(sum(pu .* τs .^ 2) * hu - Eτ^2)),
)
end
# The inclusive divergences KL(p ‖ q) of the marginals, on the grid: τ's in log τ, with the Jacobian
function kl_x(exact, q)
h = step(exact.xs)
return sum(p * (log(p) - logpdf(q, x)) for (p, x) in zip(exact.px, exact.xs) if p > 0) * h
end
function kl_τ(exact, q)
h = step(exact.us)
return sum(p * (log(p) - logpdf(q, exp(u)) - u) for (p, u) in zip(exact.pu, exact.us) if p > 0) * h
end
exact = exact_posterior(y)
@printf("exact: E[x] = %.4f, sd(x) = %.4f, E[τ] = %.4f, sd(τ) = %.4f, log p(y) = %.4f\n", exact.x.mean, exact.x.sd, exact.τ.mean, exact.τ.sd, exact.logevidence)
exact: E[x] = -10.3223, sd(x) = 0.1929, E[τ] = 3.1747, sd(τ) = 1.2457, log p(y) = -13.0780Mean field: variational message passing
With RxInfer's NormalMeanPrecision node and the constraint $q(x, \tau) = q(x)\,q(\tau)$, every message has a closed form, and the iterations need initial marginals for both variables.
@model function normal_model(y, likelihood)
x ~ NormalMeanVariance(m0, v0)
τ ~ Gamma(shape = a0, rate = b0)
for i in eachindex(y)
y[i] ~ likelihood(x, τ)
end
end
vmp = infer(
model = normal_model(likelihood = NormalMeanPrecision), data = (y = y,),
constraints = MeanField(), iterations = 100, free_energy = true,
initialization = @initialization(begin
q(x) = NormalMeanVariance(m0, v0)
q(τ) = GammaShapeRate(a0, b0)
end),
)
q_vmp = (x = last(vmp.posteriors[:x]), τ = last(vmp.posteriors[:τ]))
(x = NormalWeightedMeanPrecision(-328.2053221234823, 31.788425885252696), τ = GammaShapeRate(7.0, 2.204833721615009))Natural-gradient propagation with RxInfer's Normal node
Without a factorisation, the same model is handled by fallback = NaturalGradientPropagation(). NormalMeanPrecision has rules for mean field only, so the fallback computes both of its messages. $x$ and $\tau$ are connected through every observation, which forms a loop, so belief propagation starts from initial messages; we initialise each variable with its prior. Each of the twenty sites takes one step per iteration, with the default step size alpha = 0.5 and momentum beta = 0.2, and 60 iterations are enough for all of them to settle.
initial_messages = @initialization begin
μ(x) = NormalMeanVariance(m0, v0)
μ(τ) = GammaShapeRate(a0, b0)
end
fit(likelihood, y) = infer(
model = normal_model(likelihood = likelihood), data = (y = y,),
initialization = initial_messages, iterations = 60,
fallback = NaturalGradientPropagation(), free_energy = true, report = true,
)
ngmp_native = fit(NormalMeanPrecision, y)
q_native = (x = last(ngmp_native.posteriors[:x]), τ = last(ngmp_native.posteriors[:τ]))
(x = NormalWeightedMeanPrecision(-323.57820071791855, 31.39886022444732), τ = GammaShapeRate(6.325364614259367, 1.985954621489099))The report shows the sites of each variable and the messages that formed them. Towards $\tau$, the fallback sends the belief propagation message $\ell_{i \to \tau}$, computed against the Gaussian message of $x$, so the ten sites of $\tau$ are Gamma distributions. Towards $x$, the belief propagation message would integrate the likelihood against the message of $\tau$, a Gamma distribution. The fallback does not do this. It averages the log-likelihood over that message, as variational message passing does with the marginal, and the report warns about it.
ngmp_native.report.approximations
Approximations: 2 of 2 posteriors approximated, 1 warning
Diagnostics
╭─────────┬─────────────────────────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │ where │ what │
├─────────┼─────────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ warning │ y[1:10] ~ NormalMeanPrecision(x, τ) │ under BP, the messages towards μ average over another variable's message: variational, not exact BP │
╰─────────┴─────────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────╯
Approximated posteriors
╭─────────────────────────────────────┬─────────┬───────┬──────────┬───────────────────────────────────────────────────────────────────────────────╮
│ Messages from │ towards │ exact │ fallback │ expectations │
├─────────────────────────────────────┴─────────┴───────┴──────────┴───────────────────────────────────────────────────────────────────────────────┤
│ x: natural-gradient propagation, 10 sites, 600 steps │
├─────────────────────────────────────┬─────────┬───────┬──────────┬───────────────────────────────────────────────────────────────────────────────┤
│ x ~ NormalMeanVariance(0.0, 25.0) │ out │ 1 │ 0 │ │
│ y[1:10] ~ NormalMeanPrecision(x, τ) │ μ │ 0 │ 600 │ GammaShapeRate → UnconstrainedLegendre │
├─────────────────────────────────────┴─────────┴───────┴──────────┴───────────────────────────────────────────────────────────────────────────────┤
│ τ: natural-gradient propagation, 10 sites, 600 steps │
├─────────────────────────────────────┬─────────┬───────┬──────────┬───────────────────────────────────────────────────────────────────────────────┤
│ τ ~ GammaShapeRate(2.0, 1.0) │ out │ 1 │ 0 │ │
│ y[1:10] ~ NormalMeanPrecision(x, τ) │ τ │ 0 │ 600 │ NormalMeanVariance → GaussHermite, NormalWeightedMeanPrecision → GaussHermite │
╰─────────────────────────────────────┴─────────┴───────┴──────────┴───────────────────────────────────────────────────────────────────────────────╯
Joints and energies by the fallback
╭─────────────────────────────────────┬─────────────────┬───────┬──────────────────────────╮
│ Node │ computed │ times │ how │
├─────────────────────────────────────┼─────────────────┼───────┼──────────────────────────┤
│ y[1:10] ~ NormalMeanPrecision(x, τ) │ average energy │ 600 │ expectation │
│ y[1:10] ~ NormalMeanPrecision(x, τ) │ joint of (μ, τ) │ 600 │ joint Laplace, converged │
╰─────────────────────────────────────┴─────────────────┴───────┴──────────────────────────╯
Expectations: ExactSum, GaussHermite, UnconstrainedLegendre, QuantileLegendreThe belief propagation message towards the mean
Integrated against a Gamma message $\Gamma(a, b)$ of $\tau$, the likelihood of $y_i$ is a Student-t density in $x$ with $2a$ degrees of freedom, centred at $y_i$ with scale $\sqrt{b / a}$. We write the likelihood as a custom node, defined by its log-density, and give it a rule for this one message. The message towards $\tau$ is still computed by the fallback. The Student-t is not Gaussian, so it gets its own Gaussian site, which moves towards its target like the others.
struct PrecisionObservation{X, T} <: ContinuousUnivariateDistribution
x::X
τ::T
end
BayesBase.logpdf(d::PrecisionObservation, y) = (log(d.τ) - log(2π) - d.τ * (y - d.x)^2) / 2
BayesBase.insupport(::PrecisionObservation, y) = true
@define_factor_node(node = PrecisionObservation, type = Stochastic, interfaces = [:out, :x, :τ])
# Belief propagation's message towards x: ∫ N(y | x, 1/τ) Γ(τ | a, b) dτ, a Student-t in x
@define_message_update_rule(
node = PrecisionObservation, target = :x,
args = (q[:out]::PointMass, m[:τ]::GammaDistributionsFamily),
body = (args) -> begin
a, b = shape(args.m[:τ]), rate(args.m[:τ])
return LocationScale(mean(args.q[:out]), sqrt(b / a), TDist(2a))
end,
)
ngmp = fit(PrecisionObservation, y)
q_ngmp = (x = last(ngmp.posteriors[:x]), τ = last(ngmp.posteriors[:τ]))
(x = NormalWeightedMeanPrecision(-293.16154765258636, 28.39469073450028), τ = GammaShapeRate(6.286661397946343, 1.9629942034533368))The report now shows that every message of the observations towards $x$ comes from the rule, and it has no warnings:
ngmp.report.approximations
Approximations: 2 of 2 posteriors approximated, no warnings
Approximated posteriors
╭──────────────────────────────────────┬─────────┬───────┬──────────┬───────────────────────────────────────────────────────────────────────────────╮
│ Messages from │ towards │ exact │ fallback │ expectations │
├──────────────────────────────────────┴─────────┴───────┴──────────┴───────────────────────────────────────────────────────────────────────────────┤
│ x: natural-gradient propagation, 10 sites, 600 steps │
├──────────────────────────────────────┬─────────┬───────┬──────────┬───────────────────────────────────────────────────────────────────────────────┤
│ x ~ NormalMeanVariance(0.0, 25.0) │ out │ 1 │ 0 │ │
│ y[1:10] ~ PrecisionObservation(x, τ) │ x │ 600 │ 0 │ │
├──────────────────────────────────────┴─────────┴───────┴──────────┴───────────────────────────────────────────────────────────────────────────────┤
│ τ: natural-gradient propagation, 10 sites, 600 steps │
├──────────────────────────────────────┬─────────┬───────┬──────────┬───────────────────────────────────────────────────────────────────────────────┤
│ τ ~ GammaShapeRate(2.0, 1.0) │ out │ 1 │ 0 │ │
│ y[1:10] ~ PrecisionObservation(x, τ) │ τ │ 0 │ 600 │ NormalMeanVariance → GaussHermite, NormalWeightedMeanPrecision → GaussHermite │
╰──────────────────────────────────────┴─────────┴───────┴──────────┴───────────────────────────────────────────────────────────────────────────────╯
Joints and energies by the fallback
╭──────────────────────────────────────┬─────────────────┬───────┬──────────────────────────╮
│ Node │ computed │ times │ how │
├──────────────────────────────────────┼─────────────────┼───────┼──────────────────────────┤
│ y[1:10] ~ PrecisionObservation(x, τ) │ average energy │ 600 │ expectation │
│ y[1:10] ~ PrecisionObservation(x, τ) │ joint of (x, τ) │ 600 │ joint Laplace, converged │
╰──────────────────────────────────────┴─────────────────┴───────┴──────────────────────────╯
Expectations: ExactSum, GaussHermite, UnconstrainedLegendre, QuantileLegendreResults
row(name, q, F) = [name mean(q.x) std(q.x) mean(q.τ) std(q.τ) kl_x(exact, q.x) kl_τ(exact, q.τ) F]
rows = [
row("mean field (VMP)", q_vmp, last(vmp.free_energy));
row("NGMP, Normal node", q_native, last(ngmp_native.free_energy));
row("NGMP, BP towards x", q_ngmp, last(ngmp.free_energy));
"exact" exact.x.mean exact.x.sd exact.τ.mean exact.τ.sd 0.0 0.0 -exact.logevidence
]
pretty_table(rows; column_labels = ["", "E[x]", "sd(x)", "E[τ]", "sd(τ)", "KL(p ‖ q), x", "KL(p ‖ q), τ", "free energy"], formatters = [fmt__printf("%.4f", 2:5), fmt__printf("%.2e", 6:7), fmt__printf("%.4f", 8:8)], fit_table_in_display_horizontally = false)
┌────────────────────┬──────────┬────────┬────────┬────────┬──────────────┬──────────────┬─────────────┐
│ │ E[x] │ sd(x) │ E[τ] │ sd(τ) │ KL(p ‖ q), x │ KL(p ‖ q), τ │ free energy │
├────────────────────┼──────────┼────────┼────────┼────────┼──────────────┼──────────────┼─────────────┤
│ mean field (VMP) │ -10.3247 │ 0.1774 │ 3.1748 │ 1.2000 │ 1.29e-02 │ 1.51e-03 │ 13.1163 │
│ NGMP, Normal node │ -10.3054 │ 0.1785 │ 3.1850 │ 1.2664 │ 1.62e-02 │ 2.15e-04 │ 12.3620 │
│ NGMP, BP towards x │ -10.3245 │ 0.1877 │ 3.2026 │ 1.2773 │ 6.20e-03 │ 5.16e-04 │ 12.3225 │
│ exact │ -10.3223 │ 0.1929 │ 3.1747 │ 1.2457 │ 0.00e+00 │ 0.00e+00 │ 13.0780 │
└────────────────────┴──────────┴────────┴────────┴────────┴──────────────┴──────────────┴─────────────┘With the belief propagation message towards $x$, the spread of the posterior of $x$ is within 3% of the exact one. The mean-field posterior is 8% narrower: it is a Gaussian with the precision $1/v_0 + N\,\mathbb{E}[\tau]$, as if $\tau$ were known. With RxInfer's Normal node, the messages towards $x$ average over the message of $\tau$ on each edge, which does not include that observation, and the posterior of $x$ is further from the exact one than the mean-field posterior.
The mean-field $q(\tau)$ is too narrow, and the one from natural-gradient propagation is a little too wide. On this data set, the latter is closer.
The mean-field free energy is a bound, above $-\log p(y)$. The free energy of natural-gradient propagation is the Bethe free energy, with the average energies of the nodes without rules. The model has a loop through the observations, so this free energy is a diagnostic of the fixed point and not a bound. Here it is below $-\log p(y)$.
τs = exp.(exact.us)
plot(τs, exact.pu ./ τs; color = :black, linewidth = 2, label = "exact", xlabel = "τ", ylabel = "density", xlims = (0, quantile(q_ngmp.τ, 0.9999)))
plot!(τs, pdf.(q_vmp.τ, τs); color = :orange, linewidth = 2, label = "mean field (VMP)")
plot!(τs, pdf.(q_ngmp.τ, τs); color = :blue, linewidth = 2, label = "NGMP, BP towards x")
vline!([data.τ]; color = :gray, linestyle = :dot, label = "true τ")

As the data grow
Lukashchuk et al. measure how the inclusive divergence $\mathrm{KL}(p \,\|\, q)$ of each marginal decreases with the number of observations, for instances whose true mean and precision are drawn from the priors. We repeat this for $N$ from 4 to 64, with ten instances for each $N$.
Ns = [4, 8, 16, 32, 64]
instances = 10
function divergences(N, k)
d = draw(StableRNG(1000N + k), N)
reference = exact_posterior(d.y)
v = infer(
model = normal_model(likelihood = NormalMeanPrecision), data = (y = d.y,), constraints = MeanField(), iterations = 100,
initialization = @initialization(begin
q(x) = NormalMeanVariance(m0, v0)
q(τ) = GammaShapeRate(a0, b0)
end),
)
n = fit(PrecisionObservation, d.y)
qv, qn = (last(v.posteriors[:x]), last(v.posteriors[:τ])), (last(n.posteriors[:x]), last(n.posteriors[:τ]))
settled = isempty(RxInfer.diagnostics(n.report))
return (; vmp = (kl_x(reference, qv[1]), kl_τ(reference, qv[2])), ngmp = (kl_x(reference, qn[1]), kl_τ(reference, qn[2])), shapes = (shape(qv[2]), shape(qn[2]), reference.τ.mean^2 / reference.τ.sd^2), settled)
end
results = [divergences(N, k) for N in Ns, k in 1:instances]
average(f) = [sum(f, results[j, :]) / instances for j in eachindex(Ns)]
kl = (vmp_x = average(r -> r.vmp[1]), vmp_τ = average(r -> r.vmp[2]), ngmp_x = average(r -> r.ngmp[1]), ngmp_τ = average(r -> r.ngmp[2]))
# the slope of log KL against log N, by least squares
slope(values) = (A = [ones(length(Ns)) log.(Ns)]; (A \ log.(values))[2])
@printf("slopes of log KL in log N: τ: VMP %.2f, NGMP %.2f; x: VMP %.2f, NGMP %.2f\n", slope(kl.vmp_τ), slope(kl.ngmp_τ), slope(kl.vmp_x), slope(kl.ngmp_x))
@printf("KL of x, VMP / NGMP at N = %s: %s\n", join(Ns, ", "), join([@sprintf("%.1f", r) for r in kl.vmp_x ./ kl.ngmp_x], ", "))
@printf("KL of τ, VMP / NGMP at N = %s: %s\n", join(Ns, ", "), join([@sprintf("%.1f", r) for r in kl.vmp_τ ./ kl.ngmp_τ], ", "))
slopes of log KL in log N: τ: VMP -1.64, NGMP -1.82; x: VMP -1.77, NGMP -1.80
KL of x, VMP / NGMP at N = 4, 8, 16, 32, 64: 2.2, 2.0, 2.3, 2.3, 2.3
KL of τ, VMP / NGMP at N = 4, 8, 16, 32, 64: 0.5, 0.7, 0.8, 0.8, 0.9p_x = plot(Ns, kl.vmp_x; marker = :circle, color = :orange, label = "mean field (VMP)", xscale = :log2, yscale = :log10, xlabel = "N", ylabel = "KL(p ‖ q)", title = "x")
plot!(p_x, Ns, kl.ngmp_x; marker = :circle, color = :blue, label = "NGMP, BP towards x")
p_τ = plot(Ns, kl.vmp_τ; marker = :circle, color = :orange, label = "mean field (VMP)", xscale = :log2, yscale = :log10, xlabel = "N", ylabel = "KL(p ‖ q)", title = "τ")
plot!(p_τ, Ns, kl.ngmp_τ; marker = :circle, color = :blue, label = "NGMP, BP towards x")
plot!(p_τ, Ns, kl.vmp_τ[end] .* (Ns ./ Ns[end]) .^ -2; color = :gray, linestyle = :dot, label = "∝ N⁻²")
plot!(p_τ, Ns, kl.vmp_τ[end] .* (Ns ./ Ns[end]) .^ -3; color = :gray, linestyle = :dash, label = "∝ N⁻³")
plot(p_x, p_τ; size = (1000, 400), bottom_margin = 5Plots.mm, left_margin = 5Plots.mm)

The grey lines fall as $N^{-2}$ and $N^{-3}$ and pass through the mean-field divergence at $N = 64$. For the mean, natural-gradient propagation is closer to the exact posterior at every $N$, by a factor of about two, and both divergences fall at the same rate. For the precision, both also fall at about the same rate, close to $N^{-2}$. (The fitted slopes between $N = 4$ and $64$ are above $-2$, because the small $N$ are not yet in the limit.) Here natural-gradient propagation is not better: on average its divergence is larger, twice that of mean field at $N = 4$ and within 20% of it at $N = 64$. The shapes of the Gamma distributions explain why. The exact posterior of $\tau$ is close to a Gamma with shape $a_0 + (N - 1)/2$, because integrating out $x$ removes one half. The mean-field shape is exactly $a_0 + N/2$, half a unit too large. The shape from natural-gradient propagation is close to $a_0 + N/2 - 1$, half a unit too small. Each site $\ell_{i \to \tau}$ includes the uncertainty of $x$ through $v_x$, but the $N$ sites include it separately, and together they remove twice as much as the joint integral does. At $N = 64$, averaged over the instances:
j = findfirst(==(64), Ns)
shapes = [sum(r -> r.shapes[k], results[j, :]) / instances for k in 1:3]
@printf("shape of q(τ) at N = 64: VMP %.3f, NGMP %.3f, exact (moment-matched) %.3f; a₀ + N/2 = %.1f\n", shapes[1], shapes[2], shapes[3], a0 + 32)
shape of q(τ) at N = 64: VMP 34.000, NGMP 32.991, exact (moment-matched) 33.501; a₀ + N/2 = 34.0Lukashchuk et al. report that the divergence of the precision falls as $N^{-3}$ under natural-gradient propagation, compared with $N^{-2}$ under mean field. With the messages used here, the belief propagation messages in both directions, we find the same rate for both, and the shapes above suggest $N^{-2}$ for both. In this model, natural-gradient propagation improves the posterior of the mean, which keeps the uncertainty of $\tau$.
Summary
- Without mean field,
fallback = NaturalGradientPropagation()gives the precision Gamma sites from the belief propagation messages, which include the uncertainty of the mean. Towards the mean, the fallback averages over the message of the precision instead of integrating against it, and the report warns about this. One rule, the Student-t message, makes that message a belief propagation message too. - With belief propagation messages in both directions, the posterior of the mean is about twice as close to the exact one as the mean-field posterior, measured by the divergence, at every $N$ we tried. The posterior of the precision is a little too wide where the mean-field posterior is too narrow, and on average it is not closer: both divergences fall as about $N^{-2}$.
References
- M. Lukashchuk, K. Yemets, A. Ledbetter and İ. Şenöz (2026). Information geometry of message passing. arXiv:2608.15922.
- C. M. Bishop (2006). Pattern Recognition and Machine Learning, Section 10.1.3. Springer.
This example was automatically generated from a Jupyter notebook in the RxInferExamples.jl repository.
We welcome and encourage contributions! You can help by:
- Improving this example
- Creating new examples
- Reporting issues or bugs
- Suggesting enhancements
Visit our GitHub repository to get started. Together we can make RxInfer.jl even better! 💪
This example was executed in a clean, isolated environment. Below are the exact package versions used:
For reproducibility:
- Use the same package versions when running locally
- Report any issues with package compatibility
Status `/tmp/jl_kQqZki/Project.toml`
[b4ee3484] BayesBase v1.7.0
⌃ [31c24e10] Distributions v0.25.134
[91a5bcdd] Plots v1.41.10
[08abe8d2] PrettyTables v3.5.1
[86711068] RxInfer v6.2.0
[860ef19b] StableRNGs v1.1.0
[37e2e46d] LinearAlgebra v1.13.0
[de0858da] Printf v1.11.0
Info Packages marked with ⌃ have new versions available and may be upgradable.