Manopt example not working

30 views
Skip to first unread message

AH3

unread,
Mar 20, 2019, 2:55:20 AM3/20/19
to Manopt
Hi there,

I am completely new to Manopt and I tried the first example on my computer. And it just failed unexpectedly. Here is my code and error message. I have no idea why this happened.

Please help me there.

Screen Shot 2019-03-20 at 5.53.01 pm.png

Screen Shot 2019-03-20 at 5.52.40 pm.png

Thanks

Nicolas Boumal

unread,
Mar 20, 2019, 5:16:41 AM3/20/19
to Manopt
Hello,

Could you please share the full script you are executing, and also let us know which version of Matlab you are running? (type version at the command prompt).

Thanks!
Nicolas

AH3

unread,
Mar 20, 2019, 5:35:12 AM3/20/19
to Manopt
Hi Nicolas

I am currently using version 9.4.0.813654 (R2018a). And I tried several times, it now works. But when I try to run the example with 'caching', another problem comes out. 

Here is my script, 

importmanopt

 

n = 1000;

A = randn(n);

A = .5*(A+A.');

 

% Create the problem structure.

manifold = spherefactory(n);

problem.M = manifold;

 

problem.cost = @mycost;       % Cost function

problem.egrad = @myegrad;     % Euclidean gradient of the cost function

 

% Numerically check gradient consistency (optional).

checkgradient(problem);

 

% Solve.

[x, xcost, info, options] = trustregions(problem);

 

 

function [f, store] = mycost(A, x, store)

 

    if ~isfield(store, 'Ax')

        store.Ax = A*x;       % The store memory is associated to a specific x

    end

    Ax = store.Ax;

    

    f = -x'*Ax;               % No need to cache f: cost values are cached 'under the hood'

    

end

 

function [g, store] = myegrad(A, x, store)

 

    % This could be placed in a separate function

    % to avoid code duplication.

    if ~isfield(store, 'Ax')

        store.Ax = A*x;

    end

    Ax = store.Ax;

 

    % Euclidean gradient; this is also cached 'under the hood'.

    g = -2*Ax;

    

end


When I run this, an error message appeared as 'Undefined function or variable 'A'.

Then I added 'A' to the two functions prototype, error message became, 'Undefined operator '*' for input arguments of type 'StoreDB'.'

Thanks for your reply! Much appreciated!

Nicolas Boumal

unread,
Mar 20, 2019, 5:59:13 AM3/20/19
to Manopt
Got it: just use these lines:

problem.cost = @(x, store) mycost(A, x, store);       % Cost function

problem
.egrad = @(x, store) myegrad(A, x, store);     % Euclidean gradient of the cost function


The function handle you place in problem.cost and problem.egrad should (in this case, using the caching system in this way) take 2 inputs. The matrix A cannot be provided by Manopt; it must be provided by you. With the code above, you provide A explicitly, and leave it to Manopt to provide x and store, as it should.

Best,
Nicolas

AH3

unread,
Mar 21, 2019, 12:47:09 AM3/21/19
to Manopt
Thanks Nicolas, 

Just another quick question, when I try to change the default value for solver, I do not know the correct syntax. I have tried 


steepestdescent(problem,[],options.tolgradnorm = 1e-4)


It will not work!

Nicolas Boumal

unread,
Mar 21, 2019, 5:35:25 AM3/21/19
to Manopt
Hello,

Try this:

options = struct(); % this line is optional, but it's good practice.

options.tolgradnorm = 1e-4;

steepestdescent(problem, [], options);



Best,
Nicolas
Reply all
Reply to author
Forward
0 new messages