Hi, I am trying to find multiple parameters for the optimized system which is governed by a system of equations.
In my code, I need to be able to use 4 or 5 equations and determine the parameters for the optimized system. I have simplified the code to a system of 3 equations for simplicity, (but it is 5 equations), as below:
using Optimization, ForwardDiff, OptimizationOptimJL, OptimizationBBO
function f1(du, u, p, t)
x, y = u
α, β, δ, γ = p
du[1] = dx = α * x - β * x * y
du[2] = dy = -δ * y + γ *x * y
du[3] = dz = α*x
end
u0 = [1.0; 1.0; 1.0]
tspan = (0.0, 10.0)
p = [1.5, 1.0, 3.0, 1.0]
prob = ODEProblem(f1, u0, tspan, p)
t = collect(range(0, stop = 10, length = 200)) # Creates the time vector
data = Array(solve(prob, Tsit5(), saveat = t, abstol = 1e-12, reltol = 1e-12))
bound = Tuple{Float64, Float64}[(0, 10), (0, 10), (0, 10), (0, 10),
(0, 10), (0, 10), (0, 10), (0, 10),
(0, 10), (0, 10), (0, 10), (0, 10),
(0, 10), (0, 10), (0, 10), (0, 10), (0, 10), (0, 10)]
obj = multiple_shooting_objective(prob, Tsit5(), L2Loss(t, data),Optimization.AutoForwardDiff(); discontinuity_weight = 1.0, abstol = 1e-12, reltol = 1e-12)
optprob = Optimization.OptimizationProblem(obj, zeros(18), lb = first.(bound), ub = last.(bound))
optsol = solve(optprob, BBO_adaptive_de_rand_1_bin_radiuslimited(), maxiters = 10000)
Optimised_parameters = optsol.u[(end - 1):end]
println("Optimised parameters: ")
println("p₁: ", Optimised_parameters[1])
println("p₂: ", Optimised_parameters[2])
println(" ")
However, I am getting the error message:
ERROR: InexactError: Int64(4.666666666666667)
Stacktrace:
[1] Int64
@ .\float.jl:994 [inlined]
[2] (::DiffEqParamEstim.var"#43#48"{…})(p::Vector{…}, ::SciMLBase.NullParameters)
@ DiffEqParamEstim C:\Users\Finn Mezzetti\.julia\packages\DiffEqParamEstim\6z5Ou\src\multiple_shooting_objective.jl:33
[3] (::OptimizationFunction{…})(::Vector{…}, ::Vararg{…})
@ SciMLBase C:\Users\Finn Mezzetti\.julia\packages\SciMLBase\VAClc\src\scimlfunctions.jl:3944
[4] (::OptimizationBBO.var"#20#22"{OptimizationCache{…}})(θ::Vector{Float64})
@ OptimizationBBO C:\Users\Finn Mezzetti\.julia\packages\OptimizationBBO\UYBCT\src\OptimizationBBO.jl:146
[5] fitness(x::Vector{…}, p::BlackBoxOptim.FunctionBasedProblem{…})
@ BlackBoxOptim C:\Users\Finn Mezzetti\.julia\packages\BlackBoxOptim\lZtsr\src\problem.jl:61
[6] setup_problem(func::Function, parameters::BlackBoxOptim.ParamsDictChain)
@ BlackBoxOptim C:\Users\Finn Mezzetti\.julia\packages\BlackBoxOptim\lZtsr\src\bboptimize.jl:37
[7] bbsetup(functionOrProblem::Function, parameters::Dict{…}; kwargs::@Kwargs{…})
@ BlackBoxOptim C:\Users\Finn Mezzetti\.julia\packages\BlackBoxOptim\lZtsr\src\bboptimize.jl:111
[8] bbsetup
@ C:\Users\Finn Mezzetti\.julia\packages\BlackBoxOptim\lZtsr\src\bboptimize.jl:109 [inlined]
[9] __solve(cache::OptimizationCache{…})
@ OptimizationBBO C:\Users\Finn Mezzetti\.julia\packages\OptimizationBBO\UYBCT\src\OptimizationBBO.jl:158
[10] solve!(cache::OptimizationCache{…})
@ SciMLBase C:\Users\Finn Mezzetti\.julia\packages\SciMLBase\VAClc\src\solve.jl:186
[11] solve(::OptimizationProblem{…}, ::BBO_adaptive_de_rand_1_bin_radiuslimited; kwargs::@Kwargs{…})
@ SciMLBase C:\Users\Finn Mezzetti\.julia\packages\SciMLBase\VAClc\src\solve.jl:94
Which indicates that somewhere it is receiving an integer but expecting a Float. I am not sure how to fix this so I can extend the system to include more equations.
Any help would be much appreciated!