2
votes

I'm new to GEKKO and so my question could be stupid. I want to estimate some parameters of my model, it's a SIR model. I've read many times the documentation and watch many videos of professor John Hedengren but GEKKO it's still hard to understand for me. This is my code:

from gekko import GEKKO
tab_data = [275.5,317,457.34,646,888.67,1236.67,1619.34,2077.34]
total_active_data=[59999725.,59999684.33333334,59999558.66666666,\
                   59999385.33333334,59999158.33333333,59998823.,\
                   59998474.66666666,59998053.33333333]
population = 60e6
m = GEKKO()
v = m.MV(0.97,0,9.7)
v.STATUS = 1
v.FSTATUS = 0
tau = m.MV(0.066,0.0594,0.099)
tau.STATUS=0
tau.FSTATUS = 0
I0 = m.Var(100)
S0 = m.Var(population-I0.value-275)
R0 = m.CV(value=tab_data)
R0.FSTATUS=1
m.time = [i for i in range(len(tab_data))]
m.Equation(S0.dt() == -v*S0*I0/total_active_data)
m.Equation(I0.dt() == v*S0*I0/total_active_data - 0.07*I0-tau*I0)
m.Equation(R0.dt() == tau*I0)
m.options.IMODE = 5  # MHE
m.options.EV_TYPE = 2  # Objective type
m.options.NODES = 3  # Collocation nodes
m.options.SOLVER = 3  # IPOPT
m.solve()

If I run it, there is the following error

Equation without an equality (=) or inequality (>,<)

I think that I have set all the parameters and the variables in the right way (I want to allow that v and tau could change in time and R0 is the one on which I compute my objective function) but maybe I'm wrong.

1

1 Answers

0
votes

You need to define a new Gekko parameter to insert the parameter values as a vector in the equation.

tad = m.Param(total_active_data)
m.Equation(S0.dt() == -v*S0*I0/tad)
m.Equation(I0.dt() == v*S0*I0/tad - 0.07*I0-tau*I0)

The modified script now runs successfully.

from gekko import GEKKO
tab_data = [275.5,317,457.34,646,888.67,1236.67,1619.34,2077.34]
total_active_data=[59999725.0,59999684.33333334,\
                   59999558.66666666,59999385.33333334,\
                   59999158.33333333,59998823.0,\
                   59998474.66666666,59998053.33333333]
population = 60e6
m = GEKKO(remote=False)
v = m.MV(0.97,0,9.7)
v.STATUS = 1
v.FSTATUS = 0
tau = m.MV(0.066,0.0594,0.099)
tau.STATUS=0
tau.FSTATUS = 0
I0 = m.Var(100)
S0 = m.Var(population-I0.value-275)
R0 = m.CV(value=tab_data)
R0.FSTATUS=1
m.time = [i for i in range(len(tab_data))]
tad = m.Param(total_active_data)
m.Equation(S0.dt() == -v*S0*I0/tad)
m.Equation(I0.dt() == v*S0*I0/tad - 0.07*I0-tau*I0)
m.Equation(R0.dt() == tau*I0)
m.options.IMODE = 5  # MHE
m.options.EV_TYPE = 2  # Objective type
m.options.NODES = 3  # Collocation nodes
m.options.SOLVER = 3  # IPOPT
m.solve()

Here is the solver output.

Number of Iterations....: 48

                                   (scaled)                 (unscaled)
Objective...............:  4.8513730486940313e+005   4.8513730486940313e+005
Dual infeasibility......:  8.9731011182818626e-008   8.9731011182818626e-008
Constraint violation....:  6.2281364666837996e-009   9.2077243607491255e-009
Complementarity.........:  3.0323778515541553e-007   3.0323778515541553e-007
Overall NLP error.......:  1.9345602538908201e-008   3.0323778515541553e-007


Number of objective function evaluations             = 53
Number of objective gradient evaluations             = 49
Number of equality constraint evaluations            = 53
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 49
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 48
Total CPU secs in IPOPT (w/o function evaluations)   =      0.174
Total CPU secs in NLP function evaluations           =      0.052

EXIT: Optimal Solution Found.

 The solution was found.

 The final value of the objective function is  485137.30486940313
 
 ---------------------------------------------------
 Solver         :  IPOPT (v3.12)
 Solution time  :  0.2999 sec
 Objective      :  485137.30486940313
 Successful solution
 ---------------------------------------------------