Multiplication of SDPVAR and vectorized version

41 views
Skip to first unread message

jhua...@hawk.iit.edu

unread,
Nov 13, 2020, 11:40:37 AM11/13/20
to YALMIP
Hi professor,

I get the following message:
Multiplication of SDPVAR object caused memory error
Continuing using unvectorized version which is extremely slow

They are related with my code as follow,
FIM1=w_2*H_m'*(diag(p))*H_m
where w_2 is a constant, H_m is a m-by-n matrix.

How can I solve these 2 problems? By the way, I think my code is vectorized, right?

Thanks,
Jianqiao Huang

Johan Löfberg

unread,
Nov 13, 2020, 11:53:45 AM11/13/20
to YALMIP
You re simply creating a way too large symbolic expression. What do you intend to use it for? If it is a semidefinite constraint, you re screwed anyway as you never would be able to solve anything that large. If you are creating it to use it later for something else, you might not need to construct this first but do things in a more clever way

A simple thing like this
>> x = sdpvar(100);
>> R = randn(100);
>> x'*R*x

will have on the order of 10000 expressions, each involving on the order of 10000 monomials, and this will probably take a GB or so to represent

jhua...@hawk.iit.edu

unread,
Nov 13, 2020, 11:59:28 AM11/13/20
to YALMIP
Hi professor,

FIM1=w_2*H_m'*(diag(p))*H_m , where only p is a variable vector (8878-by-1), w_2 and H_m are constant number and matrix. It's a semidefinite model. Last year, I used a similar model and it worked. But I don't know why it doesn't work this time.

Thanks,
Jianqiao Huang

jhua...@hawk.iit.edu

unread,
Nov 13, 2020, 12:01:23 PM11/13/20
to YALMIP
Hi professor,

Do you think the model is large given that only p is a 8878-by-1 vector and the others are constant number or matrix? Do I need to send you my code?

Thanks,
Jianqiao Huang

jhua...@hawk.iit.edu

unread,
Nov 13, 2020, 12:07:35 PM11/13/20
to YALMIP
I mean only p is a 8878-by-1 variable vector. H_m is a 8878-by-7410 constant matrix and w_m is a constant number.

Johan Löfberg

unread,
Nov 13, 2020, 12:07:42 PM11/13/20
to YALMIP
Still going to a massive object to create and hold symbollically if h is dense. As I said, are you actually using this matrix, or is it a partial result before doing something else
>> clear all
>> h = randn(250);
>> p = sdpvar(250,1);
>> q = h'*diag(p)*h;
>> whos
  Name        Size                 Bytes  Class     Attributes

  h         250x250               500000  double              
  p         250x1                  10552  sdpvar              
  q         250x250            250006536  sdpvar              





jhua...@hawk.iit.edu

unread,
Nov 13, 2020, 12:13:17 PM11/13/20
to YALMIP
My model is very similar to the D-optimal design convex relaxed problem https://yalmip.github.io/example/experimentdesign/. variable vector p is like variable m in the link.

In this case, am I actually using this matrix, or is it a partial result?

Johan Löfberg

unread,
Nov 13, 2020, 12:25:28 PM11/13/20
to YALMIP
So you intend to solve a 7410x7410 semidefinite program involving 8878 variables? That's just not going to fly

jhua...@hawk.iit.edu

unread,
Nov 13, 2020, 2:38:32 PM11/13/20
to YALMIP
Hi professor,

SDPT3 can work now when replace the matrix vector multiplication with the following for loop,
for i=1: m
      hi=H(i,:);
      A=A+p(i)*hi'*hi;
end.

Thanks,
Jianqiao Huang

Johan Löfberg

unread,
Nov 13, 2020, 3:23:47 PM11/13/20
to YALMIP
That loop has to be absolutely awfully slow, as it will manipulate an increasingly complex object. Some recursive calls at least to avoid that. THe last method below has roughly the same time as H'*diag(p)*H

m = 300;
H = randn(m);
p = sdpvar(m,1);
tic
A = 0;
for i=1:m
    hi = H(i,:);
    A = A+p(i)*hi'*hi;
end
toc
tic
A = recursivesum1(H,p)
toc
tic
A = recursivesum2(H,p)
toc


function B = recursivesum1(A,p)

if length(p) > 10
    n = ceil(length(p)/2);
    B1 = recursivesum1(A(1:n,:),p(1:n));
    B2 = recursivesum1(A(n+1:end,:),p(n+1:end));
    B = B1 + B2;
else
    B = 0;
    for i = 1:length(p)       
        B = B+p(i)*A(i,:)'*A(i,:);
    end
end
    


function B = recursivesum2(A,p)

if length(p) > 10
    n = ceil(length(p)/2);
    B1 = recursivesum2(A(1:n,:),p(1:n));
    B2 = recursivesum2(A(n+1:end,:),p(n+1:end));
    B = B1 + B2;
else
    B = A'*diag(p)*A;   
end
    

Reply all
Reply to author
Forward
0 new messages