问题
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