使用python进行拉丁超立方体采样 [英] Latin hypercube sampling with python

查看:1925
本文介绍了使用python进行拉丁超立方体采样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对一个函数定义的分布进行多维(2、3、4)采样:

I would like to sample a distribution defined by a function in multiple dimensions (2,3,4):

f(x, y, ...) = ...

分布可能是丑陋的,非标准的(例如数据上的3D样条曲线,高斯之和等).为此,我想对2..4维空间进行均匀采样,然后使用一个额外的随机数来接受或拒绝该空间的给定点进入我的样本.

The distributions might be ugly, non standard (like a 3D spline on data, sum of gaussians ect.). To this end I would like to uniformly sample the 2..4 dimensional space, and than with an additional random number accept or reject the given point of the space into my sample.

  1. 是否已准备好为此目的使用python lib?

  1. Is there a ready to use python lib for this purpose?

是否存在python lib来通过拉丁超立方体采样或其他统一采样方法在2..4维空间中生成点?具有独立随机数的Bruteforce采样通常会导致空间密度越来越小.

Is there python lib for generating the points in this 2..4 dimensional space with latin hypercube sampling, or with other uniform sampling method? Bruteforce sampling with independent random numbers usually results in more and less dense regimes of the space.

如果1)和2)不存在,那么有没有人愿意和他分享相同或相似问题的实现.

if 1) and 2) doesn't exist, is there anybody who is kind enough to share his implementation for the same or similar problem.

我将在python代码中使用它,但也会认可与其他解决方案的链接.

I'll use it in a python code, but links to other solutions are also acknowledged.

推荐答案

我想这是一个较晚的答案,但这也适合将来的访问者.我刚刚在git上放置了多维统一拉丁Hypercube采样的实现.它是最小的,但非常易于使用.如果变量是独立的,则可以使用Latin Hypercube Sampling生成在n个维度中采样的统一随机变量.下面是一个示例图,它比较了零相关的二维蒙特卡罗和拉丁文超立方体采样以及多维统一性(LHS-MDU).

I guess this is a late answer, but this is also for future visitors. I have just put up an implementation of multi-dimensional uniform Latin Hypercube sampling on git. It is minimal, but very easy to use. You can generate uniform random variables sampled in n dimensions using Latin Hypercube Sampling, if your variables are independent. Below is an example plot comparing Monte Carlo and Latin Hypercube Sampling with Multi-dimensional Uniformity (LHS-MDU) in two dimensions with zero correlation.

import lhsmdu
import matplotlib.pyplot as plt
import numpy

l = lhsmdu.sample(2,10) # Latin Hypercube Sampling of two variables, and 10 samples each.
k = lhsmdu.createRandomStandardUniformMatrix(2,10) # Monte Carlo Sampling

fig = plt.figure()
ax = fig.gca()
ax.set_xticks(numpy.arange(0,1,0.1))
ax.set_yticks(numpy.arange(0,1,0.1))
plt.scatter(k[0], k[1], color="b", label="LHS-MDU")
plt.scatter(l[0], l[1], color="r", label="MC")
plt.grid()
plt.show()

这篇关于使用python进行拉丁超立方体采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆