Introduction to Derivatives — Instantaneous Rate of Change and Tangent
Introduction to Derivatives -- Instantaneous Rate of Change and Tangent
Derivative = Instantaneous rate of change of a function at a certain point = Slope of the tangent line at that point.
Understanding the derivative means understanding why gradient descent moves in the opposite direction.
From Average Rate of Change to Instantaneous Rate of Change
Average Rate of Change (Secant Slope) $\rightarrow$ $\Delta x$ gets smaller $\rightarrow$ Secant line becomes tangent line $\rightarrow$ Derivative = Tangent line slope.
The derivative sign reveals the function's behavior
**
f'(x) > 0
The function is increasing here
The tangent slopes upwards to the right
**
f'(x) < 0
The function is decreasing here
The tangent slopes downwards to the right
**
f'(x) = 0
Horizontal—possibly an extremum
Tangent is horizontal
The intuition of gradient descent is hidden in the derivative sign:
f'(x) > 0 → function is increasing → move in the opposite direction. f'(x) < 0 → function is decreasing → continue in this direction.
This is the origin of the "negative gradient direction."
Real-life example
**Speedometer = Derivative of the position function
Driving 120 kilometers in total for 2 hours $\rightarrow$ Average speed of 60 km/h.
But the instantaneous speed on the dashboard is constantly changing. This "instantaneous speed" is the derivative of the distance function with respect to time.
Mathematical definition
[ f'(x) = \lim_{\Delta x \to 0} \frac{f(x + \Delta x) - f(x)}{\Delta x} ]
If this limit exists, f is differentiable at x.
Python hands-on practice
Example
import
numpy
as
np
def
numerical_derivative
(
f
,
x
,
h
=
1e-5
)
:
return
(
f
(
x + h
)
- f
(
x - h
)
)
/
(
2
- h
)
f
=
lambda
x: x**
2
f'(2) = 2*2 = 4
(
f
"f'(2) Numerical={numerical_derivative(f, 2):.6f}, Theoretical=4"
)
Derivative at each point
for
x
in
[
2
,
1
,
0
,
1
,
2
]
:
d
=
numerical_derivative
(
f
,
x
)
dir
=
"descending"
if
d
<
0
else
(
"Ascending"
if
d
0
else
"Horizontal"
)
print
(
f"x={x:2d}, f'(x)={d:5.1f}, {dir}"
)
Original prompt (Chinese, left untranslated)
f'(2) 数值=4.000000, 理论=4
x=-2, f'(x)= -4.0, 下降
x=-1, f'(x)= -2.0, 下降
x= 0, f'(x)= 0.0, 水平
x= 1, f'(x)= 2.0, 上升
x= 2, f'(x)= 4.0, 上升
Application scenarios in AI
One-dimensional prototype of gradient descent
For a single-variable function, gradient descent degenerates to ( x_{new} = x_{old} - \eta \cdot f'(x_{old}) ). The derivative tells you "which way to go for the function value to decrease"—a positive derivative means moving left, and a negative derivative means moving right.
The derivative of the activation function determines the efficiency of backpropagation
The derivative of ReLU: 1 when x>0, and 0 when x<=0. It is extremely fast to compute, and the gradient does not decay in the positive half-region—this is the key reason why ReLU is more suitable for deep neural networks than Sigmoid. The maximum derivative of Sigmoid is only 0.25, and after multiplication across multiple layers, the gradient decays exponentially (vanishing gradient).
The derivative of the loss function at the optimal solution is zero.
When the model converges to a local optimum, the partial derivatives of the loss function with respect to all parameters approach 0—gradient descent naturally stops. This is a signal of training convergence: the gradient norm ||\nabla J|| \approx 0.