Introduction to Calculus
While computers are discrete machines, the algorithms they run often solve continuous problems. Calculus is the language of optimization—the mathematical tool for finding the "best" value in a sea of possibilities.
1. Differential Calculus: Rates of Change
- The Derivative: Measures how a function changes as its input changes. In code, this represents the sensitivity of an output to an input.
- Chain Rule: The absolute MVP of Deep Learning. It allows us to calculate the derivative of a composite function, which is the mechanism behind Backpropagation in neural networks.
- Partial Derivatives: Necessary for functions with multiple inputs (most real-world software). It allows us to optimize one variable while holding others constant.
2. Optimization and Automatic Differentiation
How do we find the bottom of a "Loss Function"?
- The Gradient: A vector of partial derivatives pointing in the direction of the steepest ascent.
- Gradient Descent: The algorithm that trains almost all modern AI. By moving in the opposite direction of the gradient, we can minimize error.
- Automatic Differentiation (AutoDiff): The secret sauce of PyTorch and TensorFlow. Unlike numerical differentiation (approximation) or symbolic differentiation (formula manipulation), AutoDiff computes exact derivatives by traversing the computational graph of a program.
3. Taylor Series and Approximation
How do computers calculate $\sin(x)$ or $e^x$?
- Taylor Polynomials: Representing complex, non-linear functions as an infinite sum of polynomials.
- Approximation: In practice, we take the first few terms. This is foundational for Numerical Methods and physics engines where we need fast, "good enough" answers for complex curves.
4. Integral Calculus: Accumulation
- Integration: The inverse of differentiation, representing the "total" of a changing quantity.
- Probability Density Functions: Used to calculate the probability that a continuous variable falls within a certain range (the area under the curve).
- Work and Energy: Essential for Game Development and physics simulations (e.g., calculating the path of a projectile or the deformation of a mesh).
5. Vector Calculus: High-Dimensional Surfaces
- Jacobians and Hessians: High-dimensional versions of first and second derivatives.
- Curvature: The Hessian helps optimization algorithms understand the "shape" of the loss landscape, helping them avoid getting stuck in local minima or slowing down in "flat" regions.
The Discrete/Continuous Bridge
Calculus allows us to take continuous concepts (like a smooth error curve) and turn them into discrete steps that a computer can execute to "learn" from its mistakes. It is the core of the Learning Loop in modern intelligence.