Introduction to Optimization Problems — Objective Function, Variables, and Constraints
Introduction to Optimization Problems -- Objective Function, Variables, and Constraints
Optimization is finding the parameters that minimize the objective function. AI training = optimizing the loss function.
Concept Analysis
Three Elements of an Optimization Problem
| Element | Meaning | Corresponding in AI Training |
|---|---|---|
| Objective function | Function to be minimized | Loss function J(θ) |
| Decision variables | Adjustable quantities | Model parameters θ |
| Constraints | Variable restrictions | Usually unconstrained |
Convex function vs Non-convex function
** Convex function
Bowl-shaped, any line connecting two points is above the curve
Local optimum = Global optimum
Such as the MSE loss in linear regression
** Non-convex function
Has multiple valleys and peaks
Only local optima can be found
Such as the loss function of deep neural networks
The loss function of deep neural networks is highly non-convex—but in practice, the local optima found by gradient descent are usually good enough.
Real-life example
**Choosing the shortest route
There are three routes from home to school: 5 minutes, 8 minutes, and 12 minutes.
Decision variable = which route to choose, objective function = time spent, goal = minimize time.
It's simple—just try all three paths. But AI models have millions of parameters, so it's impossible to enumerate all combinations.
That's why we need gradient descent—to step by step approach the optimal solution along the gradient direction.
Python hands-on practice
Example
import
numpy
as
np
Convex function f(x) = x^2, global optimum at x=0
Non-convex function f(x) = sin(x) + 0.1*x^2, has multiple local optima
def
f_convex
(
x
)
:
return
x**
2
def
f_nonconvex
(
x
)
:
return
np.
sin
(
x
)
0.1
x*
2
Gradient descent from different starting points (detailed in the next chapter); non-convex functions may converge to different local optima
(
"Non-convex functions may reach different local optima from different starting points"
)
(
"These are things to note when tuning deep learning"
)
Runtime output:
Original prompt (Chinese, left untranslated)
非凸函数从不同起点可能到达不同的局部最优
这是深度学习调参需要注意的
Convex function vs Non-convex function 3D comparison
The bottom-left figure is a convex function f(x,y)=x²+y² (bowl-shaped, unique global optimum), and the right figure is a non-convex function (multiple local optima).
Rotating the view can intuitively show the difference between "convex = single valley bottom" and "non-convex = multiple valley bottoms":
Application Scenarios in AI
The entire training process = large-scale optimization
Training a GPT-level model is about finding the optimum in a trillion-dimensional space. The loss function J(θ) is a hypersurface in this space, and gradient descent moves step-by-step down this surface. The entire training may last for weeks, consuming millions of dollars in computing power—just to find a set of parameters that minimizes the loss as much as possible.
Convex vs. Non-convex: Theory and Practice
The optimization problems for linear regression and SVM are convex—gradient descent guarantees finding the global optimum. However, the loss surface of deep neural networks is highly non-convex, with countless local optima and saddle points. In practice, the local optima found by SGD usually generalize well—large batches tend to converge to "sharp" local optima (poor generalization), while small batches tend to converge to "flat" local optima (good generalization).
Loss Landscape Visualization
Researchers found by projecting the high-dimensional loss surface onto 2D that the loss landscape of deep networks has a "valley" structure—even though it is non-convex, following the bottom of the valley almost always leads to a good solution. This explains why random initialization + SGD is so robust in deep learning.