1.2.9Calculus & Optimization Basics

Local vs global minima - maxima

2,552 words12 min readdifficulty · medium1 backlinks

Overview

Understanding the difference between local and global extrema is critical in machine learning because gradient descent and other optimization algorithms can get trapped in local minima, preventing us from finding the best possible solution. This concept explains why neural network training is hard and why we need techniques like random restarts, momentum, and adaptive learning rates.

Figure — Local vs global minima - maxima

Core Concepts


First-Principles Derivation

How Do We Identify Extrema?

Step 1: Necessary Condition (Critical Points)

At any local extremum, if ff is differentiable, the gradient must vanish:

f(x)=0\nabla f(\mathbf{x}^*) = \mathbf{0}

Why? Suppose x\mathbf{x}^* is a local minimum but f(x)0\nabla f(\mathbf{x}^*) \neq \mathbf{0}. Then there exists a direction d=f(x)\mathbf{d} = -\nabla f(\mathbf{x}^*) where ff decreases (by definition of gradient). Moving slightly in that direction: x+ϵd\mathbf{x}^* + \epsilon \mathbf{d} gives f(x+ϵd)<f(x)f(\mathbf{x}^* + \epsilon \mathbf{d}) < f(\mathbf{x}^*) for small ϵ>0\epsilon > 0, contradicting that x\mathbf{x}^* is a minimum.

But: f=0\nabla f = \mathbf{0} is necessary but not sufficient. Critical points can be minima, maxima, or saddle points.


Step 2: Second-Order Condition (Classifying Critical Points)

For a function f:RnRf: \mathbb{R}^n \to \mathbb{R}, compute the Hessian matrix:

Hij=2fxixjH_{ij} = \frac{\partial^2 f}{\partial x_i \partial x_j}

At a critical point x\mathbf{x}^*:

  • Local minimum: HH is positive definite (all eigenvalues >0> 0)
  • Local maximum: HH is negative definite (all eigenvalues <0< 0)
  • Saddle point: HH has mixed-sign eigenvalues

Why does this work? The second-order Taylor expansion near x\mathbf{x}^* is:

f(x+h)f(x)+f(x)Th+12hTHhf(\mathbf{x}^* + \mathbf{h}) \approx f(\mathbf{x}^*) + \nabla f(\mathbf{x}^*)^T \mathbf{h} + \frac{1}{2} \mathbf{h}^T H \mathbf{h}

Since f(x)=0\nabla f(\mathbf{x}^*) = \mathbf{0}:

f(x+h)f(x)12hTHhf(\mathbf{x}^* + \mathbf{h}) - f(\mathbf{x}^*) \approx \frac{1}{2} \mathbf{h}^T H \mathbf{h}

  • If HH positive definite: hTHh>0\mathbf{h}^T H \mathbf{h} > 0 for all h0\mathbf{h} \neq \mathbf{0} → function increases in all directions → local min
  • If HH negative definite: opposite → local max
  • If mixed eigenvalues: increases in some directions, decreases in others → sadle

Step 3: Distinguishing Local from Global

There's no local test for global optimality. You must:

  1. Find all critical points
  2. Evaluate ff at each
  3. Check boundaries (if domain is bounded)
  4. Compare all values—the smallest is the global minimum

Why is this hard in ML? Neural networks have millions of parameters, making exhaustive search impossible. We rely on optimization algorithms and empirical tricks.


Worked Examples


Common Mistakes


Connections to Machine Learning

Gradient Descent Convergence:

  • Vanilla gradient descent with small learning rate converges to a local minimum (or saddle point)
  • No guarantee of finding the global minimum in non-convex problems
  • Links to: Gradient Descent, Learning Rate Tuning

Optimization Algorithms:

  • Momentum helps escape shallow local minima by accumulating velocity
  • Simulated anealing and genetic algorithms use randomness to explore the landscape
  • Adam optimizer adapts learning rates per parameter
  • Links to: Momentum and Nesterov, Adam Optimizer

Loss Surface Geometry:

  • High-dimensional spaces have exponentially many sadle points
  • Mode connectivity: different local minima often lie on connected low-loss paths
  • Links to: Loss Landscape Visualization, Neural Network Optimization

Regularization Effects:

  • L2 regularization modifies the loss landscape to be "smother"
  • Can turn sharp local minima into broader basins, aiding generalization
  • Links to: Regularization Techniques, Generalization in Deep Learning

Active Recall Practice

Recall Explain to a 12-Year-Old (Feynman Technique)

Imagine you're playing a video game where you're blindfolded and trying to find the lowest point in a huge park with hills and valleys. You can only feel if the ground is sloping up or down under your feet.

A local minimum is like finding a small dip—maybe a pudle. If you take any step from that pudle, you go uphill, so it feels like the lowest point. But there might be a huge lake on the other side of the park that's way lower—that's the global minimum.

In machine learning, the "park" is all the possible ways to set your AI's brain (the numbers in the neural network). The "height" is how many mistakes the AI makes. We want the lowest point (fewest mistakes), but our algorithm (like taking downhill steps) might get stuck in a pudle instead of finding the lake.

That's why training AI is tricky—we need clever tricks to help it explore more of the park, not just settle for the first low spot it finds!

Think: "When building with LEGOs, you might make a small tower (local max) but miss that you could build a huge castle (global max) if you explored more pieces."


Flashcards

#flashcards/ai-ml

What is a local minimum? :: A point where the function value is lower than all nearby points within some neighborhood, but not necessarily the lowest point overall.

What is a global minimum?
The point where the function achieves its absolute lowest value across the entire domain.
What is the necessary condition for a point to be a local extremum?
The gradient must be zero: f(x)=0\nabla f(\mathbf{x}^*) = \mathbf{0} (making it a critical point).
How do you use the Hessian to classify a critical point?
Check eigenvalues—positive definite (all positive) means local min, negative definite means local max, mixed signs mean saddle point.
Why can gradient descent get stuck in local minima?
It only takes downhill steps based on local gradient information, so it converges to the first local minimum it encounters without exploring the full landscape.
Is every local minimum also a global minimum?
No—only in convex functions. In non-convex functions (like neural networks), local minima can have higher values than the global minimum.
Can a local extremum also be a global extremum?
Yes—an interior local extremum can coincide with the global extremum, and global extrema need not be unique (they can be achieved at multiple points, e.g. an interior point and an endpoint).
What is a saddle point?
A critical point where the Hessian has both positive and negative eigenvalues—the function decreases in some directions and increases in others, so it's neither a min nor max.
Why are saddle points common in high-dimensional optimization?
In high dimensions, the chance that all eigenvalues have the same sign (all positive or all negative) decreases exponentially, making saddle points more likely than local minima.

Concept Map

shape defines

shape defines

always also a

walks downhill on

can get trapped in

helps escape

converges to

found where

classified by

positive definite means

indicates

negative definite means

indicates

Local minimum

Global minimum

Loss landscape

Gradient descent

Critical points

Hessian matrix

Positive definite

Negative definite

Random restarts momentum

Gradient equals zero

Local maximum

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, jab bhi hum machine learning model train karte hain, toh ek "loss function" hota hai jo bata hai ki model kitna galat hai. Optimization ka matlab hai us loss ko kam karna—minimum dhoondhna. Lekin problem yeh hai ki local minimum aur global minimum mein fark hota hai.

Local minimum ek aisa point hai jahan loss apne as-pas ke points se kam hai, matlabagar thoda left ya right jao toh loss badhta hai. Lekin pore landscape mein dekhoge toh kahin aur ek aur bhi neeche point mil sakta hai—woh global minimum hai. Jaise ek gaon mein sabse neechi jagah ek kuan ho, lekin pore district mein ek gehri nadi ho—woh nadi global minimum hai.

Gradient descent jaisa algorithm sirf neeche ki taraf steps leta hai.Agar woh ek chhote kuan mein fas gaya, toh woh wahi ruk jayega, chahe gehri nadi kahi aur ho. Isliye deep learning mein hum momentum, adaptive learning rates, ya multiple random starts use karte hain taki algorithm landscape explore kar sake aur ek acha minimum dhundh sake. Non-convex functions (jaise neural networks) mein yeh problem bohot zyada hoti hai kyunki bahut sare local minima hote hain. Samajhna zaroori hai ki har critical point (jahan gradient zero ho) minimum nahi hota—woh sadle point bhi ho sakta hai, jahan kuch directions

Go deeper — visual, from zero

Test yourself — Calculus & Optimization Basics

Connections