问题描述
我正在将一些代码从Python转换为R,并且发现很难在每个代码中找到相应的函数。在这种情况下,我遇到的代码是:
x_sol_best = solve_ivp(
fun=model_covid,y0=x_0_cases,t_span=[t_predictions[0],t_predictions[-1]],t_eval=t_predictions,args=tuple(optimal_params),).y
从scipy.integrate.solve_ivp
documentation中,我看到此函数中使用的默认集成方法为:'RK45'(默认):阶显式Runge-Kutta方法5(4)
R中的哪些包/功能与此等效?
从R中ode
函数的R documentation中,我看到有许多可用的RK 4(5)方法(如下所示)-但Python文档指出RK45是5(4)...
任何人都可以提供澄清吗? TIA
"rk45ck" | Runge-Kutta Cash-Karp,order 4(5)
"rk45f" | Runge-Kutta-Fehlberg,order 4(5); Octave: ode45,pair=1
"rk45e" | Runge-Kutta-England,order 4(5)
"rk45dp6" | Dormand-Prince,order 4(5),local order 6
"rk45dp7","ode45" | Dormand-Prince 4(5),local order 7
解决方法
根据文档,solve_ivp()
中的默认求解器为Dormand-Prince。这在ode45
包的ode()
函数中称为deSolve
。
x_sol_best = deSolve::ode(
y = x_0_cases,times = t_predictions,func = model_covid,parms = c(...),# vector of parameter values
method = "ode45"
)[,-1] # drop the t column