ReactiveMP.jl icon indicating copy to clipboard operation
ReactiveMP.jl copied to clipboard

Multiple `RequireMarginals` with SP and `PointMass` constraint do not update/ask for missing rule

Open bartvanerp opened this issue 2 years ago • 0 comments

When using PointMass constraints in SP, the behaviour is incorrect as in this issue on RxInfer. Patching this using RequireMarginals on both adjacent nodes also results in either not updating the variables (example below) or in asking for missing rules (notebook).

Example

using RxInfer, LinearAlgebra

# adds missing rule (solved in addons PR)
@rule Categorical(:out, Marginalisation) (m_p::Dirichlet,) = begin
    return Categorical(normalize(mean(m_p), 1))
end

@model function model_issue()
    y = datavar(Vector{Float64})

    α ~ Dirichlet(0.01 .* ones(3))
    z_old ~ Categorical(α) where { pipeline = RequireMarginal(out) }
    z_new ~ Transition(z_old, diagm(ones(3))) where { pipeline = RequireMarginal(in) }
    y ~ Transition(z_new, diagm(ones(3)))

    return y, z_new, z_old, α

end

@constraints function constraints_issue()
    q(z_old) :: PointMass
end

results_combination = inference(
    model = model_issue(), 
    data  = ( y = [1.0, 0.0, 0.0], ),
    constraints = constraints_issue(),
    returnvars = ( α=KeepLast(), ),
)

bartvanerp avatar Nov 29 '22 14:11 bartvanerp