Derivatives and local approximation
导数与局部近似
Predict how a small parameter change affects an output, and distinguish local slope, numerical approximation, and an optimum.
derivativesPredict a small change first
Consider the invented cost function . At , its value is 3. Increasing the parameter by 0.1 gives 3.21, an average rate of change of . Increasing it by only 0.01 gives an average rate of 2.01.
As the step shrinks, the ratio approaches 2, describing local sensitivity near 4. It does not promise that every later increase of 1 will raise the cost by 2. A derivative is local information and must be reevaluated as the operating point changes.
State the limit of the difference quotient
A real function is differentiable at when the following finite limit exists:
The difference quotient uses two points; the derivative describes their limit as the points approach one another. An ordinary two-sided derivative requires matching left and right limits. Domain boundaries need an explicit convention if a one-sided derivative is intended. D2L, Section 2.4.1
Expanding this article’s function derives the answer without memorizing a differentiation table:
Differentiability also describes a local linear approximation:
The remainder vanishes faster than the first-order step. For this quadratic it is exactly . At , the approximation gives 3.2 and the exact value is 3.21, leaving error 0.01. MML, Section 5.1
This expression also shows that differentiability implies continuity: the function increment consists of vanishing first-order and remainder terms. The converse fails. At zero, is continuous but has right difference quotient 1 and left quotient -1, so no common two-sided derivative exists.
Derivatives have units. With seconds as input and meters as output, the derivative is measured in meters per second. Expressing the input in milliseconds changes its numerical value. Similar scale choices affect optimization step sizes.
What can finite differences check?
This complete Python example compares forward differences, central differences, and the analytical derivative. Steps must be finite and positive; the function must also be defined at the points being evaluated.
import math
def central_difference(f, x, h):
if not math.isfinite(h) or h <= 0:
raise ValueError("step must be finite and positive")
return (f(x + h) - f(x - h)) / (2 * h)
f = lambda x: (x - 3) ** 2 + 2
for h in [0.1, 0.01, 0.001]:
forward = (f(4 + h) - f(4)) / h
assert abs(forward - (2 + h)) < 1e-9
assert abs(central_difference(f, 4, 1e-5) - 2) < 1e-8
assert abs(f(4.1) - (f(4) + 2 * 0.1) - 0.01) < 1e-12
assert central_difference(abs, 0, 0.001) == 0
assert 4.0 + 1e-20 == 4.0
assert central_difference(f, 4.0, 1e-20) == 0
Central differences require two function evaluations. If one costs , the principal work is approximately two evaluations at that cost. For sufficiently smooth functions, central-difference truncation error is typically , but rounding error does not keep decreasing with . The final two assertions show that a step below floating-point resolution can produce a false zero.
Zero derivatives and nondifferentiable points
The central difference of at zero returns 0 without proving differentiability. Symmetric sampling cancels the opposing changes, while the definition requires consistent two-sided quotients. Numerical checks support mathematical and program analysis; they do not replace it.
A zero derivative is not automatically a minimum. The derivative of at zero vanishes, yet neighboring values are both smaller and larger. A differentiable unconstrained interior local minimum requires a zero derivative, a necessary condition that is generally not sufficient.
Measurement noise, discrete outputs, and parameter thresholds can make finite differences unreliable. Training commonly uses smooth or piecewise-differentiable losses to supply useful gradients; these need not equal the final reported task accuracy. Decreasing a training objective and improving unseen-data performance are also different claims.
Is the local information sufficient?
- What is this function’s derivative at ? Answer: -2. A sufficiently small positive change in lowers the cost.
- Use the linear approximation at to predict . Answer: 3.02, compared with the exact 3.0201.
- Why not shrink a difference step indefinitely? Answer: perturbed inputs can round to the same value, and subtracting nearby outputs can amplify relative error.
- Can a nondifferentiable point be a minimum? Answer: yes. attains its minimum at its nondifferentiable origin; nonsmooth analysis supplies appropriate tools.
Which rate of change does training need?
Multiple parameters require partial derivatives and gradients, composed computations require the chain rule, and automatic differentiation applies local derivative rules to programs. Gradient descent uses them to choose update directions. Preserve the distinctions established here: derivatives are local, numerical implementations have error, and an optimization objective must be connected to the real task.
Make a prediction, then check
A central difference for |x| at zero returns zero. Does that prove differentiability there?
Learning objectives
- Derive a simple function’s local rate of change from a difference-quotient limit.
- Distinguish derivatives, finite differences, and optimality conditions; identify kinks and floating-point cancellation.
Prerequisites & connections
This article can be used as an entry point.
Explore related knowledge →References
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020 - Dive into Deep Learning — Calculus
Aston Zhang; Zachary C. Lipton; Mu Li; Alexander J. Smola · 2023
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: cited-source comparison, re-derivation and recalculation, bilingual argument comparison, and executed Python assertions; no independent human peer review.
- Re-derived 2(x−3) by expansion and checked 3.21/3.2 and 3.0201/3.02; ran forward, central, and sub-resolution finite-difference examples.
- Checked two-sided limits, differentiability implying continuity, the |x| kink, and the stationary point of x³; distinguished necessary and sufficient conditions.
- Compared arguments, numbers, examples, limitations, and exercise answers across languages; structural validation separately compares display formulas, code, sources, and sections. No independent human peer review.
Source locations checked:
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft) · §5.1, PDF p. 147 onward: limits and local approximation
- Dive into Deep Learning — Calculus · §2.4.1: derivatives and difference quotients
Related topics