# Estimate parameters of a Delay Differential Equation

**URL:** <https://discourse.julialang.org/t/estimate-parameters-of-a-delay-differential-equation/25159>\
**Category:** Optimization (Mathematical)\
**Tags:** diffeq\
**Created:** [June 11, 2019, 5:17pm UTC](https://discourse.julialang.org/t/estimate-parameters-of-a-delay-differential-equation/25159 "2019-06-11T17:17:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Farnazmdi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/farnazmdi/32/24072_2.png) [@Farnazmdi](https://discourse.julialang.org/u/Farnazmdi)\
**Post date:** [June 11, 2019, 5:17pm UTC](https://discourse.julialang.org/t/estimate-parameters-of-a-delay-differential-equation/25159/1 "2019-06-11T17:17:11Z")

</div>

Hi!  
I am new to Julia and I’m trying to fit my data to a DDE, but have a problem with `optimize()`. It is not recognized, here is my code, and the error.  
I would appreciate if anyone could provide a toy example for how to estimate parameters of a DDE.

Thank you!

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/f/af928eaa91128d9e03e4c684d8ae0ab2281a2cce.png)

############### The error ####################

Inappropriate solve command. The arguments do not make sense. Likely, you gave an algorithm which does not actually exist (or does not \<:DiffEqBase.DEAlgorithm)

Stacktrace:  
[1] error(::String) at .\error.jl:33  
[2] #\_\_solve#1(::Bool, ::Base.Iterators.Pairs{Symbol,Int64,Tuple{Symbol},NamedTuple{(:maxiters,),Tuple{Int64}}}, ::Function, ::DDEProblem{Array{Float64,1},Tuple{Float64,Float64},Array{Float64,1},Array{Any,1},true,Array{Float64,1},DDEFunction{true,typeof(pg2),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},typeof(h),Nothing}, ::LinRange{Float64}) at C:\Users\farna.julia\packages\DifferentialEquations\SubON\src\default\_solve.jl:3  
[3] (::getfield(DiffEqBase, Symbol(“#kw##\_\_solve”)))(::NamedTuple{(:maxiters,),Tuple{Int64}}, ::typeof(DiffEqBase.\_\_solve), ::DDEProblem{Array{Float64,1},Tuple{Float64,Float64},Array{Float64,1},Array{Any,1},true,Array{Float64,1},DDEFunction{true,typeof(pg2),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},typeof(h),Nothing}, ::LinRange{Float64}) at .\none:0  
[4] #solve#456(::Base.Iterators.Pairs{Symbol,Int64,Tuple{Symbol},NamedTuple{(:maxiters,),Tuple{Int64}}}, ::Function, ::DDEProblem{Array{Float64,1},Tuple{Float64,Float64},Array{Float64,1},Array{Any,1},true,Array{Float64,1},DDEFunction{true,typeof(pg2),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},typeof(h),Nothing}, ::LinRange{Float64}) at C:\Users\farna.julia\packages\DiffEqBase\6ewdP\src\solve.jl:41  
[5] (::getfield(DiffEqBase, Symbol(“#kw##solve”)))(::NamedTuple{(:maxiters,),Tuple{Int64}}, ::typeof(solve), ::DDEProblem{Array{Float64,1},Tuple{Float64,Float64},Array{Float64,1},Array{Any,1},true,Array{Float64,1},DDEFunction{true,typeof(pg2),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},typeof(h),Nothing}, ::LinRange{Float64}) at .\none:0  
[6] (::getfield(DiffEqParamEstim, Symbol(“##29#34”)){Nothing,Bool,Int64,typeof(DiffEqParamEstim.STANDARD\_PROB\_GENERATOR),Base.Iterators.Pairs{Symbol,Int64,Tuple{Symbol},NamedTuple{(:maxiters,),Tuple{Int64}}},DDEProblem{Array{Float64,1},Tuple{Float64,Float64},Array{Float64,1},Array{Any,1},true,Nothing,DDEFunction{true,typeof(pg2),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},typeof(h),Nothing},LinRange{Float64},DataFrames.DataFrame,Tsit5})(::Array{Float64,1}) at C:\Users\farna.julia\packages\DiffEqParamEstim\mNjO8\src\build\_loss\_objective.jl:42  
[7] (::DiffEqObjective{getfield(DiffEqParamEstim, Symbol(“##29#34”)){Nothing,Bool,Int64,typeof(DiffEqParamEstim.STANDARD\_PROB\_GENERATOR),Base.Iterators.Pairs{Symbol,Int64,Tuple{Symbol},NamedTuple{(:maxiters,),Tuple{Int64}}},DDEProblem{Array{Float64,1},Tuple{Float64,Float64},Array{Float64,1},Array{Any,1},true,Nothing,DDEFunction{true,typeof(pg2),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},typeof(h),Nothing},LinRange{Float64},DataFrames.DataFrame,Tsit5},getfield(DiffEqParamEstim, Symbol(“##33#39”))})(::Array{Float64,1}) at C:\Users\farna.julia\packages\DiffEqParamEstim\mNjO8\src\build\_loss\_objective.jl:24  
[8] #optimize#8(::Symbol, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::DiffEqObjective{getfield(DiffEqParamEstim, Symbol(“##29#34”)){Nothing,Bool,Int64,typeof(DiffEqParamEstim.STANDARD\_PROB\_GENERATOR),Base.Iterators.Pairs{Symbol,Int64,Tuple{Symbol},NamedTuple{(:maxiters,),Tuple{Int64}}},DDEProblem{Array{Float64,1},Tuple{Float64,Float64},Array{Float64,1},Array{Any,1},true,Nothing,DDEFunction{true,typeof(pg2),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},typeof(h),Nothing},LinRange{Float64},DataFrames.DataFrame,Tsit5},getfield(DiffEqParamEstim, Symbol(“##33#39”))}, ::Array{Float64,1}, ::Dogleg{LeastSquaresOptim.QR}) at C:\Users\farna.julia\packages\LeastSquaresOptim\Wvhro\src\types.jl:141  
[9] optimize(::Function, ::Array{Float64,1}, ::Dogleg{LeastSquaresOptim.QR}) at C:\Users\farna.julia\packages\LeastSquaresOptim\Wvhro\src\types.jl:141  
[10] top-level scope at In[15]:30

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 11, 2019, 6:58pm UTC](https://discourse.julialang.org/t/estimate-parameters-of-a-delay-differential-equation/25159/2 "2019-06-11T18:58:02Z")

</div>

You gave an ODE solver method to a DDEProblem. You need to give a method for DDEs to solve a DDEProblem. For example, `MethodOfSteps(Tsit5())`.

---

<div class="post-metadata">

**Author:** ![Farnazmdi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/farnazmdi/32/24072_2.png) [@Farnazmdi](https://discourse.julialang.org/u/Farnazmdi)\
**Post date:** [June 11, 2019, 8:31pm UTC](https://discourse.julialang.org/t/estimate-parameters-of-a-delay-differential-equation/25159/3 "2019-06-11T20:31:25Z")

</div>

Thank you for your reply,  
Could you please elaborate on how to use it?  
like `sol = solve(prob, Tsit5())` and I have to pass the solution to the `MethodOfSteps`? What package has to be installed for `MethodOfSteps`? I searched and read the documentation page of it, but I still couldn’t find.

Thank you,

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 11, 2019, 11:05pm UTC](https://discourse.julialang.org/t/estimate-parameters-of-a-delay-differential-equation/25159/4 "2019-06-11T23:05:08Z")

</div>

`sol = solve(prob, MethodOfSteps(Tsit5()))`. See [http://docs.juliadiffeq.org/latest/tutorials/dde\_example.html](http://docs.juliadiffeq.org/latest/tutorials/dde_example.html)

---

<div class="post-metadata">

**Author:** ![Farnazmdi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/farnazmdi/32/24072_2.png) [@Farnazmdi](https://discourse.julialang.org/u/Farnazmdi)\
**Post date:** [June 12, 2019, 4:56am UTC](https://discourse.julialang.org/t/estimate-parameters-of-a-delay-differential-equation/25159/5 "2019-06-12T04:56:45Z")

</div>

Thank you

---

<div class="post-metadata">

**Author:** ![Farnazmdi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/farnazmdi/32/24072_2.png) [@Farnazmdi](https://discourse.julialang.org/u/Farnazmdi)\
**Post date:** [June 24, 2019, 3:58am UTC](https://discourse.julialang.org/t/estimate-parameters-of-a-delay-differential-equation/25159/6 "2019-06-24T03:58:28Z")

</div>

Hello,  
I am trying to estimate parameters of a DDE, when I call optimize(), 90/100 times it throws this error:

```julia
Constant lags and time direction do not match. Exiting.

```

I am also estimating constant delays here. Changed initial guesses many times, just works sometimes and I haven’t figured out what the problem is, or what the time direction means. Could anyone help me with this?  
Thanks,

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 24, 2019, 4:53am UTC](https://discourse.julialang.org/t/estimate-parameters-of-a-delay-differential-equation/25159/7 "2019-06-24T04:53:54Z")

</div>

If you’re estimating the delay `h(t-tau)`, and tau goes negative, then this can be thrown. So you’d need to make sure that the optimizer keeps values positive that you expect to be positive.
