A gradient is a vector of partial derivatives evaluated at a point in a multivariable function. Its direction indicates the function’s fastest local growth; optimization methods such as gradient descent follow its negative direction to reduce a cost function. section 16.3.1
Use the gradient in an iterative optimization step:
- Compute each partial derivative at the current point, one coordinate direction at a time. section 16.3.2
- Update each coordinate by moving opposite the gradient, scaled by a step-size parameter. section 16.3.1 section 16.3.2
- Stop when the derivatives are zero or sufficiently small, or when a maximum step count is reached. section 16.3.2
Finding a lower-cost position
Imagine nudging a marble through fog along a track whose height represents cost. At each position, the gradient indicates the steepest uphill direction; repeated short nudges in the opposite direction move toward a minimum. section 16.3 section 16.3.2
Listing 16.4 Method gradientDescent
function gradientDescent(f, P0, alpha, maxSteps) #1
for _ in {1..maxSteps} do #2
for i in {1.. |P0|} do #3
P[i] ← P0[i] – alpha * derivative(f, P0, i) #4
if P == P0 then #5
break
P0 ← P #6
return P0
Pseudocode makes the gradient-descent loop concrete: calculate derivatives, update coordinates, compare successive points, and enforce a step limit. section 16.3.2



















