Dealing with a large Kronecker product in Matlab

896 Views Asked by At

Following is my minimization problem to solve for matrix D:

$$P=BDB^{T}$$

where dimension of $B$ is $576 \times 1296$ and dimension of $P$(unsymmetric) is $576\times 576$ and $D$ is a diagonal matrix of dimension $1296 \times 1296$.

To tackle this problem, I am doing the following:

Firstly, I used vector operation:

$$vec(P)= vec(BDB^T) = (B\otimes B)vec(D)$$

Since matrix D is diagonal, we can only choose columns of $B\otimes B$ corresponding to diagonal entries of matrix D.

When I try to implement this in Matlab, I ran into a memory problem. Can anyone help me fix this?

My matlab code looks like the following:

kronBB = kron(B,B); % kronecker product % D = eye(size(B,2)); vecD = D(:); in = find(vecD); % non-zero indices of vector D % kronBB1 = kronBB(:,in) % Only keeping columns corresponding to the diagonal entries of matrix D ;

Error in matlab reads:

Requested 576x576x1296x1296 (4151.9GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information. Error in kron (line 34) K = reshape(A.*B,[ma*mb na*nb]);

1

There are 1 best solutions below

4
On

Here is a Matlab program giving you what you call "kronBB1" under two forms : $U$ (direct, as you do) and $V$ (the way I advise) with my formula that I have inplemented as a set of Kronecker products of column vectors (that are still column vectors) without memory issues. This program checks that $U$ and $V$ are the same :

clear all;
m=7;n=12; % for example
% direct method giving U (with memory issues for big m and n):
B=round(9*rand(m,n))
D=kron(B,B);
U=D(:,n*(0:(n-1))+(1:n)); % straightforward "good column indices"
% indirect method giving V (without memory issues):
V=zeros(m^2,n);
for q=1:n
    V(:,q)=kron(B(1:m,q),B(:,q));% "1D" Kronecker products
end;
max(max(abs(U-V))),% checking U and V are identical