Numerical Optimization II: Multiple Dimensions
Eugeniy E. Mikhailov and Greg Bentsen
Logistics and Agenda
Homework 4 due Today Oct 19 at 11:59pm
Homework 5 due Monday Oct 26 at 11:59pm
Midterm 2
- Take-home posted Monday Oct 26
- In-class exam Monday Nov 2
Agenda
- This week: Opimization in multiple dimensions
- Next week: Advanced optimization, combinatoric optimization,
machine learning
Today
Optimization in multiple dimensions
- Linear regression as an optimization problem
- Energy landscapes in two dimensions
- Four-bead protein folding model + AI demo
- Gradient descent optimization
Optimization in Multiple Dimensions
Last time: optimizing a single variable
- Three-bead protein: one angle
- Objective: minimize the energy
- Methods: bisection, Newton–Raphson, golden-section search
Today: what if the protein can bend at two
joints
?
The multidimensional optimization problem
We choose a vector of adjustable parameters:
and try to minimize the objective function:
- One parameter: a curve
- Two parameters: a surface
- Many parameters: a high-dimensional landscape
(hypersurface)
Reading a two-dimensional energy landscape
Source: generated with ChatGPT
- Valleys = low energy; hills = high
energy
- Contour lines connect points with equal energy
- A local minimum may not be the
global minimum
Example 1: Fitting Data
Linear regression as an optimization problem
Suppose we have
fixed datapoints
and want to fit a line:
Adjustable parameters:
= (slope, offset)

Linear regression as an optimization problem
Suppose we have
fixed datapoints
and want to fit a line:
Adjustable parameters:
= (slope, offset)
Objective function: sum of squared residuals
Goal: Find
that minimize
.

The Loss Landscape (objective function)
Every choice of
corresponds to a point in the parameter space, with an
associated cost
.
Demo: python linear_fit_gui.py
Next: What happens when the landscape has multiple
valleys?
Example 2: Protein Folding
Previously: Three beads, one angle
Source: generated with ChatGPT
Four beads, three links, two angles
Source: generated with ChatGPT
Three rigid links, two independent bending
angles:
- Bending costs energy
- Non-neighboring beads attract
- The fold is now a point in a 2D parameter space
Objective function: folding energy
Fixed parameters:
- :
bending stiffness
- :
attractive interaction strength
- :
preferred separation
- :
interaction range
Source: generated with ChatGPT
Adjustable parameters:
The distances
are trig functions depending on
AI Demo: translate physics into Python
Prompt a local model to generate:
bead_positions(theta1, theta2, a)
energy(theta1, theta2, a, kappa, epsilon, r0, sigma)
Specify the conventions:
- Bead 1 at
;
first link along
- Subsequent link directions:
,
,
- Attraction pairs:
,
,
- Angles in radians
energy function should be “vectorized” (i.e. allow
to be arrays)
AI coding: test before trusting
Check geometry:
- At
:
beads at
- Folding energy should agree with the displayed formula
Check numerically:
p = bead_positions(0, 0, 1.0)
assert np.allclose(p, [[0,0], [1,0], [2,0], [3,0]])
assert np.isfinite(energy(0., 0., 1., 1., 3., 1., .2))
Takeaway: AI can implement our physical model;
we specify and validate it.
Exploring the folding landscape
Demo: folding_2d.py
- Move the red marker: how does the chain fold?
- Find a low-energy region: what does the chain look like?
- Compare two distinct valleys: which fold has lower energy?
- Change
or
:
how does the landscape change?
Contrast with linear regression: this energy
landscape can have several minima.
Challenge: How can a computer automatically
find the valleys?
Gradient-Based Optimization
The gradient: which way is uphill?
For
,
define the gradient:
-
points uphill (steepest local increase)
-
points downhill (steepest local decrease)
- At a local minimum
(but so do maxima and saddle points!)
Source: generated with ChatGPT
Gradient descent is an iterated map
Start with
,
then repeatedly step downhill:
- :
learning rate (step size)
- Evaluate gradient
step downhill
repeat
- Stop when energy / parameters stop changing appreciably
This is an iterated map, just like our earlier
dynamical-systems examples.
Gradient descent in Python
Start with
,
then repeatedly step downhill:
import numpy as np
# grad_energy(theta) takes a length-2 array and returns the gradient (also length-2)
theta = np.array([1.0, -2.0]) # initial guess (radians)
eta = 0.05 # learning rate
tol = 1e-6 # convergence tolerance
max_steps = 1e4 # maximum number of steps
grad = grad_energy(theta)
step = 0
while (np.linalg.norm(grad) > tol) & (step < max_steps):
theta -= eta * grad
grad = grad_energy(theta)
step = step + 1
In practice:
may be derived analytically or approximated using finite
differences.
Demo: learning rate and starting guess
Demo: folding_gradient_descent.py
Source: generated with ChatGPT
- Small
:
safe, but slow
- Large
:
overshooting, oscillations, or divergence
- Different initial guesses: may converge to
different minima
Question: How can we be confident we found the
global minimum?
Pitfalls and Takeaways
Common optimization traps
- Local
global minima: following downhill is not enough: a low valley
may not be the lowest valley
- Initial guesses: different
lead to different minima
- Step size: a poor choice can cause either slow or
unstable convergence
- Coarse grids: may completely miss a narrow
valley
- Dimensionality:
grid samples per coordinate require
evaluations!
Practical strategy: run the optimizer from
many starting configurations.
Takeaways
The goal: minimize
in a space with many possible configurations.
- Visualize the landscape when you can
- Use gradient descent to move downhill
systematically
- A converged answer is not necessarily the global
minimum
AI-generated models and code
- Prompts should be exhaustive and specific
- Validate AI-generated numerical models against physical checks
Next time:
- What if we don’t have access to the gradient
?
- Deliberately move uphill to escape a local minimum?