Quant Memo
Core

Designing a Hyperparameter Search Space

Before any search algorithm runs, someone has to decide what range each hyperparameter can take and on what scale — get that wrong, uniform on the wrong scale or too narrow a range, and no amount of clever searching can find a good setting outside it.

Prerequisites: Random Search vs Grid Search, Hyperparameters vs Parameters

Any hyperparameter search — grid, random, or something more adaptive — only ever explores the region you told it to explore. If the true best learning rate is 0.00030.0003 but your search space runs from 0.010.01 to 0.10.1, no algorithm will ever find it, no matter how clever. Search-space design is the unglamorous decision that happens before any searching: what range should each hyperparameter span, and on what scale should values be drawn — because for many common hyperparameters, "evenly spaced" and "evenly useful" are not the same thing at all.

The analogy: a map that isn't drawn to a useful scale

Imagine using a single ruler to measure both the width of a room and the width of a continent — a scale useful for the room is useless for the continent, and vice versa. Learning rates behave similarly: whether a rate is 0.0010.001 or 0.010.01 matters enormously (a factor of 10 in effective step size), but whether it's 0.5010.501 or 0.5100.510 barely matters at all, even though both pairs differ by roughly the same absolute amount (0.0090.009 versus 0.0090.009). A search space that spaces its samples evenly in absolute terms — a linear scale — wastes most of its samples on tiny, unimportant absolute differences at the large end of the range, and starves the small end, where a factor of 10 can live in a sliver of absolute space.

Linear versus log scale

For a hyperparameter like learning rate or weight decay, where what matters is the ratio between values rather than their difference, sample on a log scale: draw uu uniformly from some range, then set the hyperparameter to 10u10^u (or eue^u).

η=10u,uUniform(a,b)\eta = 10^{u}, \qquad u \sim \text{Uniform}(a, b)

In words: instead of sampling the learning rate η\eta directly and evenly, sample its exponent uu evenly over a range (a,b)(a,b), then exponentiate — this spreads samples evenly across orders of magnitude (0.00010.0001, 0.0010.001, 0.010.01, 0.10.1 all get similar sampling density) rather than evenly across raw values (which would put almost every sample between 0.010.01 and 0.10.1 if the range were (0.0001,0.1)(0.0001, 0.1) sampled linearly). Hyperparameters like dropout rate or a mixing coefficient bounded between 00 and 11, where the actual magnitude (not the ratio) is what matters and the whole range is roughly equally interesting, are usually fine sampled on a plain linear scale instead.

Worked example 1: linear sampling wastes the small end

Learning rate range (0.0001,0.1)(0.0001, 0.1), 10 samples drawn uniformly on a linear scale. Roughly 9 of the 10 samples will land above 0.010.01 (since 0.010.01 to 0.10.1 is 90% of that linear range), and perhaps 0 or 1 will land below 0.0010.001 — even though the region between 0.00010.0001 and 0.0010.001, a whole order of magnitude, might contain the actual best value. Linear sampling here systematically starves the small-value region of any real search attention.

Worked example 2: log sampling spreads evenly across scales

Same range (0.0001,0.1)(0.0001, 0.1), sampled on a log scale: uUniform(4,1)u \sim \text{Uniform}(-4, -1) (since 104=0.000110^{-4}=0.0001 and 101=0.110^{-1}=0.1), then η=10u\eta = 10^u. Ten samples of uu spread evenly across (4,1)(-4,-1) land, roughly, two to three per unit interval — meaning about 2–3 samples fall in (0.0001,0.001)(0.0001, 0.001), another 2–3 in (0.001,0.01)(0.001, 0.01), and another 2–3 in (0.01,0.1)(0.01, 0.1): every order of magnitude gets comparable search attention, instead of nearly all of it going to the top decade as in the linear case.

Linear scale (10 samples) 0.0001 0.1 Log scale (10 samples) 0.0001 0.1
Linear sampling clusters almost every sample in the top decade of the range; log sampling spreads samples evenly across every order of magnitude.

Distribution · normal
-2.000.002.00μvalue →
Within ±1σ 68.3%mean μ 0.00std σ 1.00

Sampling a hyperparameter's exponent from a uniform distribution and exponentiating it is one specific case of the general idea the explorer above shows: the shape of the distribution you draw from determines where your samples actually land.

What this means in practice

Learning rate, weight decay, and most regularization strengths are conventionally searched on a log scale; dropout probability, momentum coefficients close to but below 1 (often reparameterized as 1momentum1-\text{momentum} on a log scale for the same reason), and mixing ratios are searched linearly or with their own natural reparameterization. Getting this wrong doesn't cause an error — it silently wastes most of a search budget on a region of the space that was never going to matter, which is why it's worth deciding deliberately rather than defaulting to "just sample uniformly" for every hyperparameter without checking whether that hyperparameter behaves multiplicatively or additively.

Hyperparameters where relative change (a factor of 10) matters more than absolute change should be sampled on a log scale, so search attention spreads evenly across orders of magnitude instead of clustering wherever the raw numeric values happen to be largest.

Practice

  1. You want to search weight decay between 10610^{-6} and 10210^{-2}. What uniform range for the exponent uu would you sample from?
  2. Why is dropout probability (bounded between 0 and 1, no notion of "orders of magnitude") usually fine on a linear scale?
  3. In one sentence, why does a badly chosen search space undermine even a very good search algorithm?

It's tempting to think any hyperparameter is safe to sample "uniformly" as a neutral, assumption-free default. Uniform is never assumption-free — it's an assumption that every equal-sized slice of the range is equally likely to matter, which is false for scale-sensitive hyperparameters like learning rate. Choosing linear-versus-log is a modeling decision with real consequences for search quality, not a technical detail to skip past.

Related concepts

Practice in interviews

Further reading

  • Bergstra & Bengio, Random Search for Hyper-Parameter Optimization, JMLR (2012)
ShareTwitterLinkedIn