TL;DR; We just released v1.0 of
cayenne
, our Python package for stochastic simulations! Read on to find out if you should model your system as a stochastic process, and why you should try outcayenne
.TL; DR; 我們剛剛發布了
cayenne
v1.0 ,這是我們用于隨機模擬的Python包! 請繼續閱讀以了解是否應該將系統建模為隨機過程,以及為什么要嘗試使用cayenne
。
Mathematical models breathe structure into our understanding of the world. Oftentimes, they are cast as ordinary differential equations that describe how things change with time. In most cases, the insight from such models is sufficient for the question at hand. However, if you are trying to model the number of people who are going to be infected by SARS-CoV-2, a differential equation may not be the right tool for at least a couple of reasons:
數學模型為我們對世界的理解注入了結構。 通常,它們被轉換為描述事物如何隨時間變化的常微分方程。 在大多數情況下,來自此類模型的見解足以解決當前的問題。 但是,如果您要對將要感染SARS-CoV-2的人數進行建模,則至少有兩個原因,微分方程可能不是正確的工具:
- Variables in differential equations are continuous and take values like 0.3, 2.7, etc. This isn’t ideal if you are talking about the number of people, which can only be integers like 1 or 2. 微分方程中的變量是連續的,且取值為0.3、2.7等。如果您要談論人數,那只能是1或2之類的整數,這并不理想。
- A differential equation always predicts the same output for a given input. However, not everyone who comes in contact with a COVID-19 infected person will develop the disease — the event is actually probabilistic, or stochastic. 對于給定的輸入,微分方程總是預測相同的輸出。 但是,并非每個與COVID-19感染者接觸的人都會患上這種疾病-該事件實際上是概率性的或隨機的。
Let’s look at this with a concrete example. Infection and recovery from SARS-CoV-2 can be modeled with Susceptible-Infectious-Recovered (SIR) model. In this model, when an infectious person comes in contact with a susceptible person, the susceptible person gets infected and can now infect others. Eventually, the infected person recovers and cannot spread the disease anymore. These are represented by the equation below:
讓我們看一個具體的例子。 SARS-CoV-2的感染和恢復可以用易感感染恢復(SIR)模型進行建模。 在此模型中,當感染者與易感者接觸時,易感者會被感染,并且現在可以感染他人。 最終,感染者康復并且無法再傳播疾病。 這些由以下等式表示:

Giving some numbers for the parameters “k1” and “k2”, we can simulate the model as an ordinary differential equation in Python like this
給參數“ k1”和“ k2”一些數字,我們可以像使用Python這樣將模型模擬為一個常微分方程。
If you plot the result of the simulation, it will look like this:
如果繪制模擬結果,它將看起來像這樣:

You can see that i) the number of people is being represented by fractional values & ii) there is no notion of “probability” in the plot, it is just a smooth curve vs. time.
您可以看到,i)用分數值表示人數; ii)在圖中沒有“概率”的概念,它只是一條隨時間變化的平滑曲線。
To address these limitations of differential equations, we use the more elegant built-for-purpose mathematical construct called a Markov jump process. Such a process is well suited for something like modeling the number of people. When the number of infected people increases from 5 to 6, there are instantaneous “jumps” between the integer values, instead of the gradual change (e.g. 5.1, 5.2, …, 6) seen in differential equations. Below we see the same SIR model from above, but simulated as a Markov jump process.
為了解決微分方程的這些局限性,我們使用了更為優雅的針對用途的內置數學構造,稱為馬爾可夫跳躍過程。 這樣的過程非常適合于模擬人數。 當被感染人數從5增加到6時,整數值之間會出現瞬時“跳躍”,而不是微分方程式中出現的逐漸變化(例如5.1、5.2,…,6)。 在下面,我們從上方看到了相同的SIR模型,但以Markov跳躍過程進行了仿真。

The number of people in this Markov process jumps between integer values at random time-points, at a frequency determined the rate constants k1 and k2. The simulation stops when the number of infected individuals is zero, around time= 70 days. Repeating this simulation with a different random number seed gives a different simulation trajectory, but with the same general trend:
該馬爾可夫過程中的人數在隨機時間點的整數值之間跳躍,其頻率確定為速率常數k1和k2。 當感染個體的數量為零時(大約70天左右),模擬停止。 使用不同的隨機數種子重復此模擬將給出不同的模擬軌跡,但具有相同的總體趨勢:

Here we see that the infection ends quickly (t=25) as the number of infected individuals becomes zero sooner. Since each simulation trajectory is probabilistic, we generally run a large number of them to get an overall picture of the process.
在這里,我們看到感染很快結束(t = 25),因為被感染的人數很快變為零。 由于每個仿真軌跡都是概率性的,因此我們通常會運行大量仿真軌跡以獲取整個過程的概況。
For simulating these Markov jump processes (also known as continuous-time Markov chains), we have developed an accurate, easy-to-use Python package called cayenne
. You should be able to install it easily from here. And below is the minimal code for simulating the SIR model 10 times and plotting the simulation trajectories.
為了模擬這些Markov跳躍過程(也稱為連續時間Markov鏈),我們開發了一個準確,易于使用的Python軟件包,稱為cayenne
。 您應該可以從這里輕松安裝它。 下面是用于模擬SIR模型10次并繪制模擬軌跡的最小代碼。

If you are someone who runs stochastic simulations, we think you will enjoy trying out our package (get it here, examples here and a tutorial here) if you care about:
如果您是運行隨機模擬的人,那么如果您關心以下方面,我們認為您會喜歡嘗試一下我們的軟件包的( 在此處獲取示例, 在 此處提供示例,并在此處獲得教程)。
Accuracy: We tested all our algorithms for accuracy using the stochastic SBML test suite. Other packages that we tested were not as accurate as ours, as we find in our benchmarks.
準確性 :我們使用隨機SBML測試套件測試了所有算法的準確性。 正如我們在基準測試中發現的那樣,我們測試的其他軟件包的準確性不如我們的軟件包。
Fast code: Our backend is written in Cython for a nice balance between speed and ease of writing new algorithms. And different repetitions of the algorithm can be run across multiple CPU cores out of the box.
快速代碼 :我們的后端使用Cython編寫,可以在速度和編寫新算法的便利性之間取得很好的平衡。 而且該算法的不同重復可以在多個CPU核心中運行。
Quick prototyping: We leverage the cool antimony library to provide an easy and intuitive model writing interface. There is no need to write out the stoichiometric matrices.
快速原型制作 :我們利用出色的銻庫提供簡單直觀的模型編寫界面。 無需寫出化學計量矩陣。
The little things: Stochastic simulations usually mean outputs logged at stochastic time points (e.g. at t = 19.3, 19.7). But with
cayenne
, you can get an accurately interpolated value at the time points of your choice (e.g. at t = 19.5).小事情 :隨機模擬通常意味著在隨機時間點記錄的輸出(例如,在t = 19.3,19.7時)。 但是,使用
cayenne
,您可以在選擇的時間點獲得準確的插值(例如,t = 19.5)。
We’d love for you to check out our package and let us know what you think! Currently, we are writing up a manuscript.
我們希望您能檢查我們的包裹,并告訴我們您的想法! 目前,我們正在編寫手稿。
翻譯自: https://medium.com/heuro-labs/cayenne-a-python-package-for-stochastic-simulations-3807dc4398f5
本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。 如若轉載,請注明出處:http://www.pswp.cn/news/388771.shtml 繁體地址,請注明出處:http://hk.pswp.cn/news/388771.shtml 英文地址,請注明出處:http://en.pswp.cn/news/388771.shtml
如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!