-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
I'm trying to run the following example taken from the Genify documentation. genify runs without error on the provided function, but when I try to sample from the model, I get an error:
ERROR: MethodError: no method matching dynamo_generator(::UInt64, ::LineNumberNode, ::TypeVar, ::Type{typeof(Genify.splice)}, ::NTuple{7, DataType})
Closest candidates are:
dynamo_generator(::UInt64, ::Any, ::Any, ::Any)
@ IRTools ~/.julia/packages/IRTools/ntYVg/src/reflection/dynamo.jl:140`Here is the code; is this a Gen or a Genify issue?
using Random, Distributions
using Gen, Genify
using Plots
function sir_model(T::Int, init_pop::Vector{Int},
β::Float64=0.5, γ::Float64=0.02)
# Initialize population history
pop_history = zeros(Int, 3, T)
pop_history[:, 1] = init_pop
tot_pop = sum(init_pop)
for t in 2:T
susceptible, infected, recovered = pop_history[:, t-1]
# Sample number of individuals who are newly infected and recovered
newly_infected = rand(Binomial(susceptible, β * infected / tot_pop))
newly_recovered = rand(Binomial(infected, γ))
# Update the population counts
susceptible -= newly_infected
infected += newly_infected - newly_recovered
recovered += newly_recovered
pop_history[:, t] = [susceptible, infected, recovered]
end
return pop_history
end;
pop_history = sir_model(40, [990, 10, 0], 0.5, 0.25)
plot(pop_history', labels=["Susceptible" "Infected" "Recovered"],
xlabel="Day", ylabel="Population", title="SIR Model")
# Transform the `sir_model` method by providing its type signature
gen_sir_model = genify(sir_model, Int, Vector{Int}, Float64, Float64);
# Sample a trace from the model where 50 people were infected on day 10
trace, weight = Gen.generate(gen_sir_model, (40, [990, 10, 0], 0.5, 0.25),
choicemap((:newly_infected => 10 - 1, 100)))
# Check that trace has the right value
@assert trace[:newly_infected => 10 - 1] == 100
# Plot sampled trace
plot_sir(get_retval(trace))Metadata
Metadata
Assignees
Labels
No labels