Table of Contents#
- Introduction to Univariate Optimization
- Core Definitions: Local vs Global Optima 2.1 What is an Optimum? 2.2 Local Optimum 2.3 Global Optimum 2.4 Key Distinctions Between Local and Global Optima
- Visualizing Local and Global Optima: Univariate Examples 3.1 Example 1: Multiple Local Minima and One Global Minimum 3.2 Example 2: Convex Function (No Local Optima Other Than Global) 3.3 Example 3: Non-Convex Function with Plateaus and Saddle Points
- How Algorithms Differentiate Between Local and Global Optima 4.1 Local Search Algorithms 4.2 Global Search Algorithms 4.3 Hybrid Approaches
- Common Practices for Identifying and Navigating Optima 5.1 Checking Convexity: The Silver Bullet 5.2 Initialization Strategies for Local Search 5.3 Multiple Restarts to Mitigate Local Traps 5.4 Analyzing Function Behavior with Derivatives
- Best Practices for Real-World Univariate Optimization
- Case Study: Optimizing Manufacturing Costs
- Conclusion
- References
1. Introduction to Univariate Optimization#
Univariate optimization focuses on finding the input value ( x ) in a defined domain ( D ) that minimizes or maximizes a function ( f(x): \mathbb{R} \rightarrow \mathbb{R} ). Unlike multivariate optimization (which involves multiple variables), univariate problems are easier to visualize and analyze—making them an ideal foundation for understanding optimization principles.
The goal is to find:
- A minimum: ( f(x^*) \leq f(x) ) for all ( x \in D )
- A maximum: ( f(x^*) \geq f(x) ) for all ( x \in D )
However, not all minima or maxima are created equal. The critical divide is between local and global optima.
2. Core Definitions: Local vs Global Optima#
2.1 What is an Optimum?#
An optimum (plural: optima) is a point where the function reaches its highest (maximum) or lowest (minimum) value within some subset of its domain. For univariate functions, we can classify optima based on the size of that subset.
2.2 Local Optimum#
A point ( x^* ) is a local minimum if there exists a small neighborhood ( \epsilon > 0 ) such that: [ f(x^) \leq f(x) \quad \forall x \in (x^ - \epsilon, x^* + \epsilon) \cap D ]
Similarly, ( x^* ) is a local maximum if: [ f(x^) \geq f(x) \quad \forall x \in (x^ - \epsilon, x^* + \epsilon) \cap D ]
In plain terms: a local optimum is the best value within a small, immediate area. It’s the “peak” or “valley” you see when you’re standing right next to it—but there could be better peaks or valleys elsewhere.
2.3 Global Optimum#
A point ( x^* ) is a global minimum if: [ f(x^*) \leq f(x) \quad \forall x \in D ]
A global maximum follows the same logic: [ f(x^*) \geq f(x) \quad \forall x \in D ]
The global optimum is the absolute best value across the entire domain. There can be multiple global optima (e.g., a periodic function where every peak is the same height), but they all have the same function value.
2.4 Key Distinctions Between Local and Global Optima#
| Feature | Local Optimum | Global Optimum |
|---|---|---|
| Domain Scope | Limited to a small neighborhood | Entire function domain |
| Uniqueness | Can have multiple local optima | May have one or multiple (same value) |
| Algorithm Convergence | Local search algorithms (e.g., gradient descent) converge here | Requires global search or convexity guarantees |
| Convexity Context | Exists only in non-convex functions | Exists in both convex and non-convex functions |
3. Visualizing Local and Global Optima: Univariate Examples#
The best way to understand optima is to see them. Let’s explore three common univariate function types with visualizations (and Python code to reproduce them).
3.1 Example 1: Multiple Local Minima and One Global Minimum#
Consider the function: [ f(x) = x^4 - 4x^3 + 4x^2 + x - 1 ]
This non-convex function has:
- One global minimum at ( x \approx -0.107 ) (function value ≈ -1.06)
- One local maximum at ( x \approx 0.3 ) (function value ≈ -0.44)
- One local minimum at ( x \approx 2.6 ) (function value ≈ 4.03)
Python Code to Visualize:#
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import minimize, differential_evolution
def f(x):
return x**4 - 4*x**3 + 4*x**2 + x - 1
x = np.linspace(-0.5, 3.5, 1000)
y = f(x)
# Find local minima with BFGS
local_min1 = minimize(f, x0=0.0, method='BFGS')
local_min2 = minimize(f, x0=2.0, method='BFGS')
global_min = differential_evolution(f, bounds=[(-0.5, 3.5)])
plt.figure(figsize=(10,6))
plt.plot(x, y, label='$f(x) = x^4 -4x^3 +4x^2 +x -1$', color='blue')
plt.scatter(local_min1.x, local_min1.fun, color='red', marker='o', label=f'Local Min: x={local_min1.x[0]:.2f}, f(x)={local_min1.fun:.2f}')
plt.scatter(local_min2.x, local_min2.fun, color='green', marker='o', label=f'Local Min (trap): x={local_min2.x[0]:.2f}, f(x)={local_min2.fun:.2f}')
plt.scatter(global_min.x, global_min.fun, color='blue', marker='*', s=200, label=f'Global Min: x={global_min.x[0]:.2f}, f(x)={global_min.fun:.2f}')
plt.xlabel('x')
plt.ylabel('f(x)')
plt.title('Function with Multiple Local Minima')
plt.legend()
plt.grid(True)
plt.show()Output Insight: Local search starting at ( x=0.0 ) gets trapped in the local minimum, while starting at ( x=2.0 ) finds the global minimum. Global search (differential evolution) reliably finds the global minimum regardless of initialization.
3.2 Example 2: Convex Function (No Local Optima Other Than Global)#
A convex function satisfies ( f''(x) \geq 0 ) for all ( x ) in the domain. For such functions, every local minimum is also the global minimum.
Example function: [ f(x) = x^2 + 2x + 1 = (x+1)^2 ]
This function has only one global minimum at ( x=-1 ) (function value=0). Any local search algorithm will converge to this point, as there are no other optima to trap it.
3.3 Example 3: Non-Convex Function with Plateaus and Saddle Points#
Consider: [ f(x) = x^3 + \sin(2x) ]
This function has:
- Multiple local minima and maxima
- An inflection point at ( x=0 ) (where ( f'(0) = 2 \neq 0 ), so no stationary point)
- Plateaus in some regions where the function value changes very little, making optima hard to detect
Key Takeaway: Plateaus and saddle points can confuse algorithms, as they may appear to be optima but are not.
4. How Algorithms Differentiate Between Local and Global Optima#
Optimization algorithms can be broadly categorized into local and global search methods, each with different strengths in handling optima.
4.1 Local Search Algorithms#
Local search algorithms start at an initial point and iteratively move towards a better solution within the immediate neighborhood. They are fast but prone to getting stuck in local optima.
- Gradient Descent: Uses the first derivative to move towards the minimum. Works well for convex functions but traps in local minima for non-convex ones.
- Newton’s Method: Uses first and second derivatives to converge faster than gradient descent. Still a local search method—suffers from the same local optima issues.
- BFGS: A quasi-Newton method that approximates the second derivative. Faster than gradient descent for many non-convex functions but still local.
4.2 Global Search Algorithms#
Global search algorithms explore the entire domain (or large parts of it) to find the global optimum. They are slower but avoid local optima traps.
- Simulated Annealing: Inspired by metal annealing—starts with a high “temperature” (accepts worse solutions to explore) and cools down (focuses on local refinement).
- Genetic Algorithms: Uses selection, crossover, and mutation to evolve candidate solutions. Effective for non-convex functions with many local optima.
- Grid Search: Brute-force search over a grid of input values. Simple but only feasible for small domains.
- Differential Evolution: A population-based algorithm that mutates and combines solutions to explore the domain. Popular for univariate and multivariate non-convex problems.
4.3 Hybrid Approaches#
Hybrid methods combine local and global search to balance speed and accuracy:
- Use a global algorithm to identify promising regions of the domain.
- Apply a local search algorithm to refine the best candidates from the global search.
For example: Simulated annealing to explore the domain, then Newton’s method to fine-tune the best solution found.
5. Common Practices for Identifying and Navigating Optima#
5.1 Checking Convexity: The Silver Bullet#
If your function is convex, you don’t need to worry about local optima—any minimum found by a local search is the global minimum. For univariate functions, check if the second derivative is non-negative for all ( x ) in the domain: [ f''(x) \geq 0 \quad \forall x \in D ]
5.2 Initialization Strategies for Local Search#
Local search algorithms are sensitive to initial points. To avoid local optima:
- Random Initialization: Start at multiple random points in the domain.
- Domain Sampling: Initialize at evenly spaced points (e.g., grid-based) to cover the entire domain.
- Prior Knowledge: Use domain expertise to choose initial points near likely global optima (e.g., if minimizing manufacturing costs, start at typical production volumes).
5.3 Multiple Restarts to Mitigate Local Optima Traps#
Run your local search algorithm multiple times with different initial points. The best result across all runs is more likely to be the global optimum. This is a low-cost way to improve performance without switching to a full global algorithm.
5.4 Analyzing Function Behavior with Derivatives#
- First Derivative: At optima, ( f'(x) = 0 ). Use this to verify candidate points.
- Second Derivative: For a minimum, ( f''(x) > 0 ); for a maximum, ( f''(x) < 0 ); for saddle points, ( f''(x) = 0 ).
6. Best Practices for Real-World Univariate Optimization#
- Start with Convexity Analysis: If your function is convex, use a fast local search algorithm (e.g., gradient descent) for guaranteed global optima.
- Match Algorithm to Function Type:
- Convex: Gradient Descent, Newton’s Method.
- Non-Convex with Few Local Optima: Multiple Restart BFGS.
- Non-Convex with Many Local Optima: Differential Evolution, Simulated Annealing.
- Validate Optima: Always check the first and second derivatives at the candidate point to confirm it’s a true optimum (not a plateau or saddle point).
- Sensitivity Analysis: Evaluate how small changes in ( x ) affect ( f(x) ) around the optimum. This helps you understand how robust the solution is to real-world noise.
- Document Assumptions: If you assume convexity or use a local search, document these choices and their limitations (e.g., “Results may be a local minimum if the function is non-convex”).
7. Case Study: Optimizing Manufacturing Costs#
Scenario#
A factory wants to minimize the cost of producing a batch of parts. The cost function is: [ C(x) = 0.1x^4 - 2x^3 + 10x^2 + 50 ] Where ( x ) is the number of parts per batch (domain: ( 0 \leq x \leq 15 )).
Workflow#
- Check Convexity: Compute the second derivative: ( C''(x) = 1.2x^2 - 12x + 20 ). This is negative for ( x \in (2.1, 7.9) ), so the function is non-convex in this range.
- Local Search: Running BFGS with initial point ( x=3 ) converges to a local maximum at ( x=5 ) (cost ≈ $112.5).
- Global Search: Using differential evolution finds the global minimum at ( x=10 ) (cost ≈ $50).
- Validation: Check ( C'(10) = 0.4(10)^3 -6(10)^2 +20(10) = 400-600+200=0 ), and ( C''(10)=1.2(100)-12(10)+20=120-120+20=20>0 )—confirming it’s a minimum. Note that ( x=0 ) also yields ( C(0)=50 ), so the global minimum is attained at both endpoints ( x=0 ) and ( x=10 ).
Outcome#
Switching to batch sizes of 10 reduces costs by 60% compared to the local optimum of 5. This demonstrates the value of finding the global optimum.
8. Conclusion#
Local and global optima are fundamental concepts in univariate optimization. The key to success lies in:
- Understanding whether your function is convex (guaranteed global optima) or non-convex (risk of local traps).
- Choosing the right algorithm for the function type.
- Using initialization strategies and multiple restarts to mitigate local optima issues.
By following the practices outlined in this blog, you can confidently navigate univariate optimization problems and make decisions based on the best possible solutions—not just the nearest ones.
9. References#
- Boyd, S., & Vandenberghe, L. (2004). Convex Optimization. Cambridge University Press.
- Kirkpatrick, S., Gelatt, C. D., Jr., & Vecchi, M. P. (1983). Optimization by Simulated Annealing. Science.
- Goldberg, D. E. (1989). Genetic Algorithms in Search, Optimization, and Machine Learning. Addison-Wesley.
- SciPy Documentation: Optimization Module
- Wikipedia: Local Maximum and Minimum