Issues with porting Turing.jl to RxInfer.jl

Hi everyone, I’m trying to port a Turing.jl example to RxInfer.jl. However, the following throws an error; any tips on how to reformat?

using OrdinaryDiffEq
using SciMLSensitivity
using RxInfer

Y = [7, 6, 10, 8, 13, 17, 18, 19, 29, 27,
     39, 28, 45, 55, 41, 39, 41, 44, 28, 39,
     28, 34, 22, 12, 12, 11, 15, 16, 15, 12,
     7, 3, 1, 3, 4, 2, 2, 2, 0, 0];

function sir_ode!(du,u,p,t)
    (S,I,R,C) = u
    (β,c,γ) = p
    N = S+I+R
    infection = β*c*I/N*S
    recovery = γ*I
    @inbounds begin
        du[1] = -infection
        du[2] = infection - recovery
        du[3] = recovery
        du[4] = infection
    end
    nothing
end;

@model function bayes_sir(y)
    l = length(y)
    i₀  ~ Uniform(0.0,1.0)
    β ~ Uniform(0.0,1.0)
    I = i₀*1000.0
    u0=[1000.0-I,I,0.0,0.0]
    p=[β,10.0,0.25]
    tspan = (0.0,float(l))
    prob = ODEProblem(sir_ode!,
            u0,
            tspan,
            p)
    sol = solve(prob,
                Tsit5(),
                saveat = 1.0)
    sol_C = Array(sol)[4,:] # Cumulative cases
    sol_X = sol_C[2:end] - sol_C[1:(end-1)]
    for i in 1:l
      y[i] ~ Poisson(abs(sol_X[i]))
    end
end;

result = infer(
    model = bayes_sir(),
    data  = (y = Y, )
)

Error:

ERROR: MethodError: no method matching *(::GraphPPL.VariableRef{…}, ::Float64)

The line it is complaining about (and there are similar ones) is:

I = i₀*1000.0

Why can’t I transform in the model file?

PS. I’m not sure that RxInfer.jl can handle the ODE within the model loop, but I can write a discrete time model that it should be able to handle…

Hi @sdwfrost! Thanks for trying out RxInfer.jl!

Can you please duplicate this question on ReactiveBayes · Discussions · GitHub?

Dear @albertpod

I seemed to be able to fix this using ~, but now I run into the problem of extracting Float64 from my random variable to pass to the differential equation solver. I’ve posted this as a follow-up to the ask for a DifferentialEquations example in the RxInfer discussion.