Vectorization (mathematics)

From HandWiki
Revision as of 18:10, 6 February 2024 by Ohm (talk | contribs) (link)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Short description: Conversion of a matrix or a tensor to a vector


In mathematics, especially in linear algebra and matrix theory, the vectorization of a matrix is a linear transformation which converts the matrix into a vector. Specifically, the vectorization of a m × n matrix A, denoted vec(A), is the mn × 1 column vector obtained by stacking the columns of the matrix A on top of one another: [math]\displaystyle{ \operatorname{vec}(A) = [a_{1,1}, \ldots, a_{m,1}, a_{1,2}, \ldots, a_{m,2}, \ldots, a_{1,n}, \ldots, a_{m,n}]^\mathrm{T} }[/math] Here, [math]\displaystyle{ a_{i,j} }[/math] represents the element in the i-th row and j-th column of A, and the superscript [math]\displaystyle{ {}^\mathrm{T} }[/math] denotes the transpose. Vectorization expresses, through coordinates, the isomorphism [math]\displaystyle{ \mathbf{R}^{m \times n} := \mathbf{R}^m \otimes \mathbf{R}^n \cong \mathbf{R}^{mn} }[/math] between these (i.e., of matrices and vectors) as vector spaces.

For example, for the 2×2 matrix [math]\displaystyle{ A = \begin{bmatrix} a & b \\ c & d \end{bmatrix} }[/math], the vectorization is [math]\displaystyle{ \operatorname{vec}(A) = \begin{bmatrix} a \\ c \\ b \\ d \end{bmatrix} }[/math].

Illustration video of vectorized addition

The connection between the vectorization of A and the vectorization of its transpose is given by the commutation matrix.

Compatibility with Kronecker products

The vectorization is frequently used together with the Kronecker product to express matrix multiplication as a linear transformation on matrices. In particular, [math]\displaystyle{ \operatorname{vec}(ABC) = (C^\mathrm{T}\otimes A) \operatorname{vec}(B) }[/math] for matrices A, B, and C of dimensions k×l, l×m, and m×n.[note 1] For example, if [math]\displaystyle{ \operatorname{ad}_A(X) = AX-XA }[/math] (the adjoint endomorphism of the Lie algebra gl(n, C) of all n×n matrices with complex entries), then [math]\displaystyle{ \operatorname{vec}(\operatorname{ad}_A(X)) = (I_n\otimes A - A^\mathrm{T} \otimes I_n ) \text{vec}(X) }[/math], where [math]\displaystyle{ I_n }[/math] is the n×n identity matrix.

There are two other useful formulations: [math]\displaystyle{ \begin{align} \operatorname{vec}(ABC) &= (I_n\otimes AB)\operatorname{vec}(C) = (C^\mathrm{T}B^\mathrm{T}\otimes I_k) \operatorname{vec}(A) \\ \operatorname{vec}(AB) &= (I_m \otimes A) \operatorname{vec}(B) = (B^\mathrm{T}\otimes I_k) \operatorname{vec}(A) \end{align} }[/math]

More generally, it has been shown that vectorization is a self-adjunction in the monoidal closed structure of any category of matrices.[1]

Compatibility with Hadamard products

Vectorization is an algebra homomorphism from the space of n × n matrices with the Hadamard (entrywise) product to Cn2 with its Hadamard product: [math]\displaystyle{ \operatorname{vec}(A \circ B) = \operatorname{vec}(A) \circ \operatorname{vec}(B) . }[/math]

Compatibility with inner products

Vectorization is a unitary transformation from the space of n×n matrices with the Frobenius (or Hilbert–Schmidt) inner product to Cn2: [math]\displaystyle{ \operatorname{tr}(A^\dagger B) = \operatorname{vec}(A)^\dagger \operatorname{vec}(B), }[/math] where the superscript denotes the conjugate transpose.

Vectorization as a linear sum

The matrix vectorization operation can be written in terms of a linear sum. Let X be an m × n matrix that we want to vectorize, and let ei be the i-th canonical basis vector for the n-dimensional space, that is [math]\displaystyle{ \mathbf{e}_i=\left[0,\dots,0,1,0,\dots,0\right]^\mathrm{T} }[/math]. Let Bi be a (mn) × m block matrix defined as follows: [math]\displaystyle{ \mathbf{B}_i = \begin{bmatrix} \mathbf{0} \\ \vdots \\ \mathbf{0} \\ \mathbf{I}_m \\ \mathbf{0} \\ \vdots \\ \mathbf{0} \end{bmatrix} = \mathbf{e}_i \otimes \mathbf{I}_m }[/math]

Bi consists of n block matrices of size m × m, stacked column-wise, and all these matrices are all-zero except for the i-th one, which is a m × m identity matrix Im.

Then the vectorized version of X can be expressed as follows: [math]\displaystyle{ \operatorname{vec}(\mathbf{X}) = \sum_{i=1}^n \mathbf{B}_i \mathbf{X} \mathbf{e}_i }[/math]

Multiplication of X by ei extracts the i-th column, while multiplication by Bi puts it into the desired position in the final vector.

Alternatively, the linear sum can be expressed using the Kronecker product: [math]\displaystyle{ \operatorname{vec}(\mathbf{X}) = \sum_{i=1}^n \mathbf{e}_i \otimes \mathbf{X} \mathbf{e}_i }[/math]

Half-vectorization

For a symmetric matrix A, the vector vec(A) contains more information than is strictly necessary, since the matrix is completely determined by the symmetry together with the lower triangular portion, that is, the n(n + 1)/2 entries on and below the main diagonal. For such matrices, the half-vectorization is sometimes more useful than the vectorization. The half-vectorization, vech(A), of a symmetric n × n matrix A is the n(n + 1)/2 × 1 column vector obtained by vectorizing only the lower triangular part of A: [math]\displaystyle{ \operatorname{vech}(A) = [A_{1,1}, \ldots, A_{n,1}, A_{2,2}, \ldots, A_{n,2}, \ldots, A_{n-1,n-1}, A_{n,n-1}, A_{n,n}]^\mathrm{T}. }[/math]

For example, for the 2×2 matrix [math]\displaystyle{ A = \begin{bmatrix} a & b \\ b & d \end{bmatrix} }[/math], the half-vectorization is [math]\displaystyle{ \operatorname{vech}(A) = \begin{bmatrix} a \\ b \\ d \end{bmatrix} }[/math].

There exist unique matrices transforming the half-vectorization of a matrix to its vectorization and vice versa called, respectively, the duplication matrix and the elimination matrix.

Programming language

Programming languages that implement matrices may have easy means for vectorization. In Matlab/GNU Octave a matrix A can be vectorized by A(:). GNU Octave also allows vectorization and half-vectorization with vec(A) and vech(A) respectively. Julia has the vec(A) function as well. In Python NumPy arrays implement the flatten method,[note 1] while in R the desired effect can be achieved via the c() or as.vector() functions. In R, function vec() of package 'ks' allows vectorization and function vech() implemented in both packages 'ks' and 'sn' allows half-vectorization.[2][3][4]

Applications

Vectorization is used in matrix calculus and its applications in establishing e.g., moments of random vectors and matrices, asymptotics, as well as Jacobian and Hessian matrices.[5] It is also used in local sensitivity and statistical diagnostics.[6]

Notes

  1. 1.0 1.1 The identity for row-major vectorization is [math]\displaystyle{ \operatorname{vec}(ABC) = (A \otimes C^\mathrm{T})\operatorname{vec}(B) }[/math].

See also

References

  1. Macedo, H. D.; Oliveira, J. N. (2013). "Typing Linear Algebra: A Biproduct-oriented Approach". Science of Computer Programming 78 (11): 2160–2191. doi:10.1016/j.scico.2012.07.012. 
  2. Duong, Tarn (2018). "ks: Kernel Smoothing". R package version 1.11.0. https://cran.r-project.org/package=ks. 
  3. Azzalini, Adelchi (2017). "The R package 'sn': The Skew-Normal and Related Distributions such as the Skew-t". R package version 1.5.1. https://cran.r-project.org/package=sn. 
  4. Vinod, Hrishikesh D. (2011). "Simultaneous Reduction and Vec Stacking". Hands-on Matrix Algebra Using R: Active and Motivated Learning with Applications. Singapore: World Scientific. pp. 233–248. ISBN 978-981-4313-69-8. https://books.google.com/books?id=oXzkJwutS1UC&pg=PA233. 
  5. Magnus, Jan; Neudecker, Heinz (2019). Matrix differential calculus with applications in statistics and econometrics. New York: John Wiley. ISBN 9781119541202. 
  6. Liu, Shuangzhe; Leiva, Victor; Zhuang, Dan; Ma, Tiefeng; Figueroa-Zúñiga, Jorge I. (March 2022). "Matrix differential calculus with applications in the multivariate linear model and its diagnostics" (in en). Journal of Multivariate Analysis 188: 104849. doi:10.1016/j.jmva.2021.104849.