Multiplying large vectors and Out of memory. Type HELP MEMORY for your options

穿精又带淫゛_ 提交于 2019-12-25 09:47:42

问题


Actually this is what i am trying to do Ad=<100820x20164 double> and b= <100820x1 double> also Ad is sparse matrix and b is non-sparse .Below is the original Problem and i try to change the statement A=V'*V + y_0*y_0'; using the block processing technique as you told me , now the problem is on the assignment statement mentioned below.

V=Ad;     
b_1=b;
x_0=ones(size(V ,1) ,1);
y_0=V'*x_0;
A=V'*V + y_0*y_0';
b=V'*b_1 + dot(x_0,b_1)*y_0;

%%%%%%%%% Modified using block processing below %%%%%%

V=Ad;     
b_1=b;
x_0=ones(size(V ,1) ,1);
y_0=V'*x_0;

v=V'*V ;   %%% v is updated here which is left hand side of equation 

 %%% Block Processing code %% For right hand side of equation
 y_01 = y_0(1:size(y_0)/2);
 y_02 = y_0(size(y_0)/2 + 1:end);


 res =( y_01 * y_01'); % Upper left 
 Temp=v(1:size(v ,1)/2 , 1:size(v ,1)/2)  + res  ;
 v(1:size(v ,1)/2 , 1:size(v ,1)/2)  = Temp;       %%%% Problem here gets hang
 clear Temp; clear res ;


 res = y_02 * y_02'; % Bottom right
 Temp=v(size(v ,1)/2 + 1 :end , size(v ,1)/2 + 1 :end)  + res  ;  
 v(size(v ,1)/2 + 1:end , size(v ,1)/2 + 1:end)  = Temp; 
 clear Temp; clear res ;


 res = y_01 * y_02'; % Upper right
 Temp=v(1:size(v ,1)/2 , size(v ,1)/2 + 1:end)  + res  ;
 v(1:size(v ,1)/2 , size(v ,1)/2 + 1:end)  = Temp; 
 clear Temp; clear res ;


 res = y_02 * y_01'; % Bottom left   
 Temp=v(size(v ,1)/2 + 1:end, 1:size(v ,1)/2 )   + res  ;
 v(size(v ,1)/2 + 1:end, 1:size(v ,1)/2 )  = Temp; 
 clear Temp; clear res ;

回答1:


While V'*V is sparse, y_0*y_0' is not. Unless of course V' has many empty rows. You could calculate y_0*y_0' block-wise:

y_01 = y_0(1:10000);
y_02 = y_0(10001:end);

res = y_01 * y_01' % Upper left 
% Process...
res = y_02 * y_02' % Bottom right
% Process...
res = y_01 * y_02' % Upper right
% Process...
res = y_02 * y_01' % Bottom left  
% Process...

In the 'Process' section you can combine it with the appropriate portion of V'*V. I would also suggest re-factoring my code snippet to avoid redundancy.



来源:https://stackoverflow.com/questions/7861709/multiplying-large-vectors-and-out-of-memory-type-help-memory-for-your-options

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!