浅谈张量分解（三）：如何对稀疏矩阵进行奇异值分解？

1 矩阵的奇异值分解

2 稀疏矩阵的奇异值分解

3 缺失元素的初始化填补

.

A_sparse=[0,90,449,517;0,0,412,0;192,0,697,687;185,0,699,657;164,58,0,0];
A_real=[208,90,449,517;104,43,412,411;192,77,697,687;185,115,699,657;...
164,58,696,599];
pos1=find(A_sparse==0);pos2=find(A_sparse~=0);[m,n]=size(A_real);
mu=mean(A_sparse(pos2));b1=0.1*rand(1,m);b2=0.1*rand(1,n);error=zeros(m,n);
alpha1=0.01;
for iter=1:1000
for i=1:m
for j=1:n
A_hat(i,j)=round(mu+b1(1,i)+b2(1,j));
if A_sparse(i,j)~=0
error(i,j)=A_sparse(i,j)-A_hat(i,j);
end
end
end
b1=b1+alpha1*sum(error');b2=b2+alpha1*sum(error);
L1(1,iter)=0.5*sum(sum(error.^2));
end
RMSE=sqrt(sum((A_real(pos1)-A_hat(pos1)).^2)/length(pos1))


A_sparse=[0,90,449,517;0,0,412,0;192,0,697,687;185,0,699,657;164,58,0,0];
A_real=[208,90,449,517;104,43,412,411;192,77,697,687;185,115,699,657;...
164,58,696,599];
pos=find(A_sparse==0);[m,n]=size(A_real);r=3;
U=0.1*rand(m,r);V=0.1*rand(n,r);error=zeros(m,n);
alpha2=0.0001;
for iter=1:1500
A_hat=round(U*V');error=A_sparse-A_hat;error(pos)=0;
U_plus=U+alpha2*error*V;
V_plus=V+alpha2*error'*U;
U=U_plus;V=V_plus;
L2(1,iter)=0.5*sum(sum(error.^2));
end
RMSE=sqrt(sum((A_real(pos)-A_hat(pos)).^2)/length(pos))


4 迭代的奇异值分解

Charu C. Aggarwal在其著作《Recommender systems》第115页给出的算法非常简单，将缺失元素初始化填补阶段得到的记为，按照如下操作：

• 第一步：对进行奇异值分解，只选取前个最大的奇异值和其对应的特征向量，得到
• 第二步：用更新矩阵（最初的，不是）缺失位置的元素，记为，若未收敛，令，返回第一步。

A_sparse=[0,90,449,517;0,0,412,0;192,0,697,687;185,0,699,657;164,58,0,0];
A_real=[208,90,449,517;104,43,412,411;192,77,697,687;185,115,699,657;...
164,58,696,599];
A_hat=[401,90,449,517;401,401,412,401;192,401,697,687;185,401,699,657;...
164,58,401,401];
pos=find(A_sparse==0);[m,n]=size(A_real);k=2;
A_f=A_hat;
for iter=1:8000
[Q,Sigma,P]=svds(A_f,k);
A_hat=Q*Sigma*P';
A_f(pos)=A_hat(pos);
convergence(1,iter)=sum(A_hat(pos).^2);
end
RMSE=sqrt(sum((A_real(pos)-A_f(pos)).^2)/length(pos))


A_sparse=[0,90,449,517;0,0,412,0;192,0,697,687;185,0,699,657;164,58,0,0];
A_real=[208,90,449,517;104,43,412,411;192,77,697,687;185,115,699,657;...
164,58,696,599];
A_hat=[48,41,505,510;-44,-51,412,418;219,212,676,681;207,200,664,670;...
115,107,571,577];
pos=find(A_sparse==0);[m,n]=size(A_real);k=2;
A_f=A_hat;
for iter=1:100
[Q,Sigma,P]=svds(A_f,k);
A_hat=Q*Sigma*P';
A_f(pos)=A_hat(pos);
convergence(1,iter)=sum(A_hat(pos).^2);
end
RMSE=sqrt(sum((A_real(pos)-A_f(pos)).^2)/length(pos))


A_sparse=[0,90,449,517;0,0,412,0;192,0,697,687;185,0,699,657;164,58,0,0];
A_real=[208,90,449,517;104,43,412,411;192,77,697,687;185,115,699,657;...
164,58,696,599];
A_hat=[139,89,449,517;114,46,412,408;192,75,697,687;186,59,699,657;...
163,59,599,579];
pos=find(A_sparse==0);[m,n]=size(A_real);k=2;
A_f=A_hat;
for iter=1:500
[Q,Sigma,P]=svds(A_f,k);
A_hat=Q*Sigma*P';
A_f(pos)=A_hat(pos);
convergence(1,iter)=sum(A_hat(pos).^2);
end
RMSE=sqrt(sum((A_real(pos)-A_f(pos)).^2)/length(pos))


5 相关阅读

• 2
点赞
• 0
评论
• 21
收藏
• 一键三连
• 扫一扫，分享海报

05-12

06-15 1万+
04-08 1万+
03-08 5773
06-06 9039
09-25 540
03-08 2375
09-01
09-14 1581
12-22 694
11-12 359
01-20 1万+
04-08 5218