ReactiveBayes / RxInfer.jl

Julia package for automated Bayesian inference on a factor graph with reactive message passing
MIT License
254 stars 24 forks source link

`initmarginals` broadcasting not working for `PointMass` #101

Closed bartvanerp closed 9 months ago

bartvanerp commented 1 year ago

It is possible to start of the inference procedure like

inference(
    model = model(nr_samples),
    initmarginals = (z= NormalMeanVariance(0,1), ),
    data = (y = y, ),
)

which initializes all variables z with the NormalMeanVariance(0,1) distribution. However, it throws an iteration error for PointMass objects, which need to be explicitly repeated as

inference(
    model = model(nr_samples),
    initmarginals = (z= repeat([PointMass(10)], nr_samples), ),
    data = (y = y, ),
)
bvdmitri commented 10 months ago

This task has been added to the milestone for tracking and prioritization.

bvdmitri commented 10 months ago

To solve this you simply need to add

Base.broadcastable(pm::PointMass) = Ref(pm)
bvdmitri commented 9 months ago

@Chengfeng-Jia This task has been added to the milestone for tracking and prioritization.

Chengfeng-Jia commented 9 months ago

I tried running the following code,


inference(
    model = model(nr_samples),
    initmarginals = (z= PointMass(1.0), ),
    data = (y = y, ),
)

No error reported, should it have been fixed? Is there a mistake in my understanding

bartvanerp commented 9 months ago

@Chengfeng-Jia was z an array of random variables in your model? In this case the issue seems to have fixed itself.

Chengfeng-Jia commented 9 months ago

I misunderstood before, now I changed z to an array of random variables. Indeed, this code doesn't work. initmarginals = (z= PointMass(0),)

However, if I change the code like this, it runs well and doesn't need to repeat initmarginals = (z= [PointMass(0)],)

Do you think it's fine, or still need the broadcast part

bartvanerp commented 9 months ago

I would prefer initmarginals = (z= PointMass(0),) to work, similarly as we can do initmarginals = (z= Normal(0,1),)

Chengfeng-Jia commented 9 months ago

Uh, I see.

bvdmitri commented 9 months ago

However, if I change the code like this, it runs well and doesn't need to repeat initmarginals = (z= [PointMass(0)],)

It's a "bug", it silently initializes only one (the first) variable

bartvanerp commented 9 months ago

Will be closed by https://github.com/biaslab/ReactiveMP.jl/pull/360