Hello everybody,
I have already asked a question on the same topic (ODEs parameter estimation) but unfortunately I am experiencing some early user issues which I cannot understand how to solve.
I am currently using the SciMLSensitivity.jl package to solve a parameter estimation problem with a specific cost function (Not the standard L2Loss).
I have two questions on this matter:
1) When running the following code
function SIDTHEfun(du, u, p, t)
s, i, d, t, h, e = u
α, δ, γ, σ, τ = p
λ = 0.1 # coefficient Lambda (fixed)
du[1] = -s * i * α # dS/dt
du[2] = s * i * α - (γ + λ) * i # dI/dt
du[3] = i * γ - d * (λ + δ) # dD/dt
du[4] = δ * d - (σ + τ) * t # dT/dt
du[5] = (i + d) * λ + t * σ # dH/dt
du[6] = t * τ # dE/dt
end
u0 = [S_data[1]; I_data[1]; D_data[1]; T_data[1]; H_data[1]; E_data[1]]
α0 = 0.25
γ0 = 0.12
δ0 = 0.01
σ0 = 0.02
τ0 = 0.02
p0 = [α0, γ0, δ0, σ0, τ0]
# First simulation with initial condition parameters
tspan = (1.0, N_mhe)
tsteps = collect(range(1, stop = N_mhe, length = N_mhe))
prob = ODEProblem(SIDTHEfun, u0, tspan, p0)
function simulate(p)
newprob = remake(prob, p = p)
solsim = solve(newprob, Tsit5(), saveat = tsteps, abstol = 1e-8, reltol = 1e-8)
return reduce(hcat,solsim.u)
end
ymeas = measure_mat[:, 1:N_mhe] #available measurement for each time window
function loss(p)
sol = simulate(p)
loss = abs2.( (sol .- ymeas) ./ std.(eachrow(ymeas)))
return sum(loss)
end
adtype = Optimization.AutoForwardDiff()
optf = Optimization.OptimizationFunction((x, p) -> loss(x), adtype)
optprob = Optimization.OptimizationProblem(optf, p0) # Initial guess for parameter estimation
optires = Optimization.solve(optprob, PolyOpt(), maxiters = 5000)
I obtain a Instability detected. Aborting warning, after which a ERROR: DimensionMismatch: arrays could not be broadcast to a common size; got a dimension with lengths 5 and 21 appears.
I guess there is a mismatch somewhere, but after having checked, I cannot find the actual error. Both sol and ymeas variables in the cost function are 6x21 matrices, while std.(eachrow(ymeas)) it’s a 6x1 column vector.
2) I want to include (together with the parameters) as optimization variables the initial condition of the set of the equation. Do you know if there are any example on this topic? I cannot find anythig unfortunately (or maybe i have not searched well enough ) .
Thanks in advance for the help !!