没有项目描述

stochastic-arrow的Python项目详细描述


箭头

“……即使前一毫秒比宇宙诞生时离我们更近,也同样遥不可及。” ―让·克里斯托夫·瓦尔塔,《明亮的混沌》

概念

这个库实现了Gillespie Algorithm的一个通用版本,一个随机的 离散系统的数值求解方法。每次迭代,算法 将计算给定速率和计数的每个反应的倾向性 在系统当前状态下的反应物中,选择一个 反应发生的时间间隔 当前的反应。迭代此操作将生成以下对象的轨迹(或history) 仿真过程中的状态向量。

安装

在您的requirements.txt中添加以下内容,或者 pip install stochastic-arrow

stochastic-arrow==0.1.4

用法

arrow库将单个类表示为接口, StochasticSystem,对一组反应(编码为numpy)进行操作。 化学计量系数矩阵)和相关反应速率:

fromarrowimportStochasticSystemimportnumpyasnp# Each row is a reaction and each column is a molecular species (or other# entity). The first reaction here means that the first and second elements# combine to create the third, while the fourth is unaffected.stoichiometric_matrix=np.array([[1,1,-1,0],[-2,0,0,1],[-1,-1,1,0]],np.int64)# Each reaction has an associated rate for how probable that reaction is.rates=np.array([3.0,1.0,1.0])# Once we have a matrix of reactions and their associated rates, we can# construct the system.system=StochasticSystem(stoichiometric_matrix,rates)

现在系统已经被实例化了,我们可以用任何初始的 状态向量,然后在给定的时间间隔内运行它:

# This gives the initial state of the system (counts of each molecular species,# for instance).state=np.array([1000,1000,0,0])# We also specify how long we want the simulation to run. Here we set it to one# second.duration=1

一旦我们有了初始状态和持续时间,我们就可以运行 给定的持续时间。evolve返回带五个键的字典:

  • 步骤-模拟所采取的步骤数
  • 时间-每个事件发生的时间点
  • 事件-发生的事件
  • 发生次数-每个事件发生的次数(直接从events派生)
  • 结果-系统的最终状态
result=system.evolve(state,duration)

如果你对绘制或其他的州的历史感兴趣,可以是 从事件列表和化学计量矩阵以及初始 国家。为您提供了一个函数``来执行此操作:

fromarrowimportreenact_eventshistory=reenact_events(stoichiometry,result['events'],state)

测试

arrow使用pytest:https://docs.pytest.org/en/latest/以便您可以简单地测试 通过调用:

> pytest

另外,我们还有一个测试,它生成了可以运行的各种系统的图 喜欢这样:

> python arrow/test/test_arrow.py --plot

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用Eclipse Helios for Web项目   java指定行。作为编译器设置的分隔符?   osm映射中带有osmdroid的java标记   java Android ClassNotFoundException在路径:DexPathList上未找到类   java从j2me调用GWT方法   更新到java 8后的aspectj问题   如何仅从根元素java,com提取文本内容。滴虫软件。是的。html   安卓公司。谷歌。火基。数据库DatabaseException:未能转换java类型的值。将字符串改为长字符串   从java中的方法返回arraylist变量   java如果将引用重新分配给同步块内的锁对象,会是什么?   java下载。使用spring mvc的资源文件中的xlsx文件   java Eclipse提供了什么工具来运行Eclipse中未包含的程序?   spring boot Java泛型如何读取传递给泛型方法的类型上的字段或调用方法   Javacard中的javaecdsa签名