简体   繁体   English

MATLAB-SIR流行病模型的优化

[英]MATLAB - Optimization of SIR epidemic model

I'm trying to model a flu epidemic using the SIR model: http://en.wikipedia.org/wiki/Epidemic_model#The_SIR_Model . 我正在尝试使用SIR模型对流感流行进行建模: http : //en.wikipedia.org/wiki/Epidemic_model#The_SIR_Model

It basically requires me to solve 3 differential equations simultaneously. 基本上,我需要同时求解3个微分方程。

My task is to fit a graph to a set of data and I was just wondering how I should go about doing this. 我的任务是使图形适合一组数据,而我只是想知道我应该如何去做。

I've managed to setup a system to solve the ODEs like this: 我设法建立了一个解决ODE的系统,如下所示:

function dydt = sir_ode(t,y,p)
B = p(1);
r = p(2);
S = y(1);
I = y(2);
R = y(3);
dydt = [-B*I*S; B*I*S - r*I; r*I];

and the m file to call it: 和m文件来调用它:

time = 1:24;
y0 = [400 1 0];
tspan = time;
p0 = [.01 .5];
[t,y] = ode45(@sir_ode,tspan,y0,[],p0);

so I have a tspan, I have a y0 matrix for S, I and R. For my function, the output contains 3 of the differential equations so I can solve them together with the ode45 function. 所以我有一个tspan,我有一个S,I和R的y0矩阵。对于我的函数,输出包含3个微分方程,因此我可以将它们与ode45函数一起求解。

Now all I need to do now is find the appropriate p0 matrix so I can fit the curves to my data. 现在,我需要做的就是找到合适的p0矩阵,以便可以将曲线拟合到数据中。

Firstly, can anyone see any flaws in my solving method and secondly, who would have any suggestions on how I would go about finding the best p0 matrix? 首先,谁能看到我的求解方法中的任何缺陷,其次,对于我将如何寻找最佳的p0矩阵有何建议?

Thanks!! 谢谢!!

The solving method seems correct to me. 解决方法对我来说似乎是正确的。

For the second part of your question, in every optimisation problem there is a function that you want to maximize or minimize (using various algorithms, more on that later). 对于问题的第二部分,在每个优化问题中,都有一个您想要最大化或最小化的函数(使用各种算法,稍后再介绍)。 Here you could minimize an error function . 在这里,您可以最小化错误函数 One possible design for the error function is the L2 distance between your functions (or in your case the sum of the squared distances of the points between your original data curve and the curve given by your model at each timestep). 误差函数的一种可能设计是函数之间的L2距离(或者在每种情况下,原始数据曲线与模型给出的曲线之间的点的平方距离总和 )。 This should be fairly simple given the code you already have. 给定您已有的代码,这应该非常简单。

Now you have a function whose argument is p0 and output is the error you have. 现在,您有一个函数的参数为​​p0,输出为您遇到的错误。 The minimum is clearly 0, and the function is deterministic. 最小值显然为0,并且该函数是确定性的。 My guess is that it should be rather smooth but I have no proof of that. 我的猜测是应该相当顺利,但我没有任何证据。 Now to minimize it, there are a lot of ways (the simplest ones are the gradient descent and Newton's method). 现在将其最小化,有很多方法(最简单的方法是梯度下降和牛顿法)。 But the fminsearch function in Matlab should do the trick. 但是Matlab中的fminsearch函数应该可以解决问题。 Make sure to test several starting points, as you might find several local minimas. 确保测试几个起点,因为您可能会发现几个局部最小值。

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

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