Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Tuning the knobs
A new oven has temperature and time knobs. You could try every combination on a neat chart, which wastes many cakes on settings that barely differ. You could try random settings, which explores more distinct temperatures. You could learn from each cake to pick the next setting. Or you could taste every cake after five minutes and only keep baking the promising ones. These are the four main ways to tune a model’s knobs, its hyperparameters.
Each training run of a perception network or a large simulation surrogate can cost hours of GPU time. Smart tuning gets a better model for the same budget, or the same model at a fraction of the cost.
- 1. A hyperparameter is…
- 2. In the demo, random search tests more values of the important knob because…
- 3. Stopping bad trials early saves…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Four strategies
| Strategy | How it chooses trials | Strength | Weakness |
|---|---|---|---|
| grid | every combination of listed values | simple, reproducible | cost grows exponentially; few distinct values per dimension |
| random | independent samples from distributions | covers important dimensions; parallel | ignores past results |
| Bayesian optimisation (GP, TPE) | surrogate model + acquisition function (expected improvement) | sample-efficient | sequential; overhead; struggles in high dimensions |
| successive halving / Hyperband | start many trials with small budget, keep the best 1/η | huge savings when early results predict final ones | misled if early rankings differ from final ones |
Search spaces: sample learning rates and regularisation on a log scale, integers (depth, neighbours) on integer ranges, and categoricals (kernel type) as choices. Tune on validation data or inside cross-validation, and report on a separate test set (D0.4).
import optuna
def objective(trial):
lr = trial.suggest_float("lr", 1e-5, 1e-1, log=True)
depth = trial.suggest_int("depth", 2, 10)
return cross_val_score(make_model(lr, depth), X, y, cv=5).mean()
study = optuna.create_study(direction="maximize", sampler=optuna.samplers.TPESampler(), pruner=optuna.pruners.HyperbandPruner())
study.optimize(objective, n_trials=100); print(study.best_params)- 1. A learning rate should be sampled…
- 2. Grid search with 5 values for each of 6 hyperparameters needs…
- 3. Optuna's default TPE sampler is a form of…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.How the smarter methods work
Bayesian optimisation (A6.4.2) fits a surrogate, such as a Gaussian process or TPE density ratio, to the (configuration, validation loss) pairs seen so far. It then picks the configuration maximising expected improvement:
EI(x) = (f* − μ)Φ(z) + σφ(z), with z = (f* − μ)/σ.
This balances exploiting low predicted loss μ against exploring high uncertainty σ.
Successive halving with factor η:
- Evaluate n configurations with budget b.
- Keep the best n/η and give them budget ηb.
- Repeat until one remains.
The total cost is about n·b·(number of rounds). Hyperband runs several brackets with different trade-offs between “many cheap trials” and “few full trials”, hedging against early rankings being unreliable. BOHB and Optuna combine Bayesian sampling with Hyperband pruning.
- 1. Expected improvement is large where…
- 2. Successive halving with η = 3 keeps…
- 3. Hyperband runs several brackets because…
Level 3: Advanced
★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.Practical tuning
- Start from sensible defaults and tune the few hyperparameters that matter most: learning rate first, then regularisation and capacity.
- Budget: random search with 50–100 trials is a strong baseline. Use Bayesian methods when trials are expensive and few; use Hyperband or ASHA pruning when partial training is informative.
- Parallelism: random search and Hyperband/ASHA parallelise trivially; sequential Bayesian optimisation needs batch variants.
- Noise: validation scores are noisy (D0.4). Repeat the top configurations, and don’t over-tune small differences.
- Never tune on the test set. Use nested CV or a final hold-out for the reported number.
Interview questions.
- Why is random search better than grid search? With low effective dimensionality, random search samples each important hyperparameter at n distinct values rather than n^(1/d) (Bergstra and Bengio, 2012).
- When can early stopping of trials mislead? When good configurations start slowly, for example small learning rates that end best.
- 1. 100 random trials, each with a 5% chance of hitting the top region; chance of at least one hit?
- 2. Best strategy for 8 GPUs and cheap partial evaluations?
- 3. Reported performance after tuning must come from…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.The same budget, five strategies
Exercise 1.
- Grid search finds lr = 10⁻², l2 = 10⁻³ in 90 epochs.
- Random search lands within 0.3 decades of the optimal learning rate.
- Successive halving over 27 configurations spends 108 epochs.
- Bayesian optimisation finds the minimum of a 1-D function at 0.731 (true 0.73) in 13 evaluations.
Exercise 2: 2 430 epochs each (30 full runs of 81 epochs). The objective:
- validation loss = final loss + learning-speed term · epochs^(−1/2) + noise;
- the learning rate matters 12 times more than L2;
- larger learning rates learn faster, so short runs favour them;
- the optimum lies between grid points, as it usually does.
Results are the mean regret of the chosen configuration’s final loss over 20 runs:
| Strategy | Mean regret | Median |
|---|---|---|
| grid 6 × 5 | 0.074 | 0.074 |
| random, 30 trials | 0.025 | 0.023 |
| Bayesian (GP-EI), 30 trials | 0.005 | 0.004 |
| successive halving (repeated 81-config brackets) | 0.009 | 0.005 |
| Hyperband | 0.010 | 0.007 |
- Random search is 3× better than the grid, because it tries 30 learning rates instead of 6.
- With full-length trials, Bayesian optimisation is best: the objective is smooth and two-dimensional, the setting it was designed for.
- The multi-fidelity methods come second. They evaluate hundreds of configurations, but their early rankings are biased toward fast-learning large learning rates, which costs accuracy. Their advantage grows when early results are more predictive or when the search space is larger.
Hyperparameter tuning in AI, robotics and aerospace
- Controller tuning: Bayesian optimisation of PID or MPC gains on hardware, where each trial is a costly flight or drive test.
- Perception networks: ASHA/Hyperband pruning on GPU clusters.
- Simulation surrogates: tuning kernel and regularisation parameters of Gaussian-process or neural surrogates.
- AutoML: Auto-sklearn and AutoGluon combine Bayesian optimisation, meta-learning and ensembling.
References
- J. Bergstra, Y. Bengio (2012). “Random search for hyper-parameter optimization.” JMLR 13.
- J. Snoek, H. Larochelle, R. P. Adams (2012). “Practical Bayesian optimization of machine learning algorithms.” NeurIPS.
- L. Li, K. Jamieson, G. DeSalvo, A. Rostamizadeh, A. Talwalkar (2018). “Hyperband: a novel bandit-based approach to hyperparameter optimization.” JMLR 18.
- S. Falkner, A. Klein, F. Hutter (2018). “BOHB: robust and efficient hyperparameter optimization at scale.” ICML.
- T. Akiba et al. (2019). “Optuna: a next-generation hyperparameter optimization framework.” KDD.