[英]Gradient descent for small and large values of multidimensional matrix
I have a matrix R which I want to estimate using gradient descent method. 我有一个矩阵R,我想使用梯度下降法进行估算。 The code is working good for small dimension matrix (eg 100x1) but it gives NaN values as I increase dimension (eg 10x3).
该代码适用于小尺寸矩阵(例如100x1),但是随着我增加尺寸(例如10x3),它可以提供NaN值。 Please help!
请帮忙!
R =[196,242,3;186,302,3;22,377,1;244,51,2;166,346,1;298,474,4;115,265,2;253,465,5;305,451,3;6,86,3];
N = length(R);
M = size(R,2);
K = 3;
P = rand(N,K);
Q = rand(M,K);
alpha = 0.002;
beta = 0.02;
for iter = 1 : 5000
e = R - P*Q';
P_new = P + 2*alpha*(e*Q-beta*P);
Q_new= Q + 2*alpha*(e'*P-beta*Q);
mse2(iter) = norm(R - P*Q')/norm(R);
P=P_new;
Q=Q_new;
end
R_est = P*Q';
Your problem lies in the for loop. 您的问题出在for循环中。 The largest double matlab can store is
1.7977e+308
, after 7 runs of the loop your values for P and Q are on the order of 10^101 and after 8 runs inf
. 最大的double matlab可以存储的是
1.7977e+308
,在循环运行7次后,P和Q的值约为10 ^ 101,在运行8个inf
。 I'm not sure what you mean by estimate matrix but your nan
values are coming from the way P an Q grow so rapidly. 我不确定您的估算矩阵是什么意思,但您的
nan
值来自P和Q如此快速增长的方式。 One other things of note, the mse2
variable is not to used. 需要注意的另一件事是,不使用
mse2
变量。 What is its purpose? 目的是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.