Partial Derivative

Formal

The generalization of Univariate Calculus Refresher to functions of several variables is the gradient.

(Partial Derivative)

For a function f:RnR,xf(x),xRnf:\mathbb{R}^n \rightarrow \mathbb{R}, x \mapsto f(x), x \in \mathbb{R}^n of nn variables x1,,xnx_1, \dots, x_{n} we define partial derivative as

fx1=limh0f(x1+h,,xn)f(x)h fxn=limh0f(x1,,xn+h)f(x)h(1)\begin{align} \frac{\partial f}{\partial x_{1}} &= \lim_{ h \to 0 } \frac{f(x_{1}+h,\dots,x_{n})-f(x)}{h} \\ &\ \vdots \\ \frac{\partial f}{\partial x_{n}} &= \lim_{ h \to 0 } \frac{f(x_{1},\dots,x_{n}+h)-f(x)}{h} \end{align} \tag{1}

and collect them in a row vector

xf=gradf=dfdx=[fx1fx2fxn]R1×n,(2)\nabla_{x} f = \text{grad}f = \frac{df}{dx} =\begin{bmatrix} \dfrac{\partial f}{\partial x_{1}} \dfrac{\partial f}{\partial x_{2}}\dots \dfrac{\partial f}{\partial x_{n}} \end{bmatrix} \in \mathbb{R}^{1 \times n}, \tag {2}

where nn is the number of variables and 11 is the dimension of the image/range/codomain of ff.

Rules of Partial Differentiation
  • Product Rule:
x(f(x)g(x))=fxg(x)+f(x)gx(3)\frac{\partial}{\partial x}(f(x)g(x)) = \frac{\partial f}{\partial x}g(x)+f(x) \frac{\partial g}{\partial x} \tag{3}
  • Sum Rule:
x(f(x)+g(x))=fx+gx(4)\frac{\partial}{\partial x}(f(x)+g(x)) = \frac{\partial f}{\partial x} + \frac{\partial g}{ \partial x} \tag{4}
  • Chain Rule:
x(gf)(x)=x(g(f(x)))=gffx(5)\frac{\partial}{\partial x}(g \circ f)(x) = \frac{\partial}{\partial x}(g(f(x))) = \frac{\partial g}{\partial f} \frac{\partial f}{\partial x} \tag{5}
Intuition
Chain Rule

Think of it as a dependency graph for rates of change. Imagine a simple computation graph like the one in Figure 5.10 from the text: an input xx produces an intermediate value aa, which produces bb, which finally produces an output yy. xabyx \rightarrow a \rightarrow b \rightarrow y. The chain rule answers the question: “If I slightly nudge the input xx, how much does the final output yy change?” It tells us that the total change in yy with respect to xx is the product of the rates of change at each step along the path.

dydx=change in ychange in b×change in bchange in a×change in achange in x\begin{align} \dfrac{dy}{dx} = \dfrac{\text{change in y}}{\text{change in b}} \times \dfrac{\text{change in b}}{\text{change in a}} \times \dfrac{\text{change in a}}{\text{change in x}} \end{align}

If ff is a function in two variables x1,x2x_{1}, x_{2} which in turn are functions of tt, then the gradient of ff w.r.t. tt is

dfdt=[fx1fx2][x1(t)tx2(t)t]=fx1x1t+fx2x2t,(6)\frac{df}{dt} = \begin{bmatrix} \dfrac{\partial f}{\partial x_{1}} & \dfrac{\partial f}{\partial x_{2}} \end{bmatrix} \begin{bmatrix} \dfrac{\partial x_{1}(t)}{\partial t} \\ \dfrac{\partial x_{2}(t)}{\partial t} \end{bmatrix}=\dfrac{\partial f}{\partial x_{1}}\dfrac{\partial x_{1}}{\partial t} + \dfrac{\partial f}{\partial x_{2}}\dfrac{\partial x_{2}}{\partial t}, \tag{6}
ML Applications

Connection to Backpropagation: A deep neural network is a deeply nested composite function, y=(fKfK1f1)(x)y=(f_K\circ f_{K−1}\circ \dots\circ f_1)(x). To train the network, we minimize a loss function LL that depends on the final output. This requires computing the gradient of the loss with respect to the parameters θi\theta_i of each function (layer) fif_i.

Connections
  • #vector-calculus
  • #type/definition
  • #jacobian
  • #gradient