arrow

Research Skills

Latin Hypercube Sampling: A Simple Guide With Examples

Learn latin hypercube sampling, how it works, and how to create evenly distributed sample points for computer simulations. Explore a five-point example, compare it with Monte Carlo and Sobol methods, and discover how to implement it in Python using SciPy.

Latin Hypercube Sampling: A Simple Guide With Examples

Latin hypercube sampling is a way to pick sample points so they cover every input evenly. You cut each input into equal slices and take one point from each slice. That spreads your points out better than plain random picking, so you need fewer runs of a slow model.

The Problem It Solves

Say your computer model has three inputs, and each run takes an hour. You can only afford about 50 runs, but you still want to test the full range of every input.

Random picking can let you down. By bad luck, a bunch of points land in one corner while other areas stay empty. This method helps stop that from happening.

How Latin Hypercube Sampling Works

Here’s the rule. If you want n points, split each input into n slices of equal chance. Pick exactly one point from every slice. Then shuffle how the slices pair up across inputs.

McKay, Beckman and Conover shared the method in a 1979 paper in the journal Technometrics. Today it’s common in simulation, uncertainty checks and quantitative research that relies on computer models.

A Five Point Example

Let’s sample two inputs, X and Y, between 0 and 1. We want 5 points.

  1. Make 5 slices for each input. Each one is 0.2 wide: 0 to 0.2, 0.2 to 0.4, 0.4 to 0.6, 0.6 to 0.8, and 0.8 to 1.

  2. Pick one X value inside each slice: 0.12, 0.31, 0.55, 0.78, 0.93.

  3. Pick one Y value inside each slice: 0.07, 0.35, 0.47, 0.64, 0.86.

  4. Shuffle the Y values, then pair them with the X values.

Here’s one possible result:

Point

X

Y

X slice

Y slice

1

0.12

0.47

1st

3rd

2

0.31

0.86

2nd

5th

3

0.55

0.07

3rd

1st

4

0.78

0.64

4th

4th

5

0.93

0.35

5th

2nd

And here it is on a 5 by 5 grid:

X1

X2

X3

X4

X5

Y5

●

Y4

●

Y3

●

Y2

●

Y1

●

Every row and every column holds exactly one point. A different shuffle gives a different sample, and it’s just as good.

Why Is It Called “Latin Hypercube”?

A Latin square is a grid where each symbol shows up once in every row and every column. This method follows the same rule. A hypercube is the same idea with more than two inputs.

Latin Hypercube Sampling vs Other Methods

Method

How points are chosen

Strength

Weak spot

Simple random (Monte Carlo)

Every point is independent

Easy, works for any size

Can leave gaps and clumps

Latin hypercube

One point per slice of each input

Even coverage of each input

Combinations can still bunch up

Full grid

Every mix of levels

Complete coverage

10 levels and 6 inputs means 1,000,000 runs

Sobol or Halton

A fixed, evenly spread sequence

Often more even

Less flexible in some cases

The SciPy documentation says an estimate from n points this way never has more variance than plain Monte Carlo with one fewer point. It also works best when each input adds its own separate effect to the result.

Oracle’s Crystal Ball documentation says it needs fewer trials than Monte Carlo for the same accuracy. SciPy also notes that scrambled Sobol and Halton sequences can do even better.

It also differs from everyday data collection methods like surveys. Here you’re choosing settings for a model, not picking people.

How to Run It in Python

SciPy can do latin hypercube sampling in a few lines:

python

from scipy.stats import qmc

sampler = qmc.LatinHypercube(d=2, seed=42)

sample = sampler.random(n=5)

scaled = qmc.scale(sample, [0, 2], [10, 5])

The first line of work picks 5 points for 2 inputs. The last line stretches them to real ranges: X from 0 to 10 and Y from 2 to 5.

The SciPy docs list a few helpful options. Scramble places points randomly inside each cell. Optimization improves how evenly points fill the space, but it costs more computing time. Strength set to 2 builds an orthogonal array version, but only for certain sample sizes.

Want an input shaped like a bell curve? Convert each column with that distribution’s inverse CDF. In SciPy, that’s the ppf method.

When to Use It

Use it when each model run is slow or costly. It’s also a good fit when you have several inputs and want every range tested. People often use it for uncertainty checks and for building surrogate models.

Think twice if you need to add points later. Plain versions fix n in advance, and extra points break the one per slice rule. A Sobol sequence extends more easily.

Be careful if your inputs are strongly linked. The basic method assumes they’re independent.

Limits and Common Mistakes

Even coverage of each input doesn’t mean even coverage overall. A set of points lying along the diagonal is still a valid Latin hypercube, yet it covers the space badly. That’s why optimized versions exist.

There’s no magic sample size. Some researchers suggest about 10 points per input as a starting point, but that’s only a rule of thumb.

Watch for these slips. Don’t forget to scale the unit values to real ranges. Don’t skip the inverse CDF step for inputs that aren’t flat. And set a seed so you can repeat your results.

Also run it a few times with different seeds. Compare the answers with a measure like the coefficient of variation to see how steady they are.

Final Thoughts

Latin hypercube sampling gives you even coverage of every input with few runs. Try it on a small model. Draw 10 points with SciPy, plot them, and compare them with 10 plain random points.

FAQs

Is it better than random sampling?

For small samples and slow models, usually yes. It guarantees each input’s range is covered evenly.

Can I add more points later?

Not directly. Plan your sample size first, or look at a Sobol sequence.

Does it work for other distributions?

Yes. Sample evenly in probability, then convert the values with the distribution’s inverse CDF.

How many samples do I need?

It depends on your inputs and model. Start with your budget, test a few seeds, and add points if answers keep changing.

What is Canyam?

Canyam lets you search more than 65 million research papers and read AI generated summaries. You can find key findings, methods and citations in minutes.