liveBook · Manning

Gradient

As explained in Advanced Algorithms and Data Structures

A gradient is the vector of partial derivatives of a multivariable scalar function, indicating the direction of greatest local increase.

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

How Advanced Algorithms and Data Structures covers it

How deep it goes
Defines partial derivatives, geometric direction, coordinate updates, stopping conditions, and differentiability requirements without formal proofs.
Examples
Illustrates gradients with marble movement, one-variable curves, two-variable surfaces, and graph-drawing optimization.
What it assumes
Assumes a cost function and differentiability near evaluated points, while allowing numerical derivatives without prior calculus for application.
What you can do after
Apply it via gradient descent to iteratively seek low-cost solutions in differentiable optimization problems.
How it connects
Connects partial derivatives, gradient descent, cost functions, local minima, global minima, and supervised learning.

Also explained in

Compare how 20 books explain gradient →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Advanced Algorithms and Data Structures. The section links point to the parts of the book it draws on.