on in Gr(n,p)

65 views
Skip to first unread message

ckb

unread,
Dec 4, 2014, 4:25:04 AM12/4/14
to manopt...@googlegroups.com
Hi,
I am trying to find a new subspace X (nXm) matrix by minimizing the distance between X and the 2 already existing sub spaces again in the form of orthogonal matrices say Y and Z. I have distance function in the Grassmannian.
Can you help me how to go about it? It would be very useful to me.

Thanks a lot.
kripa

BM

unread,
Dec 4, 2014, 11:56:36 AM12/4/14
to
Hello Kripa,

What seems to be the problem? I guess, you are enquiring of the Manopt format. If that is so, lets say that the cost function is f(X) and its partial derivative is g(X). I hope that you have those expressions. Also assume that we are working with matrices of size nxp. The sample code looks like this.

Gr = grassmannfactory(n, p);
problem.M = Gr;
problem.cost = @(X)    f(X);
problem.egrad = @(X)    g(X);

Xsol = trustregions(problem);

Does this help?

Regards,
BM

ckb

unread,
Dec 5, 2014, 1:50:42 AM12/5/14
to manopt...@googlegroups.com
Thanks BM, for the reply. I am new to matlab. 
The things is if the known matrices Y and Z in the cost function are of different dimensions and the matrix to be found X is of dimension either of Y or Z.
What dimension would I choose the grassmannfactory of?.

Thanks .
ckb

ckb

unread,
Dec 5, 2014, 4:20:42 AM12/5/14
to manopt...@googlegroups.com
When I try to run

Gr = grassmannfactory(34, 3);
problem.M = Gr;
problem.cost = @(X) -trace(X*X'*X1*X1'+X*X'*JS_X1*JS_X1')+max(l,k);
problem.egrad = @(X)    2*(X1*X1'+JS_X1*JS_X1')*X;

Xsol = trustregions(problem);

 it shows the following error:


Error: File: canGetCost.m Line: 1 Column: 31
Unexpected MATLAB expression.

Error in trustregions (line 229)
if ~canGetCost(problem)

Please help  me.
kripa

Nicolas Boumal

unread,
Dec 5, 2014, 5:35:19 AM12/5/14
to manopt...@googlegroups.com
Hello ckb,

I do not understand the mathematical problem you are trying to solve.

Could you please give us more context?

Could you also tell us which version of Matlab you are running? (type "version" in the command prompt.)

Best,
Nicolas

ckb

unread,
Dec 5, 2014, 5:46:28 AM12/5/14
to manopt...@googlegroups.com
the version is 8.1.0.604 (R2013a).

ckb

unread,
Dec 5, 2014, 5:57:26 AM12/5/14
to manopt...@googlegroups.com
Hi,
 I try to minimize the cost function on Grassmannian;
-trace(X*X'*A*A''+X*X'*B*B')+max(l,k);
 where A, B are known rectangular matrices.


This is the mathematical version.

A=X1;
B=JS_X1;
X=rand(34,3);

Gr = grassmannfactory(34, 3);
problem.M = Gr;
problem.cost = @(X) -trace(X*X'*A*A'+X*X'*B*B')+max(l,k);
problem.egrad = @(X)    2*(A*A'+B*B')*X;
Xsol = trustregions(-trace(X*X'*A*A'+X*X'*B*B')+max(l,k));

the following error is shown:

Error in canGetCost (line 5)
  candoit = canGetCost( -trace(X*X'*A*A'+X*X'*B*B')+max(l,k));

Sorry that I am not good at coding .




BM

unread,
Dec 5, 2014, 12:31:12 PM12/5/14
to
[Edit: Typo corrected in the code]

Kripa, I am sorry but there seems to be some confusion, already pointed out by Nicolas. We will try to resolve it step by step. For the moment let us first clear the cost function.

Your cost has two parts -trace(X'*A*A'*X) - trace(X'*B*B'*X) and max(I, k). The trace part is indeed on the Grassmann manifold, but what is the second part max(I,K)? Does it depend on X as well? What are I and K? 

In case max(I,K) does not depend on X, then the following code is what are you looking for. Also note that the number of columns of X, A , B need not be same. This should also remove some confusion.


% n and p are the dimensions of X.
n = 34;          % Your input
p = 3;           % Your input

% Let us say that A has the dimensions n and r, and B has the dimensions n and q. 
r = 5; 
q = 8;

A = randn(n, r);        % Your rectangular matrix X1. For the moment, we create a random matrix.
B = randn(n, q);        % Your rectangular matrix JS_X1. For the moment, we create a random matrix.

Gr = grassmannfactory(n, p);
problem.M = Gr;
problem.cost = @(X)    -trace(X'*A*A'*X) - trace(X'*B*B'*X);
problem.egrad = @(X)   -2*( A*(A'*X) +  B*(B'*X));

Xsol = trustregions(problem);


Let us know if you have any other query? 

Regards,
BM




Nicolas Boumal

unread,
Dec 5, 2014, 4:50:19 PM12/5/14
to manopt...@googlegroups.com
Thanks, Bamdev! I was wondering the same as you about the "max" part.

There is just a slight typo with your code: the cost and egrad should read as follows (mind the signs):

problem.cost = @(X)    -trace(X'*A*A'*X + X'*B*B'*X);
problem.egrad = @(X)   -2*( A*(A'*X) +  B*(B'*X));

Cheers,
Nicolas

ckb

unread,
Dec 5, 2014, 5:46:49 PM12/5/14
to manopt...@googlegroups.com
I am sorry for the confusion but the max part is just a scalar quantity. it is just max(l,k) "small L'' and not I. Very sorry. It is like I need not bring that into my minimisation function, right? Normally in my problem the number of columns of the input matrices Y and Z differ say k1 and k2 respectively and that difference is made out in the term max(k1,k2).

Hope this makes it  clear  now.


Thanks for your response.

ckb

unread,
Dec 6, 2014, 1:03:24 AM12/6/14
to manopt...@googlegroups.com
Thank you very much for your help. It would not have been possible without your support. 

I now encounter another problem. It says the recursion limit is reached. When I try to change the recursion limit from 50 to 500, the code is working.

But after that it started crashing. Is there any other way to overcome this problem?
ckb


BM

unread,
Dec 6, 2014, 1:26:19 AM12/6/14
to manopt...@googlegroups.com
Strange. I don't recall any recursion limit in the Manopt toolbox. Could you show the full error? Also, could you make sure that the problem is related to the Manopt toolbox and not any other codes that you may be using.

ckb

unread,
Dec 6, 2014, 5:35:17 AM12/6/14
to manopt...@googlegroups.com
If I comment on the 

canCetCost  in the trustregions code, it is working. but can I do that?

Nicolas Boumal

unread,
Dec 6, 2014, 6:46:07 AM12/6/14
to manopt...@googlegroups.com
Well, it would be fine to comment that line, but it's very weird that it seems you have to.

Could you show us the full code you are executing? This is the first time we see something like that.

Could you also type "which spherefactory" and "which canGetCost" in the command prompt and tell us what it displays?

Thanks,
Nicolas

ckb

unread,
Dec 6, 2014, 8:28:34 AM12/6/14
to manopt...@googlegroups.com


I am attaching the input values A and B which I got it from the main program.   The next step in my code is to find the value of X that minimizes the distance between X&A as well as X&B.  

This is the part I used with your help.


importmanopt;
% n and p are the dimensions of X.
n = 34;          % Your input
p = 3;           % Your input



% Let us say that A has the dimensions n and r, and B has the dimensions n and q. 
r = 5; 
q = 8;

%A = randn(n, r);        % Your rectangular matrix X1. For the moment, we create a random matrix.
%B = randn(n, q);        % Your rectangular matrix JS_X1. For the moment, we create a random matrix.
Gr = grassmannfactory(n,p);
problem.M = Gr;
problem.cost = @(X) -trace(X'*A*A'*X+X'*B*B'*X);
problem.egrad = @(X)   -2*( A*(A'*X)+ B*(B'*X));
 set(0,'RecursionLimit',500);
 %set(0,'RecursionLimit',1100)
Xsol = trustregions(problem,[]);

Again thanks for your help so far.
myobjfun1_manopt.m.txt
X1.xlsx

Nicolas Boumal

unread,
Dec 7, 2014, 5:59:54 PM12/7/14
to manopt...@googlegroups.com

ckb

unread,
Dec 7, 2014, 10:27:14 PM12/7/14
to manopt...@googlegroups.com

which spherefactory:
\manopt\manopt\manifolds\sphere\spherefactory.m

which cangetcost:

\manopt\manopt\privatetools\canGetCost.m
Hope this would help.

ckb

unread,
Dec 8, 2014, 12:09:57 AM12/8/14
to manopt...@googlegroups.com
It is working fine. Thank you so much for your help.
kripa

Nicolas Boumal

unread,
Dec 8, 2014, 3:24:52 PM12/8/14
to manopt...@googlegroups.com
Happy to hear that it's working, thanks for letting us know! Do you know what happened? Did you have to do anything special to make it work?

Best,
Nicolas

ckb

unread,
Dec 9, 2014, 12:05:37 AM12/9/14
to manopt...@googlegroups.com
No. Nothing special. I removed manopt and then downloaded in a separate directory then tried to run the code. It worked.

Thanks a lot.

Reply all
Reply to author
Forward
0 new messages