赞
踩
参考资料:
3、浅谈张量分解(二):张量分解的数学基础 - 知乎 (zhihu.com)
4、浅谈张量分解(四):外积、Kronecker积和张量积 - 知乎 (zhihu.com)
6、张量分解 (Tensor Decomposition) - 知乎 (zhihu.com)
7、使用MATLAB快速计算Khatri-Rao积_Quino_321的博客-CSDN博客
网上找了些张量的入门资料。
matlab实现基本计算:
1、张量积
例:
程序:
C=kron(A,B)
C =
5 6 7 10 12 14
8 9 10 16 18 20
15 18 21 20 24 28
24 27 30 32 36 40
2、Khatri-Rao积
程序:
- function kr=KR(F,G)
- nR_F=size(F,1); %F的行数
- nR_G=size(G,1); %G的行数
- mul=ones(nR_G,1);
- FF=kron(F,mul); %通过kron函数实现对F矩阵的扩充,得到FF矩阵
- GG=repmat(G,nR_F,1);%通过repmat函数实现对G矩阵的扩充,得到GG矩阵
- kr=FF.*GG;
- end
带入A,B,执行结果:
5 12
7 16
9 20
15 24
21 32
27 40
3、向量的外积
>> a=[2 3 4];
>> b=[3 4 5];
>> c=cross(a,b)
c =
-1 2 -1
4、向量的数量积(内积)
dot(x,y)
5、4阶张量展开
程序:
- X(:,:,1,1)=[1 2;3 4];
- X(:,:,2,1)=[5 6;7 8];
- X(:,:,1,2)=[9 10;11 12];
- X(:,:,2,2)=[13 14;15 16];
- X=tensor(X);
- X1=tenmat(X,1)
- X2=tenmat(X,2)
- X3=tenmat(X,3)
- X4=tenmat(X,4)
输出:
X1 is a matrix corresponding to a tensor of size 2 x 2 x 2 x 2
X1.rindices = [ 1 ] (modes of tensor corresponding to rows)
X1.cindices = [ 2 3 4 ] (modes of tensor corresponding to columns)
X1.data =
1 2 5 6 9 10 13 14
3 4 7 8 11 12 15 16
X2 is a matrix corresponding to a tensor of size 2 x 2 x 2 x 2
X2.rindices = [ 2 ] (modes of tensor corresponding to rows)
X2.cindices = [ 1 3 4 ] (modes of tensor corresponding to columns)
X2.data =
1 3 5 7 9 11 13 15
2 4 6 8 10 12 14 16
X3 is a matrix corresponding to a tensor of size 2 x 2 x 2 x 2
X3.rindices = [ 3 ] (modes of tensor corresponding to rows)
X3.cindices = [ 1 2 4 ] (modes of tensor corresponding to columns)
X3.data =
1 3 2 4 9 11 10 12
5 7 6 8 13 15 14 16
X4 is a matrix corresponding to a tensor of size 2 x 2 x 2 x 2
X4.rindices = [ 4 ] (modes of tensor corresponding to rows)
X4.cindices = [ 1 2 3 ] (modes of tensor corresponding to columns)
X4.data =
1 3 2 4 5 7 6 8
9 11 10 12 13 15 14 16
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。