0

I am trying to create a latin hypercube sampling with scipy, using the following code:

from scipy.stats.qmc import LatinHypercube

engine = LatinHypercube(d=250, seed=42)
sample = engine.integers(l_bounds=0, u_bounds=2, n=50)

>>> sample[0]
array([1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
       0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1,
       0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0,
       ...], dtype=int64)

Above code produces an LHS (size 50). I would like to however ensure some constraints on the sampling like for example;

  • First two values cannot be both 0 or 1

I though of a way; generate size=1000 sample and select only ones which fits to the constraints. However, when there are lots of constraints it is starting to be just like random sampling. The order of the elements in the sample also feels random, which makes it also hard to choose the approproate sampling size.

What would be best is like following, consider the following sample of 4 elements in 1 dimension:

size4 => ______x_____________x___________x_________x____

And when I increase the size to 8, if the following could be generated, then I can choose the element which fits to the constraints:

size4 => ______x_____________x___________x_________x____
size8 => ______xy____________xy_________yx_________xy___

With the above example, I can choose y instead of x if the x is not fitting to the constraints, and the sampling is also still somewhat LHS. Is it possible?

Reinderien
  • 11,755
  • 5
  • 49
  • 77
oakca
  • 1,408
  • 1
  • 18
  • 40
  • Your problem is so unclear that I won't risk an answer. Tips google "constrained random solvers", read https://www.ics.uci.edu/~csp/r98.pdf, install and try https://pypi.org/project/pycsp3/ – Bob May 02 '23 at 07:50

0 Answers0