liveBook · Manning

Chain rule

As explained in Deep Learning with R, Third Edition

The chain rule is a calculus rule for differentiating a composition of functions by multiplying derivatives of the component functions.

The chain rule differentiates a composition of functions by multiplying the derivatives of its component operations. In neural networks, it turns the derivatives of simple operations such as addition, ReLU, tensor products, softmax, and loss functions into gradients for complex models. section 2.4.4

From a two-layer network to backpropagation

A two-layer network applies matrix multiplication, addition, ReLU, another matrix multiplication, addition, softmax, and a loss function. The chain rule passes the loss gradient backward through these operations, multiplying local derivatives along the path to each weight. This procedure is called backpropagation and supplies the gradients used to update the model. section 2.4.4 section 2.5

fg <- function(x) {
  x1 <- g(x)
  y <- f(x1)
  y
}

Trace a composition explicitly by naming the intermediate value before applying the next function. section 2.4.4

fghj <- function(x) {
  x1 <- j(x)
  x2 <- h(x1)
  x3 <- g(x2)
  y <- f(x3)
  y
}

grad(y, x) == (grad(y, x3) * grad(x3, x2) * grad(x2, x1) * grad(x1, x))

Extend the two-function pattern to a longer chain and read the gradient as a product of derivatives through successive intermediate values. section 2.4.4

Computation graphs make the chain visible: a forward pass computes the output, while a backward pass follows paths from the loss to the parameters. Mini-batch gradient descent then uses those gradients to move weights toward lower loss. section 2.4.4 section 2.6

How Deep Learning with R, Third Edition covers it

How deep it goes
Works from function composition through computation graphs and backward passes, without developing a formal calculus derivation.
Examples
Uses a two-layer network, chained tensor operations, and MNIST digit classification with Keras training.
What you can do after
Evaluate how backpropagation derives gradients and supports weight updates during neural-network training.
How it connects
Links differentiation with backpropagation, computation graphs, loss functions, optimizers, and mini-batch stochastic gradient descent.

Also explained in

Compare how 4 books explain chain rule →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.