You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于智能体模拟感染数据的SIR-ODE模型拟合问题求助

SIR模型拟合智能体模拟感染数据的问题

我使用Python的scipy.optimize工具,将易感-感染-恢复(SIR)常微分方程(ODE)模型拟合至感染数据,但发现拟合出的感染曲线存在感染上升延迟、峰值高度被高估的问题(橙色曲线)。该数据来自具有同质混合特性、包含S、I、R三状态的智能体模拟,理论上应完全符合SIR模型的假设,模型本应能完美拟合。目前不确定是拟合方法需要改进,还是该智能体模拟生成的曲线形状无法用简单ODE模型复现。

以下是相关数据及尝试代码:

import numpy as np
import matplotlib.pyplot as plt
from scipy import integrate, optimize

inf_data = [0.005,0.007,0.009,0.012,0.015,0.019,0.024,0.03,0.036,0.044,0.053,0.063,0.074,0.086,0.098,0.112,0.126,0.141,0.157,0.172,0.188,0.203,0.218,0.232,0.247,0.259,0.272,0.282,0.292,0.302,0.308,0.315,0.318,0.321,0.322,0.321,0.319,0.317,0.312,0.307,0.301,0.294,0.286,0.279,0.27,0.262,0.253,0.244,0.236,0.226,0.217,0.207,0.197,0.188,0.18,0.171,0.163,0.155,0.147,0.14,0.132,0.125,0.119,0.112,0.106,0.1,0.095,0.089,0.085,0.08,0.076,0.071,0.067,0.064,0.06,0.056,0.053,0.05,0.047,0.044,0.041,0.039,0.037,0.034,0.032,0.03,0.028,0.026,0.025,0.023,0.022,0.021,0.019,0.018,0.017,0.016,0.015,0.014,0.013,0.012,0.011] #percentage of infected
time_points = np.arange(len(inf_data))

def sir_model(y, x, beta, gamma):
    S, I, R = y
    dS = -beta * S * I / N
    dI = beta * S * I / N - gamma * I
    dR = gamma * I
    return dS, dI, dR

def fit_odeint(time_points, beta, gamma):
    return integrate.odeint(sir_model, (S0, I0, R0), time_points, args=(beta, gamma))[:,1]

# Initial values
N = 1.0
I0 = inf_data[0]
S0 = N - I0
R0 = 0.0

popt, pcov = optimize.curve_fit(fit_odeint, time_points, inf_data)
fitted = fit_odeint(time_points, *popt)

plt.plot(time_points, inf_data, 'o')
plt.plot(time_points, fitted)
plt.show()

蓝色点:观测数据;橙色线:拟合模型

内容的提问来源于stack exchange,提问作者ratsrule23

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 03:10:32