日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

cayenne:用于随机模拟的Python包

發(fā)布時間:2023/11/29 python 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 cayenne:用于随机模拟的Python包 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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 out cayenne.

TL; DR; 我們剛剛發(fā)布了 cayenne v1.0 ,這是我們用于隨機模擬的Python包! 請繼續(xù)閱讀以了解是否應該將系統(tǒng)建模為隨機過程,以及為什么要嘗試使用 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:

數(shù)學模型為我們對世界的理解注入了結(jié)構(gòu)。 通常,它們被轉(zhuǎn)換為描述事物如何隨時間變化的常微分方程。 在大多數(shù)情況下,來自此類模型的見解足以解決當前的問題。 但是,如果您要對將要感染SARS-CoV-2的人數(shù)進行建模,則至少有兩個原因,微分方程可能不是正確的工具:

  • 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.

    微分方程中的變量是連續(xù)的,且取值為0.3、2.7等。如果您要談論人數(shù),那只能是1或2之類的整數(shù),這并不理想。
  • 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)模型進行建模。 在此模型中,當感染者與易感者接觸時,易感者會被感染,并且現(xiàn)在可以感染他人。 最終,感染者康復并且無法再傳播疾病。 這些由以下等式表示:

    The infection and recovery process感染和恢復過程

    Giving some numbers for the parameters “k1” and “k2”, we can simulate the model as an ordinary differential equation in Python like this

    給參數(shù)“ k1”和“ k2”一些數(shù)字,我們可以像使用Python這樣將模型模擬為一個常微分方程。

    If you plot the result of the simulation, it will look like this:

    如果繪制模擬結(jié)果,它將看起來像這樣:

    Simulating the SIR model with differential equations用微分方程模擬SIR模型

    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)用分數(shù)值表示人數(shù); 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.

    為了解決微分方程的這些局限性,我們使用了更為優(yōu)雅的針對用途的內(nèi)置數(shù)學構(gòu)造,稱為馬爾可夫跳躍過程。 這樣的過程非常適合于模擬人數(shù)。 當被感染人數(shù)從5增加到6時,整數(shù)值之間會出現(xiàn)瞬時“跳躍”,而不是微分方程式中出現(xiàn)的逐漸變化(例如5.1、5.2,…,6)。 在下面,我們從上方看到了相同的SIR模型,但以Markov跳躍過程進行了仿真。

    Simulating the SIR model with a Markov jump process用Markov跳躍過程模擬SIR模型

    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:

    該馬爾可夫過程中的人數(shù)在隨機時間點的整數(shù)值之間跳躍,其頻率確定為速率常數(shù)k1和k2。 當感染個體的數(shù)量為零時(大約70天左右),模擬停止。 使用不同的隨機數(shù)種子重復此模擬將給出不同的模擬軌跡,但具有相同的總體趨勢:

    Simulating a Markov jump process with a different seed用不同的種子模擬Markov跳躍過程

    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.

    在這里,我們看到感染很快結(jié)束(t = 25),因為被感染的人數(shù)很快變?yōu)榱恪?由于每個仿真軌跡都是概率性的,因此我們通常會運行大量仿真軌跡以獲取整個過程的概況。

    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跳躍過程(也稱為連續(xù)時間Markov鏈),我們開發(fā)了一個準確,易于使用的Python軟件包,稱為cayenne 。 您應該可以從這里輕松安裝它。 下面是用于模擬SIR模型10次并繪制模擬軌跡的最小代碼。

    Results of simulating the SIR model as a Markov jump process, 10 repetitions, on Cayenne在Cayenne上將SIR模型作為Markov跳躍過程進行10次重復模擬的結(jié)果

    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:

    如果您是運行隨機模擬的人,那么如果您關(guān)心以下方面,我們認為您會喜歡嘗試一下我們的軟件包的( 在此處獲取示例, 在 此處提供示例,并在此處獲得教程)。

  • 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測試套件測試了所有算法的準確性。 正如我們在基準測試中發(fā)現(xiàn)的那樣,我們測試的其他軟件包的準確性不如我們的軟件包。

  • 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

    總結(jié)

    以上是生活随笔為你收集整理的cayenne:用于随机模拟的Python包的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。