向量化和矩阵化

向量化和矩阵化

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} BiRn2×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} XRn×n and vector x ∈ R n 2 x\in\mathbb{R}^{n^{2}} xRn2 , 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=1nBiXei

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=1nBiTxeiT

可以看出 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值