Mathematical Optimization
Optimization is the selection of a best element (with regard to some criterion) from some set of available alternatives. In its simplest form, this means finding the values that maximize or minimize a function.
Unconstrained Optimization
For a differentiable function , local extrema occur at points where . The Second Derivative Test determines if a point is a maximum () or a minimum ().
python
1import numpy as np
2
3def f(x):
4 return x**4 - 4*x**2 + 3
5
6def df(x):
7 return 4*x**3 - 8*x
8
9def ddf(x):
10 return 12*x**2 - 8
11
12# Roots of df(x) are 0, sqrt(2), -sqrt(2)
13critical_points = [0, np.sqrt(2), -np.sqrt(2)]
14
15for p in critical_points:
16 second_der = ddf(p)
17 kind = "Min" if second_der > 0 else "Max"
18 print(f"Point x={p:.2f} is a {kind} (f''={second_der:.2f})")
Gradient Descent
In higher dimensions, we often use iterative methods like Gradient Descent to find a local minimum: where is the learning rate.
python
1def f(x, y):
2 return x**2 + y**2 + 10
3
4def grad_f(x, y):
5 return np.array([2*x, 2*y])
6
7point = np.array([5.0, 5.0])
8gamma = 0.1
9
10for _ in range(10):
11 point = point - gamma * grad_f(*point)
12 print(f"Current point: {point}")
If the gradient of a function at a point is (0,0,0), what can we conclude?
Constrained Optimization: Lagrange Multipliers
To optimize subject to , we look for points where the gradients are parallel: