Bayesian Optimization in Action

Book description

Bayesian optimization helps pinpoint the best configuration for your machine learning models with speed and accuracy. Put its advanced techniques into practice with this hands-on guide.

In Bayesian Optimization in Action you will learn how to:

  • Train Gaussian processes on both sparse and large data sets
  • Combine Gaussian processes with deep neural networks to make them flexible and expressive
  • Find the most successful strategies for hyperparameter tuning
  • Navigate a search space and identify high-performing regions
  • Apply Bayesian optimization to cost-constrained, multi-objective, and preference optimization
  • Implement Bayesian optimization with PyTorch, GPyTorch, and BoTorch

Bayesian Optimization in Action shows you how to optimize hyperparameter tuning, A/B testing, and other aspects of the machine learning process by applying cutting-edge Bayesian techniques. Using clear language, illustrations, and concrete examples, this book proves that Bayesian optimization doesn’t have to be difficult! You’ll get in-depth insights into how Bayesian optimization works and learn how to implement it with cutting-edge Python libraries. The book’s easy-to-reuse code samples let you hit the ground running by plugging them straight into your own projects.

About the Technology
In machine learning, optimization is about achieving the best predictions—shortest delivery routes, perfect price points, most accurate recommendations—in the fewest number of steps. Bayesian optimization uses the mathematics of probability to fine-tune ML functions, algorithms, and hyperparameters efficiently when traditional methods are too slow or expensive.

About the Book
Bayesian Optimization in Action teaches you how to create efficient machine learning processes using a Bayesian approach. In it, you’ll explore practical techniques for training large datasets, hyperparameter tuning, and navigating complex search spaces. This interesting book includes engaging illustrations and fun examples like perfecting coffee sweetness, predicting weather, and even debunking psychic claims. You’ll learn how to navigate multi-objective scenarios, account for decision costs, and tackle pairwise comparisons.

What's Inside
  • Gaussian processes for sparse and large datasets
  • Strategies for hyperparameter tuning
  • Identify high-performing regions
  • Examples in PyTorch, GPyTorch, and BoTorch


About the Reader
For machine learning practitioners who are confident in math and statistics.

About the Author
Quan Nguyen is a research assistant at Washington University in St. Louis. He writes for the Python Software Foundation and has authored several books on Python programming.

Quotes
Using a hands-on approach, clear diagrams, and real-world examples, Quan lifts the veil off the complexities of Bayesian optimization.
- From the Foreword by Luis Serrano, Author of Grokking Machine Learning

This book teaches Bayesian optimization, starting from its most basic components. You’ll find enough depth to make you comfortable with the tools and methods and enough code to do real work very quickly.
- From the Foreword by David Sweet, Author of Experimentation for Engineers

Combines modern computational frameworks with visualizations and infographics you won’t find anywhere else. It gives readers the confidence to apply Bayesian optimization to real world problems!
- Ravin Kumar, Google

Table of contents

  1. Inside front cover
  2. Bayesian Optimization in Action
  3. Copyright
  4. dedication
  5. contents
  6. front matter
    1. forewords
    2. preface
    3. acknowledgments
    4. about this book
      1. Who should read this book?
      2. How this book is organized: A roadmap
      3. About the code
      4. liveBook discussion forum
    5. about the author
      1. About the technical editor
    6. about the cover illustration
  7. 1 Introduction to Bayesian optimization
    1. 1.1 Finding the optimum of an expensive black box function
      1. 1.1.1 Hyperparameter tuning as an example of an expensive black box optimization problem
      2. 1.1.2 The problem of expensive black box optimization
      3. 1.1.3 Other real-world examples of expensive black box optimization problems
    2. 1.2 Introducing Bayesian optimization
      1. 1.2.1 Modeling with a Gaussian process
      2. 1.2.2 Making decisions with a BayesOpt policy
      3. 1.2.3 Combining the GP and the optimization policy to form the optimization loop
      4. 1.2.4 BayesOpt in action
    3. 1.3 What will you learn in this book?
    4. Summary
  8. Part 1. Modeling with Gaussian processes
  9. 2 Gaussian processes as distributions over functions
    1. 2.1 How to sell your house the Bayesian way
    2. 2.2 Modeling correlations with multivariate Gaussian distributions and Bayesian updates
      1. 2.2.1 Using multivariate Gaussian distributions to jointly model multiple variables
      2. 2.2.2 Updating MVN distributions
      3. 2.2.3 Modeling many variables with high-dimensional Gaussian distributions
    3. 2.3 Going from a finite to an infinite Gaussian
    4. 2.4 Implementing GPs in Python
      1. 2.4.1 Setting up the training data
      2. 2.4.2 Implementing a GP class
      3. 2.4.3 Making predictions with a GP
      4. 2.4.4 Visualizing predictions of a GP
      5. 2.4.5 Going beyond one-dimensional objective functions
    5. 2.5 Exercise
    6. Summary
  10. 3 Customizing a Gaussian process with the mean and covariance functions
    1. 3.1 The importance of priors in Bayesian models
    2. 3.2 Incorporating what you already know into a GP
    3. 3.3 Defining the functional behavior with the mean function
      1. 3.3.1 Using the zero mean function as the base strategy
      2. 3.3.2 Using the constant function with gradient descent
      3. 3.3.3 Using the linear function with gradient descent
      4. 3.3.4 Using the quadratic function by implementing a custom mean function
    4. 3.4 Defining variability and smoothness with the covariance function
      1. 3.4.1 Setting the scales of the covariance function
      2. 3.4.2 Controlling smoothness with different covariance functions
      3. 3.4.3 Modeling different levels of variability with multiple length scales
    5. 3.5 Exercise
    6. Summary
  11. Part 2. Making decisions with Bayesian optimization
  12. 4 Refining the best result with improvement-based policies
    1. 4.1 Navigating the search space in BayesOpt
      1. 4.1.1 The BayesOpt loop and policies
      2. 4.1.2 Balancing exploration and exploitation
    2. 4.2 Finding improvement in BayesOpt
      1. 4.2.1 Measuring improvement with a GP
      2. 4.2.2 Computing the Probability of Improvement
      3. 4.2.3 Running the PoI policy
    3. 4.3 Optimizing the expected value of improvement
    4. 4.4 Exercises
      1. 4.4.1 Exercise 1: Encouraging exploration with PoI
      2. 4.4.2 Exercise 2: BayesOpt for hyperparameter tuning
    5. Summary
  13. 5 Exploring the search space with bandit-style policies
    1. 5.1 Introduction to the MAB problem
      1. 5.1.1 Finding the best slot machine at a casino
      2. 5.1.2 From MAB to BayesOpt
    2. 5.2 Being optimistic under uncertainty with the Upper Confidence Bound policy
      1. 5.2.1 Optimism under uncertainty
      2. 5.2.2 Balancing exploration and exploitation
      3. 5.2.3 Implementation with BoTorch
    3. 5.3 Smart sampling with the Thompson sampling policy
      1. 5.3.1 One sample to represent the unknown
      2. 5.3.2 Implementation with BoTorch
    4. 5.4 Exercises
      1. 5.4.1 Exercise 1: Setting an exploration schedule for the UCB
      2. 5.4.2 Exercise 2: BayesOpt for hyperparameter tuning
    5. Summary
  14. 6 Using information theory with entropy-based policies
    1. 6.1 Measuring knowledge with information theory
      1. 6.1.1 Measuring uncertainty with entropy
      2. 6.1.2 Looking for a remote control using entropy
      3. 6.1.3 Binary search using entropy
    2. 6.2 Entropy search in BayesOpt
      1. 6.2.1 Searching for the optimum using information theory
      2. 6.2.2 Implementing entropy search with BoTorch
    3. 6.3 Exercises
      1. 6.3.1 Exercise 1: Incorporating prior knowledge into entropy search
      2. 6.3.2 Exercise 2: Bayesian optimization for hyperparameter tuning
    4. Summary
  15. Part 3. Extending Bayesian optimization to specialized settings
  16. 7 Maximizing throughput with batch optimization
    1. 7.1 Making multiple function evaluations simultaneously
      1. 7.1.1 Making use of all available resources in parallel
      2. 7.1.2 Why can’t we use regular BayesOpt policies in the batch setting?
    2. 7.2 Computing the improvement and upper confidence bound of a batch of points
      1. 7.2.1 Extending optimization heuristics to the batch setting
      2. 7.2.2 Implementing batch improvement and UCB policies
    3. 7.3 Exercise 1: Extending TS to the batch setting via resampling
    4. 7.4 Computing the value of a batch of points using information theory
      1. 7.4.1 Finding the most informative batch of points with cyclic refinement
      2. 7.4.2 Implementing batch entropy search with BoTorch
    5. 7.5 Exercise 2: Optimizing airplane designs
    6. Summary
  17. 8 Satisfying extra constraints with constrained optimization
    1. 8.1 Accounting for constraints in a constrained optimization problem
      1. 8.1.1 Constraints can change the solution of an optimization problem
      2. 8.1.2 The constraint-aware BayesOpt framework
    2. 8.2 Constraint-aware decision-making in BayesOpt
    3. 8.3 Exercise 1: Manual computation of constrained EI
    4. 8.4 Implementing constrained EI with BoTorch
    5. 8.5 Exercise 2: Constrained optimization of airplane design
    6. Summary
  18. 9 Balancing utility and cost with multifidelity optimization
    1. 9.1 Using low-fidelity approximations to study expensive phenomena
    2. 9.2 Multifidelity modeling with GPs
      1. 9.2.1 Formatting a multifidelity dataset
      2. 9.2.2 Training a multifidelity GP
    3. 9.3 Balancing information and cost in multifidelity optimization
      1. 9.3.1 Modeling the costs of querying different fidelities
      2. 9.3.2 Optimizing the amount of information per dollar to guide optimization
    4. 9.4 Measuring performance in multifidelity optimization
    5. 9.5 Exercise 1: Visualizing average performance in multifidelity optimization
    6. 9.6 Exercise 2: Multifidelity optimization with multiple low-fidelity approximations
    7. Summary
  19. 10 Learning from pairwise comparisons with preference optimization
    1. 10.1 Black-box optimization with pairwise comparisons
    2. 10.2 Formulating a preference optimization problem and formatting pairwise comparison data
    3. 10.3 Training a preference-based GP
    4. 10.4 Preference optimization by playing king of the hill
    5. Summary
  20. 11 Optimizing multiple objectives at the same time
    1. 11.1 Balancing multiple optimization objectives with BayesOpt
    2. 11.2 Finding the boundary of the most optimal data points
    3. 11.3 Seeking to improve the optimal data boundary
    4. 11.4 Exercise: Multiobjective optimization of airplane design
    5. Summary
  21. Part 4. Special Gaussian process models
  22. 12 Scaling Gaussian processes to large datasets
    1. 12.1 Training a GP on a large dataset
      1. 12.1.1 Setting up the learning task
      2. 12.1.2 Training a regular GP
      3. 12.1.3 Problems with training a regular GP
    2. 12.2 Automatically choosing representative points from a large dataset
      1. 12.2.1 Minimizing the difference between two GPs
      2. 12.2.2 Training the model in small batches
      3. 12.2.3 Implementing the approximate model
    3. 12.3 Optimizing better by accounting for the geometry of the loss surface
    4. 12.4 Exercise
    5. Summary
  23. 13 Combining Gaussian processes with neural networks
    1. 13.1 Data that contains structures
    2. 13.2 Capturing similarity within structured data
      1. 13.2.1 Using a kernel with GPyTorch
      2. 13.2.2 Working with images in PyTorch
      3. 13.2.3 Computing the covariance of two images
      4. 13.2.4 Training a GP on image data
    3. 13.3 Using neural networks to process complex structured data
      1. 13.3.1 Why use neural networks for modeling?
      2. 13.3.2 Implementing the combined model in GPyTorch
    4. Summary
  24. Appendix. Solutions to the exercises
    1. A.1 Chapter 2: Gaussian processes as distributions over functions
    2. A.2 Chapter 3: Incorporating prior knowledge with the mean and covariance functions
    3. A.3 Chapter 4: Refining the best result with improvement-based policies
    4. A.3.1 Exercise 1: Encouraging exploration with Probability of Improvement
    5. A.3.2 Exercise 2: BayesOpt for hyperparameter tuning
    6. A.4 Chapter 5: Exploring the search space with bandit-style policies
    7. A.4.1 Exercise 1: Setting an exploration schedule for Upper Confidence Bound
    8. A.4.2 Exercise 2: BayesOpt for hyperparameter tuning
    9. A.5 Chapter 6: Using information theory with entropy-based policies
    10. A.5.1 Exercise 1: Incorporating prior knowledge into entropy search
    11. A.5.2 Exercise 2: BayesOpt for hyperparameter tuning
    12. A.6 Chapter 7: Maximizing throughput with batch optimization
    13. A.6.1 Exercise 1: Extending TS to the batch setting via resampling
    14. A.6.2 Exercise 2: Optimizing airplane designs
    15. A.7 Chapter 8: Satisfying extra constraints with constrained optimization
    16. A.7.1 Exercise 1: Manual computation of constrained EI
    17. A.7.2 Exercise 2: Constrained optimization of airplane design
    18. A.8 Chapter 9: Balancing utility and cost with multifidelity optimization
    19. A.8.1 Exercise 1: Visualizing average performance in multifidelity optimization
    20. A.8.2 Exercise 2: Multifidelity optimization with multiple low-fidelity approximations
    21. A.9 Chapter 11: Optimizing multiple objectives at the same time
    22. A.10 Chapter 12: Scaling Gaussian processes to large data sets
  25. index
  26. Inside back cover

Product information

  • Title: Bayesian Optimization in Action
  • Author(s): Quan Nguyen
  • Release date: December 2023
  • Publisher(s): Manning Publications
  • ISBN: 9781633439078