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

Splatting does not work (with non-linear node) #122

Closed bartvanerp closed 3 months ago

bartvanerp commented 1 year ago

The following code excerpt fails:

function foo(x...)
    return sum(x)
end

@model function model_test()
    z = randomvar(10)
    for k in 1:10
        z[k] ~ NormalMeanVariance(0.0, 1.0)
    end
    x ~ foo(z...)
    y = datavar(Float64)
    y ~ NormalMeanVariance(x, 1.0)

end

with error MethodError: no method matching as_variable(::FactorGraphModel, ::RandomVariable, ::RandomVariable, ::RandomVariable, ::RandomVariable, ::RandomVariable, ::RandomVariable, ::RandomVariable, ::RandomVariable, ::RandomVariable, ::RandomVariable).

It likely has to do with the splat operator, possibly in combination with the non-linear node. This functionality is very useful for dealing with multiple random variables going into a non-linear node. This prevents us from having to write foo(z[1], z[2], ....), which is not automatable when the number is a hyperparameter.

wouterwln commented 10 months ago

Should also be fixed in graphppl 4.0 but I'll close this myself after we merge everything and I've checked.

albertpod commented 7 months ago

@wouterwln why is this issue closed? This doesn't seem working in RxInfer.jl

wouterwln commented 7 months ago

Ah, it is fixed in the new GraphPPL release, we should probably reopen until it is fully merged