多层次的蒙特卡洛与Python
MLMC的Python项目详细描述
mlmcpy-multi-levelmontecarlo和python
一般
mlmcpy是一个开源的python实现的多级monte carlo(mlmc)不确定性传播方法。一旦用户定义了自己的计算模型并指定了模型输入参数的不确定性,mlmcpy就可以用于在指定精度内估计感兴趣量的期望值。支持并行执行所需的模型评估(如果安装了mpi4py),并提供mlmc方法的扩展以计算更高级的统计信息(例如协方差、cdfs)。
依赖关系
mlmcpy用于python 2.7,依赖于以下包:
- 努比
- scipy
- MPI4PY(并行运行时可选)
- pytest(运行单元测试时可选)
示例用法
'''Simple example of propagating uncertainty through a spring-mass model using MLMC. Estimates the expected value of the maximum displacement of the system when the spring stiffness is a random variable. See the /examples/spring_mass/from_model/ for more details.'''importnumpyasnpimportsysfromMLMCPy.inputimportRandomInputfromMLMCPy.mlmcimportMLMCSimulator# Add path for example SpringMassModel to sys path.sys.path.append('./examples/spring_mass/from_model/spring_mass')importSpringMassModel# Step 1 - Define random variable for spring stiffness:# Need to provide a sampleable function to create RandomInput instance in MLMCPydefbeta_distribution(shift,scale,alpha,beta,size):returnshift+scale*np.random.beta(alpha,beta,size)stiffness_distribution=RandomInput(distribution_function=beta_distribution,shift=1.0,scale=2.5,alpha=3.,beta=2.)# Step 2 - Initialize spring-mass models. Here using three levels with MLMC.# defined by different time stepsmodel_level1=SpringMassModel(mass=1.5,time_step=1.0)model_level2=SpringMassModel(mass=1.5,time_step=0.1)model_level3=SpringMassModel(mass=1.5,time_step=0.01)models=[model_level1,model_level2,model_level3]# Step 3 - Initialize MLMC & predict max displacement to specified error (0.1).mlmc_simulator=MLMCSimulator(stiffness_distribution,models)[estimates,sample_sizes,variances]=mlmc_simulator.simulate(epsilon=1e-1)
开始
开始使用mlmcpy的最好方法是查看examples/目录中的脚本。在examples/spring_mass/from_model
目录中可以找到通过弹簧质量系统传播不确定性的简单示例。第二个示例演示了用户可以从examples/spring_mass/from_data/
目录中的多个级别的模型(而不是他们可以直接计算的模型)访问输入输出数据的情况。有关详细信息,请参阅docs/MLMCPy_documentation.pdf
(正在进行的工作)中的源代码文档。
测试
可以通过从tests/目录运行“py.test”来执行这些测试,以确保正确的安装。
开发人员
UQ卓越中心
美国宇航局兰利研究中心
弗吉尼亚州汉普顿
该软件由美国宇航局兰利研究中心的高性能计算孵化器(hpci)资助和开发。
撰稿人:詹姆斯·华纳(james warner,james.e.warner@nasa.gov)、卢克·莫里尔(luke morrill)、胡安·巴林托斯(juan barrientos)
许可证
版权所有2018美国政府,由国家航空航天局局长代表。在美国,《美国法典》第17编中没有版权要求。保留所有其他权利。
免责声明 无保修:主题软件提供“如”,没有任何保证,无论是明示的,暗示的,或法定的,包括但不限于,任何保证,主题软件将符合规范,任何隐含保证适销性,适合某一特定目的,或不受侵犯的自由,任何保证主题软件无错误,或任何保证文件,如果提供,将符合主题软件。本协议不以任何方式构成政府机构或任何先前接收者对任何结果、由此产生的设计、硬件、软件产品或因使用本主题软件而产生的任何其他应用的认可。此外,政府机构不承认有关第三方软件的所有保证和责任,如果存在于原始软件中,并分发它“原样”。
弃权和赔偿:接受方同意放弃对美国政府、其承包商和分包商以及任何先前接受方的任何和所有索赔。如果接受方使用标的软件导致任何责任、要求、损害、费用或损失,包括因接受方使用标的软件而导致的产品损害,接受方应赔偿美国政府、其承包商和分包商,并使其免受损害。以及在法律允许的范围内的任何先前的接收者。接受方对任何此类事项的唯一补救措施是立即单方面终止本协议。