简体   繁体   English

使用 GEKKO 进行动态参数估计

[英]Dynamic parameters estimation with GEKKO

I'm new to GEKKO and so my question could be stupid.我是 GEKKO 的新手,所以我的问题可能很愚蠢。 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.我想估计我的model的一些参数,它是SIR model。我已经阅读了很多次文档并观看了John Hedengren教授的许多视频但是GEKKO对我来说仍然很难理解。 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.我认为我已经以正确的方式设置了所有参数和变量(我想让 v 和 tau 可以及时改变,而 R0 是我计算目标函数的那个)但也许我错了。

You need to define a new Gekko parameter to insert the parameter values as a vector in the equation.您需要定义一个新的 Gekko 参数以将参数值作为向量插入方程中。

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.这是求解器 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
 ---------------------------------------------------

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM