ReactiveMP.jl
ReactiveMP.jl copied to clipboard
Ux rule suggestions
I have added a rule lookup with the RuleMethodError
to print the list of existing rules, with a corresponding test as part of the rule_method_error
testset.
The inference procedure
@model function test(y)
r ~ Gamma(1.,1.)
x ~ Bernoulli(r)
y ~ Beta(x,1.)
end
infer(model = test(), data = (y = 1.0,))
now returns:
ERROR: RuleMethodError: no method matching rule for the given arguments
Existing rule(s) for node:
Beta(μ(a) :: PointMass, μ(b) :: PointMass)
Possible fix, define:
@rule Beta(:a, Marginalisation) (q_out::PointMass, q_b::PointMass, ) = begin
return ...
end
I am happy with this result but I noticed that there is a clash with a functional form constrain error now:
ERROR: The expression `q(r)` has an undefined functional form of type `ProductOf{GammaShapeRate{Float64}, Beta{Float64}}`.
This is likely because the inference backend does not support the product of these distributions.
As a result, `RxInfer` cannot compute key quantities such as the `mean` or `var` of `q(r)`.
Possible solutions:
- Implement the `BayesBase.prod` method (refer to the `BayesBase` documentation for guidance).
- Use a functional form constraint to specify the posterior form with the `@constraints` macro. For example:
```julia
using ExponentialFamilyProjection
@constraints begin
q(r) :: ProjectedTo(NormalMeanVariance)
end
So, this existing rule look may also need to be implemented in there. What do you think?
fixes #397