Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Sample a product distribution pseudo randomly in a way that guarantees good coverage of all marginals
ResourceFunction["LatinHypercubeSample"][dim,n] generates n hypercube samples from ProductDistribution[{UniformDistribution[],dim}]. | |
ResourceFunction["LatinHypercubeSample"][dist,n] generates n samples from dist that cover the probability space of the distribution equally. | |
ResourceFunction["LatinHypercubeSample"][{dist1,dist2,…},n] generates n hypercube samples from ProductDistribution[dist1,dist2,…]. | |
ResourceFunction["LatinHypercubeSample"][spec, n, m] repeats the sampling m times, generating n×m samples. |
In[1]:= | ![]() |
Generate 10 random numbers between 0 and 1 that are roughly equally spaced:
In[1]:= | ![]() |
Out[1]= | ![]() |
In[2]:= | ![]() |
Out[2]= | ![]() |
In the case of 10 samples, each leading digit will always get exactly one sample:
In[3]:= | ![]() |
Out[3]= | ![]() |
Repeat the sampling 10 times to generate 100 samples:
In[4]:= | ![]() |
Out[4]= | ![]() |
Generate pairs of uniformly distributed numbers on the unit square:
In[5]:= | ![]() |
Out[5]= | ![]() |
Generate 10 samples from NormalDistribution[] that are equally distributed in probability space:
In[6]:= | ![]() |
Out[6]= | ![]() |
Demonstrate the equal spacing:
In[7]:= | ![]() |
Out[7]= | ![]() |
Due the use of equal spacing of the selection regions, samples tend to align more closely to the reference distribution in a ProbabilityPlot than completely random samples:
In[8]:= | ![]() |
Out[8]= | ![]() |
Sample a product of multiple different distributions, continuous or discrete:
In[9]:= | ![]() |
Out[9]= | ![]() |
Generate discrete samples from 1 to n:
In[10]:= | ![]() |
Out[11]= | ![]() |
Each row and each column has exactly one sample:
In[12]:= | ![]() |
Out[12]= | ![]() |
Wolfram Language 14.0 (January 2024) or above
This work is licensed under a Creative Commons Attribution 4.0 International License