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

Initialization macro lacks features compared to model macro

Open bartvanerp opened this issue 2 months ago • 3 comments

There are differences between the @initialization macro and the @model macro, which might be confusing for users. An example:

@model function model() 
    x ~ NormalMeanPrecision(0.0, 1.0) # allowed
    x ~ Normal(mean = 0.0, precision = 1.0) # allowed
end

@initialization begin
    q(x) = Normal(mean = 0.0, precision = 1.0) # not allowed
    q(x) = NormalMeanPrecision(0.0, 1.0) # allowed
end

Would be nice if we can streamline this.

bartvanerp avatar Sep 09 '25 13:09 bartvanerp

The issue here is that the code that transforms Normal(mean = 0.0, precision = 1.0) to NormalMeanPrecision(0.0, 1.0) lives in GraphPPL.jl. But the @initialization macro is not part of GraphPPL, but RxInfer. The proper fix would be to move this code maybe to BayesBase.jl and let both GraphPPL and RxInfer reuse it.

bvdmitri avatar Sep 12 '25 10:09 bvdmitri

Don't you think we can do a similar thing to GraphPPL where we can use the GraphPPLs default_parametrization and factor_alias in RxInfer as well to transform this code? I don't see why if RxInfer depends on GraphPPL why we wouldn't reuse this function. The actual transformation is something that happens in RxInfer anyway:

https://github.com/ReactiveBayes/RxInfer.jl/blob/e8b1215e68451baa7bfad55c541a61354eba916e/src/model/graphppl.jl#L240

wouterwln avatar Sep 23 '25 07:09 wouterwln

Hm, I think you're right @wouterwln

bvdmitri avatar Sep 23 '25 09:09 bvdmitri