Automating Experimental Optimization
2023-12-31
This talk is part 3 of a series on Experimental Design tutorials given at GemCity ML.
It based strongly on Dr. David Sweet’s book called “Experimentation for Engineers” (Sweet (2022))
Experimental Design Tutorials:

It cost money to run an experiment!
It also cost money to train algorithms and implement algorithms.
GPU time is expensive, if you can train and run on a CPU you can save a lot of money.
How do you know if you can reduce sample size and runtime?
There are mathematical models you can use to identify what is the number of sample you need to get good results. (see A/B testing)
In addition, not knowing how to adjust your experiment to meet the risk, can cost you your job and/or the company a lot of money.
When, Google debuted their Bard, it failed. It cost the company $100B in valuation. This was a high risk demo.
You need to know how to adjust your experiments for the risk!
This is where design experimentation comes in. How does one adjust for risk while reducing the cost of running the experiment.
One way to reduce cost and risk is to set-up an A/B Test, but that is only good for two variables: A and B.
How do you design an experiment when you have lots of variables.
This is were Bayesian Optimization comes in.
Bayesian optimization is a sequential design strategy for global optimization of black-box functions that does not assume any functional forms.
Machine Learning Models have multiple hyper-parameters that need to be optimized.
The model is a black-box function.
Training a ML model can take hours to weeks per configuration.
You want to quickly find the hyper-parameters that work well and before this decade ends!
Bayesian optimization is a sequential design strategy for global optimization of black-box functions that does not assume any functional forms.
Say you need to speed up the a web application. You can control seven parameters. However, each experiment will take an hour to run. (Sweet (2022))

The following example is from “Experimentation for Engineers”, by Dr. Sweet (Sweet (2022)).
What do we know about the system?
Look, we have a response surface! (shaded blue area)
Let’s take a measurement.

Let’s take a value in the middle.
Which results in
So, what happens to our uncertainty.

Note: Uncertainty follows an exponential decay: \(exp(-x^2)\)
How do we decide on which point to take next?
Let’s make another measurement.

We want to pick a value that lowers uncertainty but,
has the best expected outcome.

Remember our goal is to make the website faster.
The shaded area is our uncertainty times the standard deviation of results (y).
def kernel(self, x1, x2):
# find the distance between a measured and unmeasured point
# Want to weight points near a measured one more
distance_squared = ((x1-x2)**2)
return np.exp(-distance_squared/(2*self.sigma**2))
def estimate(self, query_parameter):
kernels_x_query = np.array([self.kernel(x, query_parameter)
for x in self.x])
kernels_x_x = np.array([[
self.kernel(x1, x2) for x1 in self.x]
for x2 in self.x])
weights= kernels_x_query.T @ np.linalg.inv(kernels_x_x)
expectation = self.mean_y + weights @ self.y # Dashed line
uncertainty_squared = 1 - weights @ kernels_x_query
uncertainty = np.sqrt(uncertainty_squared)
return expectation, self.std_y*uncertaintyValue = .17
We can see that we are converging quickly to an optimal solution
Remember we chose 0 to be our second value. We still get the same solution.
| Value = 0 | Value = 1 |
|---|---|
![]() |
![]() |
This is where the fun begins.
Our CPU test takes 1 hour and we want to sample each variable 10 times.
In 1000 years no one is going to care about your website.
So how do we improve the website while the content is still current?
Monte Carlo method is similar in a sense that we randomly select values to run our experiment.
However, in Bayesian Optimization we feed in past results and model the response surface to know if we are moving in the right direction.
We can see how the systems is converging to an optimized solution.

We optimized a system that would have took us over 1000 years to a couple days!

Gem City Tech ML/AI