-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_predictive_posterior.jl
More file actions
41 lines (35 loc) · 1.13 KB
/
test_predictive_posterior.jl
File metadata and controls
41 lines (35 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using RxInfer
@marginalrule NormalMeanPrecision(:out_μ) (m_out::Uninformative, m_μ::UnivariateNormalDistributionsFamily, q_τ::Any) = begin
return missing
xi_μ, W_μ = weightedmean_precision(m_μ)
W_bar = mean(q_τ)
W = [W_bar -W_bar; -W_bar W_μ+W_bar]
xi = [zero(xi_μ); xi_μ]
return MvNormalWeightedMeanPrecision(xi, W)
end
@rule NormalMeanPrecision(:μ, Marginalisation) (m_out::Uninformative, q_τ::GammaShapeRate, ) = begin
return Uninformative()
end
@model function check_pred(x)
κ ~ GammaShapeRate(1, 10)
prediction ~ NormalMeanPrecision(x, κ)
γ ~ GammaShapeRate(1, 1)
y ~ NormalMeanPrecision(prediction, γ)
y ~ Uninformative()
end
@constraints function pred_constraints()
q(y, prediction, γ, κ) = q(y, prediction)q(γ)q(κ)
end
result = infer(
model = check_pred(),
data = (x=10,),
constraints = pred_constraints(),
initialization = @initialization(begin
q(γ) = GammaShapeRate(1, 1)
q(κ) = GammaShapeRate(1, 1)
end),
iterations = 20,
);
# @show result.posteriors[:prediction]
@show result.posteriors[:γ]
@show result.posteriors[:y]