Deep Learning · TEE · section

Derivatives without a calculus course

The maths behind a network

Definition. A derivative measures the local rate of change of a function. A partial derivative varies one argument while holding the others fixed. The gradient of a scalar-valued function collects its partial derivatives into a vector.

\nabla_\theta J=\begin{bmatrix}\partial J/\partial\theta_1\\\vdots\\\partial J/\partial\theta_d\end{bmatrix}LaTeX: \nabla_\theta J=\begin{bmatrix}\partial J/\partial\theta_1\\\vdots\\\partial J/\partial\theta_d\end{bmatrix}

The rules needed for the supplied neural-network numericals are:

Function or operationDerivative
Constant c0
xⁿnxⁿ⁻¹
c f(x)c f′(x)
f(x) + g(x)f′(x) + g′(x)
f(x)g(x)f′(x)g(x) + f(x)g′(x)
eˣeˣ
ln x, x > 01/x
f(g(x))f′(g(x))g′(x)

A parameter derivative is not an input derivative

For z = wx + b, the variable named in the denominator determines which derivative is required.

\frac{\partial z}{\partial w}=x,\qquad\frac{\partial z}{\partial x}=w,\qquad\frac{\partial z}{\partial b}=1LaTeX: \frac{\partial z}{\partial w}=x,\qquad\frac{\partial z}{\partial x}=w,\qquad\frac{\partial z}{\partial b}=1

At x = 2, w = 3 and b = 1, z = 7, but the three derivatives are 2, 3 and 1 respectively. A function value and its derivative are distinct quantities.

Gradient direction

For a small parameter displacement Δθ, first-order Taylor expansion gives:

J(\theta+\Delta\theta)\approx J(\theta)+\nabla J(\theta)^T\Delta\thetaLaTeX: J(\theta+\Delta\theta)\approx J(\theta)+\nabla J(\theta)^T\Delta\theta

The gradient points in the direction of greatest local increase under the Euclidean norm. Choosing Δθ opposite to the gradient gives a local descent direction. This is the mathematical basis of gradient descent; a finite step can still overshoot if the learning rate is too large.

Differentiate before substituting: 3w^2+5

Question. Let J(w) = 3w^2+5. At w = 2, find J and dJ/dw.

Given

J(w) = 3w^2+5; w = 2.

To find

The function value and its derivative value.

Formula — which one and why

The power rule brings the exponent down as a multiplier and reduces its power by one. An added constant has derivative zero.

c is the coefficient; n is the power; k is an added constant. J and dJ/dw are different quantities.

\frac{d(cw^n+k)}{dw}=cnw^{n-1}LaTeX: \frac{d(cw^n+k)}{dw}=cnw^{n-1}

Yaad rakhne ka cue: Power neeche multiply; exponent ek kam; constant ka zero.

Solution — step by step

Step 1: evaluate the function itself.

J(2)=3(2)^2+5=17LaTeX: J(2)=3(2)^2+5=17

Step 2: differentiate symbolically.

J\prime(w)=3(2)w^{2-1}+0LaTeX: J\prime(w)=3(2)w^{2-1}+0

Step 3: put the given w into the derivative.

J\prime(2)=3(2)(2)^{1}=12LaTeX: J\prime(2)=3(2)(2)^{1}=12

Final answer: J = 17; derivative = 12.

Differentiate before substituting: 0.7w^3+0

Question. Let J(w) = 0.7w^3+0. At w = 1, find J and dJ/dw.

Given

J(w) = 0.7w^3+0; w = 1.

To find

The function value and its derivative value.

Formula — which one and why

The power rule brings the exponent down as a multiplier and reduces its power by one. An added constant has derivative zero.

c is the coefficient; n is the power; k is an added constant. J and dJ/dw are different quantities.

\frac{d(cw^n+k)}{dw}=cnw^{n-1}LaTeX: \frac{d(cw^n+k)}{dw}=cnw^{n-1}

Yaad rakhne ka cue: Power neeche multiply; exponent ek kam; constant ka zero.

Solution — step by step

Step 1: evaluate the function itself.

J(1)=0.7(1)^3+0=0.7LaTeX: J(1)=0.7(1)^3+0=0.7

Step 2: differentiate symbolically.

J\prime(w)=0.7(3)w^{3-1}+0LaTeX: J\prime(w)=0.7(3)w^{3-1}+0

Step 3: put the given w into the derivative.

J\prime(1)=0.7(3)(1)^{2}=2.1LaTeX: J\prime(1)=0.7(3)(1)^{2}=2.1

Final answer: J = 0.7; derivative = 2.1.

Differentiate before substituting: 2w^1+4

Question. Let J(w) = 2w^1+4. At w = -1, find J and dJ/dw.

Given

J(w) = 2w^1+4; w = -1.

To find

The function value and its derivative value.

Formula — which one and why

The power rule brings the exponent down as a multiplier and reduces its power by one. An added constant has derivative zero.

c is the coefficient; n is the power; k is an added constant. J and dJ/dw are different quantities.

\frac{d(cw^n+k)}{dw}=cnw^{n-1}LaTeX: \frac{d(cw^n+k)}{dw}=cnw^{n-1}

Yaad rakhne ka cue: Power neeche multiply; exponent ek kam; constant ka zero.

Solution — step by step

Step 1: evaluate the function itself.

J(-1)=2(-1)^1+4=2LaTeX: J(-1)=2(-1)^1+4=2

Step 2: differentiate symbolically.

J\prime(w)=2(1)w^{1-1}+0LaTeX: J\prime(w)=2(1)w^{1-1}+0

Step 3: put the given w into the derivative.

J\prime(-1)=2(1)(-1)^{0}=2LaTeX: J\prime(-1)=2(1)(-1)^{0}=2

Final answer: J = 2; derivative = 2.