# Gram matrix

(Redirected from Gramian matrix)

In linear algebra, the Gram matrix (or Gramian matrix, Gramian) of a set of vectors $v_{1},\dots ,v_{n}$ in an inner product space is the Hermitian matrix of inner products, whose entries are given by $G_{ij}=\left\langle v_{i},v_{j}\right\rangle$ . If the vectors $v_{1},\dots ,v_{n}$ are the columns of matrix $X$ then the Gram matrix is $X^{\dagger }X$ in the general case that the vector coordinates are complex numbers, which simplifies to $X^{\top }X$ for the case that the vector coordinates are real numbers.

An important application is to compute linear independence: a set of vectors are linearly independent if and only if the Gram determinant (the determinant of the Gram matrix) is non-zero.

It is named after Jørgen Pedersen Gram.

## Examples

For finite-dimensional real vectors in $\mathbb {R} ^{n}$ with the usual Euclidean dot product, the Gram matrix is simply $G=V^{\top }V$ , where $V$ is a matrix whose columns are the vectors $v_{k}$ . For complex vectors in $\mathbb {C} ^{n}$ , $G=V^{\dagger }V$ , where $V^{\dagger }$ is the conjugate transpose of $V$ .

Given square-integrable functions $\{\ell _{i}(\cdot ),\,i=1,\dots ,n\}$ on the interval $\left[t_{0},t_{f}\right]$ , the Gram matrix $G=\left[G_{ij}\right]$ is:

$G_{ij}=\int _{t_{0}}^{t_{f}}\ell _{i}^{*}(\tau )\ell _{j}(\tau )\,d\tau .$ where $\ell _{i}^{*}(\tau )$ is the complex conjugate of $\ell _{i}(\tau )$ .

For any bilinear form $B$ on a finite-dimensional vector space over any field we can define a Gram matrix $G$ attached to a set of vectors $v_{1},\dots ,v_{n}$ by $G_{ij}=B\left(v_{i},v_{j}\right)$ . The matrix will be symmetric if the bilinear form $B$ is symmetric.

### Applications

• In Riemannian geometry, given an embedded $k$ -dimensional Riemannian manifold $M\subset \mathbb {R} ^{n}$ and a parametrization $\phi :U\to M$ for $(x_{1},\ldots ,x_{k})\in U\subset \mathbb {R} ^{k}$ , the volume form $\omega$ on $M$ induced by the embedding may be computed using the Gramian of the coordinate tangent vectors:
$\omega ={\sqrt {\det G}}\ dx_{1}\cdots dx_{k},\quad G=\left[\left\langle {\frac {\partial \phi }{\partial x_{i}}},{\frac {\partial \phi }{\partial x_{j}}}\right\rangle \right].$ This generalizes the classical surface integral of a parametrized surface $\phi :U\to S\subset \mathbb {R} ^{3}$ for $(x,y)\in U\subset \mathbb {R} ^{2}$ :
$\int _{S}f\ dA=\iint _{U}f(\phi (x,y))\,\left|{\frac {\partial \phi }{\partial x}}\,{\times }\,{\frac {\partial \phi }{\partial y}}\right|\,dx\,dy.$ • If the vectors are centered random variables, the Gramian is approximately proportional to the covariance matrix, with the scaling determined by the number of elements in the vector.
• In quantum chemistry, the Gram matrix of a set of basis vectors is the overlap matrix.
• In control theory (or more generally systems theory), the controllability Gramian and observability Gramian determine properties of a linear system.
• Gramian matrices arise in covariance structure model fitting (see e.g., Jamshidian and Bentler, 1993, Applied Psychological Measurement, Volume 18, pp. 79–94).
• In the finite element method, the Gram matrix arises from approximating a function from a finite dimensional space; the Gram matrix entries are then the inner products of the basis functions of the finite dimensional subspace.
• In machine learning, kernel functions are often represented as Gram matrices.
• Since the Gram matrix over the reals is a symmetric matrix, it is diagonalizable and its eigenvalues are non-negative. The diagonalization of the Gram matrix is the singular value decomposition.

## Properties

### Positive-semidefiniteness

The Gram matrix is symmetric in the case the real product is real-valued; it is Hermitian in the general, complex case by definition of an inner product.

The Gram matrix is positive semidefinite, and every positive semidefinite matrix is the Gramian matrix for some set of vectors. The fact that the Gramian matrix is positive-semidefinite can be seen from the following simple derivation:

$x^{\dagger }\mathbf {G} x=\sum _{i,j}x_{i}^{*}x_{j}\left\langle v_{i},v_{j}\right\rangle =\sum _{i,j}\left\langle x_{i}v_{i},x_{j}v_{j}\right\rangle =\left\langle \sum _{i}x_{i}v_{i},\sum _{j}x_{j}v_{j}\right\rangle =\left\|\sum _{i}x_{i}v_{i}\right\|^{2}\geq 0.$ The first equality follows from the definition of matrix multiplication, the second and third from the bi-linearity of the inner-product, and the last from the positive definiteness of the inner product. Note that this also shows that the Gramian matrix is positive definite if and only if the vectors $v_{i}$ are linearly independent (that is, ${\textstyle \sum _{i}x_{i}v_{i}\neq 0}$ for all $x$ ).

### Finding a vector realization

Given any positive semidefinite matrix $M$ , one can decompose it as:

$M=B^{\dagger }B$ ,

where $B^{\dagger }$ is the conjugate transpose of $B$ (or $M=B^{\textsf {T}}B$ in the real case).

Here $B$ is a $k\times n$ matrix, where $k$ is the rank of $M$ . Various ways to obtain such a decomposition include computing the Cholesky decomposition or taking the non-negative square root of $M$ .

The columns $b^{(1)},\dots ,b^{(n)}$ of $B$ can be seen as n vectors in $\mathbb {C} ^{k}$ (or k-dimensional Euclidean space $\mathbb {R} ^{k}$ , in the real case). Then

$M_{ij}=b^{(i)}\cdot b^{(j)}$ where the dot product ${\textstyle a\cdot b=\sum _{\ell =1}^{k}a_{\ell }^{*}b_{\ell }}$ is the usual inner product on $\mathbb {C} ^{k}$ .

Thus a Hermitian matrix $M$ is positive semidefinite if and only if it is the Gram matrix of some vectors $b^{(1)},\dots ,b^{(n)}$ . Such vectors are called a vector realization of $M$ . The infinite-dimensional analog of this statement is Mercer's theorem.

### Uniqueness of vector realizations

If $M$ is the Gram matrix of vectors $v_{1},\dots ,v_{n}$ in $\mathbb {R} ^{k}$ , then applying any rotation or reflection of $\mathbb {R} ^{k}$ (any orthogonal transformation, that is, any Euclidean isometry preserving 0) to the sequence of vectors results in the same Gram matrix. That is, for any $k\times k$ orthogonal matrix $Q$ , the Gram matrix of $Qv_{1},\dots ,Qv_{n}$ is also $M$ .

This is the only way in which two real vector realizations of $M$ can differ: the vectors $v_{1},\dots ,v_{n}$ are unique up to orthogonal transformations. In other words, the dot products $v_{i}\cdot v_{j}$ and $w_{i}\cdot w_{j}$ are equal if and only if some rigid transformation of $\mathbb {R} ^{k}$ transforms the vectors $v_{1},\dots ,v_{n}$ to $w_{1},\dots ,w_{n}$ and 0 to 0.

The same holds in the complex case, with unitary transformations in place of orthogonal ones. That is, if the Gram matrix of vectors $v_{1},\dots ,v_{n}$ is equal to the Gram matrix of vectors $w_{1},\dots ,w_{n}$ in $\mathbb {C} ^{k}$ , then there is a unitary $k\times k$ matrix $U$ (meaning $U^{\dagger }U=I$ ) such that $v_{i}=Uw_{i}$ for $i=1,\dots ,n$ .

### Other properties

• A real Gram matrix is also a normal matrix, since $(X^{\textsf {T}}X)^{\textsf {T}}(X^{\textsf {T}}X)=(X^{\textsf {T}}X)(X^{\textsf {T}}X)^{\textsf {T}}$ • The Gram matrix of any orthonormal basis is the identity matrix.
• The rank of the Gram matrix of vectors in $\mathbb {R} ^{k}$ or $\mathbb {C} ^{k}$ equals the dimension of the space spanned by these vectors.

## Gram determinant

The Gram determinant or Gramian is the determinant of the Gram matrix:

$G(x_{1},\dots ,x_{n})={\begin{vmatrix}\langle x_{1},x_{1}\rangle &\langle x_{1},x_{2}\rangle &\dots &\langle x_{1},x_{n}\rangle \\\langle x_{2},x_{1}\rangle &\langle x_{2},x_{2}\rangle &\dots &\langle x_{2},x_{n}\rangle \\\vdots &\vdots &\ddots &\vdots \\\langle x_{n},x_{1}\rangle &\langle x_{n},x_{2}\rangle &\dots &\langle x_{n},x_{n}\rangle \end{vmatrix}}.$ If $x_{1},\dots ,x_{n}$ are vectors in $\mathbb {R} ^{m}$ , then it is the square of the n-dimensional volume of the parallelotope formed by the vectors. In particular, the vectors are linearly independent if and only if the parallelotope has nonzero n-dimensional volume, if and only if Gram determinant is nonzero, if and only if the Gram matrix is nonsingular. When m = n, This reduces to the standard theorem that the absolute value of the determinant of n n-dimensional vectors is the n-dimensional volume.

The Gram determinant can also be expressed in terms of the exterior product of vectors by

$G(x_{1},\dots ,x_{n})=\|x_{1}\wedge \cdots \wedge x_{n}\|^{2}.$ 