Matrix calculus extends calculus to linear algebra, providing powerful tools for optimizing functions of multiple variables. It's essential in many fields including machine learning, physics, economics, and engineering.
The fundamental concept is differentiating matrix expressions with respect to scalars, vectors, or other matrices. This includes understanding how changes in input variables affect the output of matrix-valued functions.
Matrix calculus uses different notation conventions, which can sometimes lead to confusion. The two main conventions are:
Before diving into matrix calculus, it's essential to understand basic matrix operations:
For matrices A and B of the same dimensions:
For matrices A (mn) and B (np):
The transpose of an mn matrix A is an nm matrix denoted as A:
For a square matrix A, its inverse A satisfies:
where I is the identity matrix.
The trace of a square matrix A is the sum of its diagonal elements:
The determinant is a scalar value computed from a square matrix that provides important information about the matrix's properties.
The gradient of a scalar function f(x) with respect to a vector x = [x, x, ..., x] is:
The derivative of a vector function f() = [f(), f(), ..., f()] with respect to a scalar is:
The Jacobian matrix J of a vector function f(x) where x and f(x) is:
The derivative of a scalar function f(X) with respect to a matrix X is:
The Jacobian matrix J of a vector-valued function f: at a point x is defined as:
The Jacobian contains all first-order partial derivatives of the vector function.
The gradient of a scalar function f: is a special case of the Jacobian:
The gradient points in the direction of the greatest rate of increase of the function.
The Hessian matrix of a scalar function f: is the square matrix of second-order partial derivatives:
For a function f(x, x) = x + x, the Hessian is:
The chain rule in matrix calculus allows us to compute derivatives of composite functions.
For a scalar function f(y) where y depends on vector x:
For a vector function f(y) where y depends on vector x:
For a scalar function f(Y) where Y is a function of X:
For the function f = xAx where A is symmetric and x is a vector:
| Expression | Gradient |
|---|---|
| (ax)/x | a |
| (xa)/x | a |
| (xAx)/x | (A + A)x |
| (xAx)/x (A symmetric) | 2Ax |
| (aXb)/X | ab |
| (aXb)/X | ba |
| (tr(X))/X | I |
| (tr(AX))/X | A |
| (tr(XA))/X | A |
| (det(X))/X | det(X) X |
Matrix calculus is fundamental in training neural networks through backpropagation. The derivative of the loss function with respect to network parameters is computed using chain rules in high-dimensional spaces.
Many optimization algorithms rely on gradient descent and Newton's method, which requires the gradient and Hessian of scalar functions defined in high-dimensional spaces.
Maximum likelihood estimation often involves derivatives of log-likelihood functions with respect to parameter vectors, utilizing matrix calculus.
In optimal control problems, matrix calculus is used to analyze the sensitivity of systems with respect to parameters and to derive optimal control laws.
Computing the Jacobian and Hessian of robot kinematics and dynamics is essential for trajectory planning and control.
Econometrics uses matrix calculus for deriving parameter estimates in regression models and for analyzing economic systems with multiple interdependent variables.
