Fetching a Latin hypercube using python

I would like to try the distribution defined by the function in several dimensions (2,3,4):

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

Distributions can be ugly, non-standard (for example, a 3D spline on data, the amount of gaussians ect.). For this purpose, I would like to evenly try space in space 2..4, and with an additional random number to accept or reject a given point in space in my sample.

  • Is there any ready-to-use python lib for this purpose?

  • Is there python lib for creating points in this 2..4-dimensional space with latin hypercube sampling or using another uniform sampling method? Bruteforce sampling with independent random numbers usually results in denser spatial modes.

  • if 1) and 2) does not exist, is there someone who is kind enough to share their implementation on the same or similar issue.

I will use it in python code, but links to other solutions are also confirmed.

+4
source share
3 answers

, , . Latin Hypercube git. , . , n , Latin Hypercube Sampling, . - (LHS-MDU) .

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()

MCS vs LHS

+3

pyDOE .

https://pythonhosted.org/pyDOE/randomized.html

n :

lhs(n, [samples, criterion, iterations])

n - , - .

+2

This two-dimensional example of samples uniformly on two dimensions, selects each point with a constant probability (thus preserving the doubly distributed number of points), randomly selects and does not replace these points from the sampling space and generates a pair of vectors that you can go to your function f :

import numpy as np
import random
resolution = 10
keepprob = 0.5
min1, max1 = 0., 1.
min2, max2 = 3., 11. 
keepnumber = np.random.binomial(resolution * resolution, keepprob,1)
array1,array2  = np.meshgrid(np.linspace(min1,max1,resolution),np.linspace(min2,max2,resolution))
randominixes  = random.sample(list(range(resolution * resolution)), int(keepnumber))
randominixes.sort()
vec1Sampled,vec2Sampled  = array1.flatten()[randominixes],array2.flatten()[randominixes]
0
source

All Articles