向量化和矩阵化
vectorization
matricization
看论文遇到向量化和矩阵化的概念
We use vec(·), vech(·) and mat(·) for vectorization, half vectorization, and matricization respectively.
Let e i e_{i} ei be the i i ith canonical basis vector of R n \mathbb{R}^{n} Rn and E i j = e i e j T E_{ij}=e_{i}e_{j}^{T} Eij=eiejT .
The column-wise block matrix B i ∈ R n 2 × n B_{i}\in\mathbb{R}^{n^{2}\times n} Bi∈Rn2×n consists of n blocks of size n × n n\times n n×n, with an identity matrix only in the ith block and the others are all zeros. Then for any matrix X ∈ R n × n X\in\mathbb{R}^{n\times n} X∈Rn×n and vector x ∈ R n 2 x\in\mathbb{R}^{n^{2}} x∈Rn2 , vectorization and matricization can be expressed by linear operators as vec ( X ) = ∑ i = 1 n B i X e i \operatorname{vec}(X)=\sum_{i=1}^{n}B_{i}Xe_{i} vec(X)=i=1∑nBiXei
mat ( x ) = ∑ i = 1 n B i T x e i T \operatorname{mat}(x)=\sum_{i=1}^{n}B_{i}^{T}xe_{i}^{T} mat(x)=i=1∑nBiTxeiT
可以看出
B
i
B_i
Bi是第
i
i
i块为单位矩阵,其他元素为0的块矩阵。直接看公式不是那么明显,为了便于理解写个程序验证一下结果。
我们对矩阵
X
=
[
1
2
3
4
5
6
7
8
9
]
X=\left[\begin{array}{ccc} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{array}\right]
X=⎣⎡147258369⎦⎤
进行向量化;得到
x
x
=
[
1
4
7
2
5
8
3
6
9
]
xx=\left[\begin{array}{c} 1\\ 4\\ 7\\ 2\\ 5\\ 8\\ 3\\ 6\\ 9 \end{array}\right]
xx=⎣⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎡147258369⎦⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎤
对向量
x
x
=
[
1
2
3
4
5
6
7
8
9
]
xx=\left[\begin{array}{c} 1\\ 2\\ 3\\ 4\\ 5\\ 6\\ 7\\ 8\\ 9 \end{array}\right]
xx=⎣⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎡123456789⎦⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎤
进行矩阵化,得到
X = [ 1 4 7 2 5 8 3 6 9 ] X=\left[\begin{array}{ccc} 1 & 4 & 7\\ 2 & 5 & 8\\ 3 & 6 & 9 \end{array}\right] X=⎣⎡123456789⎦⎤
验证代码(Matlab)
B1=[ 1 0 0;
0 1 0;
0 0 1;
0 0 0;
0 0 0;
0 0 0;
0 0 0;
0 0 0;
0 0 0];
B2=[0 0 0;
0 0 0;
0 0 0;
1 0 0;
0 1 0;
0 0 1;
0 0 0;
0 0 0;
0 0 0];
B3=[0 0 0;
0 0 0;
0 0 0;
0 0 0;
0 0 0;
0 0 0;
1 0 0;
0 1 0;
0 0 1];
e1 = [1 0 0]';
e2 = [0 1 0]';
e3 = [0 0 1]';
xx = [1 2 3 4 5 6 7 8 9]'; %%%向量x
X = [1 2 3;4 5 6; 7 8 9]; %%%矩阵X
A = B1*X*e1+B2*X*e2+B3*X*e3; %%把矩阵向量化
AA = B1'*xx*e1'+B2'*xx*e2'+B3'*xx*e3'; %%把向量单位化
向量化的matlab实现
A = [1,2;3,4];
B=A(:);
c=reshape(A,[],1);
B = [ 1 3 2 4 ] B=\left[\begin{array}{c} 1\\ 3\\ 2\\ 4 \end{array}\right] B=⎣⎢⎢⎡1324⎦⎥⎥⎤
c = [ 1 3 2 4 ] c=\left[\begin{array}{c} 1\\ 3\\ 2\\ 4 \end{array}\right] c=⎣⎢⎢⎡1324⎦⎥⎥⎤