LoadError: MethodError: objects of type Float64 are not callable

I’m working with SDEs. I’m very new to Julia so I’m just messing around with preexisting code to learn. Here is the error:
LoadError: MethodError: objects of type Float64 are not callable
in expression starting at [name]COVID_Project.jl:80
F(x::Vector{Float64}, p::NamedTuple{(:T, :theta, :death_rate, :m_eiu, :m_ih, :nu, :sigma, :gamma_e, :gamma_i, :gamma_h, :gamma_r, :gamma_v, :R0, :beta_bar, :beta_n, :N, :beta_stoch), Tuple

using InstantiateFromURL

using LinearAlgebra, Statistics, Random, SparseArrays

using OrdinaryDiffEq, StochasticDiffEq

using Parameters
using Plots
gr(fmt=:png);

p_gen = @with_kw ( T = 550.0, theta = 0.3, death_rate = 0.01, m_eiu = 0.1,
m_ih = 0.5, nu = 1.0/20, sigma = 0.03,
gamma_e = 1/8, gamma_i = 1/18, gamma_h = 1/20, gamma_v = 1/60,
gamma_r = 1/500, R0=1.4, beta_bar = 0.75, beta_n = 0.4,
beta_stoch = (t, p) -> p.beta_n )
pop_size = 3.3e8
beta_bar = 0.75
function F(x, p, t)
    s, e, i, iu, hr, hd, rd, ru, d, v, R0 = x
    @unpack gamma_e, gamma_i, gamma_h, gamma_r, gamma_v, R0, beta_bar, beta_n, beta_stoch, theta, nu, death_rate, m_eiu, m_ih = p

    # removed varying R0 from Python version for now
    beta_e = beta_n
    beta_i = 0.75 * beta_n
    beta_iu = 1.5 * beta_n
    beta_h = 0.25 * beta_n

    function vax_rate(t)
        if t < 270
            return gamma_v = 0
        else
            return gamma_v = 1/60
        end
    end
    # compartment interactions
    ci = (m_eiu * beta_e * e) + (m_ih * beta_i * i) + (m_eiu * beta_iu * theta * iu) + (m_ih * beta_h * hr) + (m_ih * beta_h * hd)

    return [(-(s)* ci) - (gamma_v * s);        # s_dot
            (s * ci) - (gamma_e * e) - (gamma_v * e);   # e_dot
            (gamma_e * e - gamma_i * i);        # i_dot
            ((1 - theta) * gamma_i * i) - (gamma_i * iu) - (gamma_v * iu);    # iu_dot
            theta * (1 - (death_rate / theta)) * gamma_i * i - (gamma_h * hr); #hr_dot
            (death_rate * gamma_i * i) - gamma_h * hd; # hd_dot
            (gamma_h * hr) - (gamma_v * rd); # rd_dot
            (gamma_i * iu) - (gamma_v * ru); #ru_dot
            (gamma_v * s) + (gamma_v * e) + (gamma_v * iu) + (gamma_v * rd) + (gamma_v * ru); # v_dot
            gamma_h * hd; # d_dot
            nu*(beta_bar(t, p) - beta_n);# dR₀/dt
            ]
end

function G(x, p, t)
    s, e, i, iu, hr, hd, rd, ru, d, v, R0 = x
    @unpack gamma_e, gamma_i, gamma_h, gamma_r, gamma_v, R0, beta_bar, beta_n, beta_stoch, theta, nu, death_rate, m_eiu, m_ih = p

    return [0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; sigma*sqrt(beta_n);]
end

p_gen = @with_kw ( T = 550.0, theta = 0.3, death_rate = 0.01, m_eiu = 0.1,
m_ih = 0.5, nu = 1.0/20, sigma = 0.03,
gamma_e = 1/8, gamma_i = 1/18, gamma_h = 1/20,
gamma_r = 1/500, gamma_v = 1/60, R0=1.4, beta_bar = 0.75, beta_n = 0.4, N = 3.3e8,
beta_stoch = (t, p) -> p.beta_n )
p =  p_gen()  # use all defaults
i_0 = 0
e_0 = 7_500 / pop_size
iu_0 = 0
hr_0 = 0
hd_0 =0
rd_0 = 0
ru_0 = 0
v_0 = 0
d_0 = 0
s_0 = 1 - i_0 - e_0 - iu_0 - hr_0 - hd_0 - rd_0 - ru_0 - v_0 - d_0
b_0 = beta_bar
x_0 = [s_0, i_0, e_0, iu_0, hr_0, hd_0, rd_0, ru_0, v_0, d_0, b_0]

prob = SDEProblem(F, G, x_0, (0, p.T), p)

sol_1 = solve(prob, SOSRI());
@show length(sol_1.t);

sol_2 = solve(prob, SOSRI())
plot(sol_1, vars=[2], title = "Number of Infections", label = "Trajectory 1",
     lm = 2, xlabel = "t", ylabel = "i(t)")
plot!(sol_2, vars=[2], label = "Trajectory 2", lm = 2, ylabel = "i(t)")

This is probably the issue. beta_bar is a number, but you’re trying to call it like a function.

2 Likes