To install click the Add extension button. That's it.

The source code for the WIKI 2 extension is being checked by specialists of the Mozilla Foundation, Google, and Apple. You could also do it yourself at any point in time.

4,5
Kelly Slayton
Congratulations on this excellent venture… what a great idea!
Alexander Grigorievskiy
I use WIKI 2 every day and almost forgot how the original Wikipedia looks like.
Live Statistics
English Articles
Improved in 24 Hours
Languages
Recent
Show all languages
What we do. Every page goes through several hundred of perfecting techniques; in live mode. Quite the same Wikipedia. Just better.
.
Leo
Newton
Brights
Milds

# Gram matrix

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

• 1/5
Views:
4 335
376
10 696
3 138
895
• Why Gram Matrix in Style Transfer || Quick Explained
• 41 - Mathematics of Gram Matrix | Neural Style Transfer | Deep Learning | Computer Vision
• Linear Algebra 20L: The Dot Product in Non-Cartesian Bases, the Gram Matrix or the Metric
• Advanced Linear Algebra, Lecture 7.2: Nonstandard inner products and Gram matrices
• The Gram-Schmidt Process (Example 3)

## Examples

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

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

${\displaystyle G_{ij}=\int _{t_{0}}^{t_{f}}\ell _{i}^{*}(\tau )\ell _{j}(\tau )\,d\tau .}$

where ${\displaystyle \ell _{i}^{*}(\tau )}$ is the complex conjugate of ${\displaystyle \ell _{i}(\tau )}$.

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

### Applications

• In Riemannian geometry, given an embedded ${\displaystyle k}$-dimensional Riemannian manifold ${\displaystyle M\subset \mathbb {R} ^{n}}$ and a parametrization ${\displaystyle \phi :U\to M}$ for ${\displaystyle (x_{1},\ldots ,x_{k})\in U\subset \mathbb {R} ^{k}}$, the volume form ${\displaystyle \omega }$ on ${\displaystyle M}$ induced by the embedding may be computed using the Gramian of the coordinate tangent vectors:
${\displaystyle \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 ${\displaystyle \phi :U\to S\subset \mathbb {R} ^{3}}$ for ${\displaystyle (x,y)\in U\subset \mathbb {R} ^{2}}$:
${\displaystyle \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.[2] (Also see kernel PCA)
• 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:

${\displaystyle 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 ={\biggl \langle }\sum _{i}x_{i}v_{i},\sum _{j}x_{j}v_{j}{\biggr \rangle }={\biggl \|}\sum _{i}x_{i}v_{i}{\biggr \|}^{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 ${\displaystyle v_{i}}$ are linearly independent (that is, ${\textstyle \sum _{i}x_{i}v_{i}\neq 0}$ for all ${\displaystyle x}$).[1]

### Finding a vector realization

Given any positive semidefinite matrix ${\displaystyle M}$, one can decompose it as:

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

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

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

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

${\displaystyle 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 ${\displaystyle \mathbb {C} ^{k}}$.

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

### Uniqueness of vector realizations

If ${\displaystyle M}$ is the Gram matrix of vectors ${\displaystyle v_{1},\dots ,v_{n}}$ in ${\displaystyle \mathbb {R} ^{k}}$ then applying any rotation or reflection of ${\displaystyle \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 ${\displaystyle k\times k}$ orthogonal matrix ${\displaystyle Q}$, the Gram matrix of ${\displaystyle Qv_{1},\dots ,Qv_{n}}$ is also ${\displaystyle M}$.

This is the only way in which two real vector realizations of ${\displaystyle M}$ can differ: the vectors ${\displaystyle v_{1},\dots ,v_{n}}$ are unique up to orthogonal transformations. In other words, the dot products ${\displaystyle v_{i}\cdot v_{j}}$ and ${\displaystyle w_{i}\cdot w_{j}}$ are equal if and only if some rigid transformation of ${\displaystyle \mathbb {R} ^{k}}$ transforms the vectors ${\displaystyle v_{1},\dots ,v_{n}}$ to ${\displaystyle 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 ${\displaystyle v_{1},\dots ,v_{n}}$ is equal to the Gram matrix of vectors ${\displaystyle w_{1},\dots ,w_{n}}$ in ${\displaystyle \mathbb {C} ^{k}}$ then there is a unitary ${\displaystyle k\times k}$ matrix ${\displaystyle U}$ (meaning ${\displaystyle U^{\dagger }U=I}$) such that ${\displaystyle v_{i}=Uw_{i}}$ for ${\displaystyle i=1,\dots ,n}$.[3]

### Other properties

• Because ${\displaystyle G=G^{\dagger }}$, it is necessarily the case that ${\displaystyle G}$ and ${\displaystyle G^{\dagger }}$ commute. That is, a real or complex Gram matrix ${\displaystyle G}$ is also a normal matrix.
• The Gram matrix of any orthonormal basis is the identity matrix. Equivalently, the Gram matrix of the rows or the columns of a real rotation matrix is the identity matrix. Likewise, the Gram matrix of the rows or columns of a unitary matrix is the identity matrix.
• The rank of the Gram matrix of vectors in ${\displaystyle \mathbb {R} ^{k}}$ or ${\displaystyle \mathbb {C} ^{k}}$ equals the dimension of the space spanned by these vectors.[1]

## Gram determinant

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

${\displaystyle {\bigl |}G(\{v_{1},\dots ,v_{n}\}){\bigr |}={\begin{vmatrix}\langle v_{1},v_{1}\rangle &\langle v_{1},v_{2}\rangle &\dots &\langle v_{1},v_{n}\rangle \\\langle v_{2},v_{1}\rangle &\langle v_{2},v_{2}\rangle &\dots &\langle v_{2},v_{n}\rangle \\\vdots &\vdots &\ddots &\vdots \\\langle v_{n},v_{1}\rangle &\langle v_{n},v_{2}\rangle &\dots &\langle v_{n},v_{n}\rangle \end{vmatrix}}.}$

If ${\displaystyle v_{1},\dots ,v_{n}}$ are vectors in ${\displaystyle \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 the determinant and volume are zero. 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 is also useful for computing the volume of the simplex formed by the vectors; its volume is Volume(parallelotope) / n!.

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

${\displaystyle {\bigl |}G(v_{1},\dots ,v_{n}){\bigr |}=\|v_{1}\wedge \cdots \wedge v_{n}\|^{2}.}$

When the vectors ${\displaystyle v_{1},\ldots ,v_{n}\in \mathbb {R} ^{m}}$ are defined from the positions of points ${\displaystyle p_{1},\ldots ,p_{n}}$ relative to some reference point ${\displaystyle p_{n+1}}$,

${\displaystyle (v_{1},v_{2},\ldots ,v_{n})=(p_{1}-p_{n+1},p_{2}-p_{n+1},\ldots ,p_{n}-p_{n+1})\,,}$

then the Gram determinant can be written as the difference of two Gram determinants,

${\displaystyle {\bigl |}G(\{v_{1},\dots ,v_{n}\}){\bigr |}={\bigl |}G(\{(p_{1},1),\dots ,(p_{n+1},1)\}){\bigr |}-{\bigl |}G(\{p_{1},\dots ,p_{n+1}\}){\bigr |}\,,}$

where each ${\displaystyle (p_{j},1)}$ is the corresponding point ${\displaystyle p_{j}}$ supplemented with the coordinate value of 1 for an ${\displaystyle (m+1)}$-st dimension.[citation needed] Note that in the common case that n = m, the second term on the right-hand side will be zero.

## Constructing an orthonormal basis

Given a set of linearly independent vectors ${\displaystyle \{v_{i}\}}$ with Gram matrix ${\displaystyle G_{ij}:=\langle v_{i},v_{j}\rangle }$, one can construct an orthonormal basis

${\displaystyle u_{i}:=\sum _{j}{\bigl (}G^{-1/2}{\bigr )}_{ji}v_{j}.}$

In matrix notation, ${\displaystyle U=VG^{-1/2}}$, where ${\displaystyle U}$ has orthonormal basis vectors ${\displaystyle \{u_{i}\}}$ and the matrix ${\displaystyle V}$ is composed of the given column vectors ${\displaystyle \{v_{i}\}}$.

The matrix ${\displaystyle G^{-1/2}}$ is guaranteed to exist. Indeed, ${\displaystyle G}$ is Hermitian, and so can be decomposed as ${\displaystyle G=UDU^{\dagger }}$ with ${\displaystyle U}$ a unitary matrix and ${\displaystyle D}$ a real diagonal matrix. Additionally, the ${\displaystyle v_{i}}$ are linearly independent if and only if ${\displaystyle G}$ is positive definite, which implies that the diagonal entries of ${\displaystyle D}$ are positive. ${\displaystyle G^{-1/2}}$ is therefore uniquely defined by ${\displaystyle G^{-1/2}:=UD^{-1/2}U^{\dagger }}$. One can check that these new vectors are orthonormal:

{\displaystyle {\begin{aligned}\langle u_{i},u_{j}\rangle &=\sum _{i'}\sum _{j'}{\Bigl \langle }{\bigl (}G^{-1/2}{\bigr )}_{i'i}v_{i'},{\bigl (}G^{-1/2}{\bigr )}_{j'j}v_{j'}{\Bigr \rangle }\\[10mu]&=\sum _{i'}\sum _{j'}{\bigl (}G^{-1/2}{\bigr )}_{ii'}G_{i'j'}{\bigl (}G^{-1/2}{\bigr )}_{j'j}\\[8mu]&={\bigl (}G^{-1/2}GG^{-1/2}{\bigr )}_{ij}=\delta _{ij}\end{aligned}}}

where we used ${\displaystyle {\bigl (}G^{-1/2}{\bigr )}^{\dagger }=G^{-1/2}}$.