不同iating在Java中的SEIR模型。

huangapple go评论76阅读模式
英文:

differentiating the SEIR model in Java

问题

我正试图制作一个 SEIR 传染病模型的模拟。
它包括四个部分:

  • 易感者(未感染者)
  • 潜伏期(已感染但尚未具有传染性)
  • 传染期(已感染且具有传染性)
  • 移除者(康复者/死亡者)

其中,γ 为感染率,β 为康复/死亡率。

我之前使用过 SIR 模型,这是一个更基础的模型,其中结合了 E 和 I,它使用以下方程:

(方程见原文)

从另一个帖子中,我使用了一个解决方案来模拟 SIR,使用了以下代码:

double dS = (beta * S.get(day) * I.get(day) / N);
double newS = (S.get(day) - dS);
double newI = (I.get(day) + dS - gamma * I.get(day));
double newR = (R.get(day) + gamma * I.get(day));

这在使用 Euler 方法时效果很好。然而,我尝试过对其进行修改,以适应 SEIR 模型(该模型具有以下方程:)

(方程见原文)

其中,u 是死亡率,δ 是出生率,a 是潜伏期。我尝试过类似的方法来适用于 SEIR 模型,但是我无法很好地模拟它。问题不仅仅出现在变量上,而是整体上区分这些复杂的方程。想知道是否有人能提供帮助,谢谢。

英文:

I'm attempting to make a simulation of the SEIR epidemic model.
It contains four parts:

  • Susceptibles (non-infected)
  • Exposed (infected but not infectious yet)
  • Infectious (infected and infectious)
  • Removed (recovered/dead)

where gamma γ is the infection rate and beta β is the reovery/death rate.

I've previously used the SIR model, a more basic model where E and I are combined, which uses these equations:

不同iating在Java中的SEIR模型。

From another thread I've used a solution to simulate SIR using this code:

double dS = (beta * S.get(day) * I.get(day) / N);
double newS = (S.get(day) - dS);
double newI = (I.get(day) + dS - gamma * I.get(day));
double newR = (R.get(day) + gamma * I.get(day));

This works fine using the Euler's method. However, I've tried to manipulate this to try and fit the SEIR model (which has these equations:)

不同iating在Java中的SEIR模型。

where u is the death rate, delta is the birth rate and a is the incubation period. I've made an attempt to try and use a similar method to work for SEIR but I'm unsuccessful to simulate it well at all. This isn't really a problem with the variables but as a whole differentiating these complex equations. Wondering if anyone could help, thanks.

答案1

得分: 1

真的应该更早意识到这一点,但是通过随意更改符号,发现除了 'newS' 之外的所有部分都需要获取前一天的数字并将新的 dS 相加,而不是相减。我的 SIR 代码已经实现了这一点。不太清楚我是怎么忽略了这一点。。

新的工作代码:

    int totalDays = 160; // 循环的天数/次数
    int N = 1000; // 人口数量
    int I0 = 1; // 起始感染者/暴露者
    double beta = 0.2; // 感染率
    double gamma = 1.0/10.0; // 恢复时间(每天的倒数)
    double a = 1.0/2.0; // 潜伏期(每天的倒数)
    List<Double> S = new ArrayList<>();
    List<Double> E = new ArrayList<>();
    List<Double> I = new ArrayList<>();
    List<Double> R = new ArrayList<>();

    private void createData() {
        final int R0 = 0;
        final int S0 = N - E0 - R0;

        S.add((double) S0);
        E.add((double) I0);
        I.add(0.0);
        R.add(0.0);

        for (int day = 1; day < totalDays + 1; day++) {
            double[] derivative = deriv(day);
            S.add(derivative[0]);
            E.add(derivative[1]);
            I.add(derivative[2]);
            R.add(derivative[3]);
        }
    }

    private double[] deriv(int day) {
        day = day - 1;

        double dS = (beta * S.get(day) * I.get(day)) / N;
        double newS = S.get(day) - (dS);
        double newE = E.get(day) + (dS - (a * E.get(day)));
        double newI = I.get(day) + ((a * E.get(day)) - (gamma * I.get(day)));
        double newR = R.get(day) + (gamma * I.get(day));
        return new double[] {newS, newE, newI, newR};
    }
英文:

Really should've realised this earlier but from messing around with random sign changes, worked out that everything apart from 'newS' requires getting the previous day's number and plussing the new dS, rather than minusing it. My SIR code already did this. Don't really know how I missed this..

New working code:

int totalDays = 160; // How many days/times to loop
int N = 1000; // Population
int I0 = 1; // Starting infected/exposed
double beta = 0.2; // Infection rate
double gamma = 1.0/10.0; // recovery time (days to the -1)
double a = 1.0/2.0; // incubation period (days to the -1)
List&lt;Double&gt; S = new ArrayList&lt;&gt;();
List&lt;Double&gt; E = new ArrayList&lt;&gt;();
List&lt;Double&gt; I = new ArrayList&lt;&gt;();
List&lt;Double&gt; R = new ArrayList&lt;&gt;();
private void createData() {
final int R0 = 0;
final int S0 = N - E0 - R0;
S.add((double) S0);
E.add((double) I0);
I.add(0.0);
R.add(0.0);
for (int day = 1; day &lt; totalDays + 1; day++) {
double[] derivative = deriv(day);
S.add(derivative[0]);
E.add(derivative[1]);
I.add(derivative[2]);
R.add(derivative[3]);
}
}
private double[] deriv(int day) {
day = day - 1;
double dS = (beta * S.get(day) * I.get(day)) / N;
double newS = S.get(day) - (dS);
double newE = E.get(day) + (dS - (a * E.get(day)));
double newI = I.get(day) + ((a * E.get(day)) - (gamma * I.get(day)));
double newR = R.get(day) + (gamma * I.get(day));
return new double[] {newS, newE, newI, newR};
}

huangapple
  • 本文由 发表于 2020年9月25日 18:47:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/64062614.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定