Home > manopt > tools > checkmanifold.m

checkmanifold

PURPOSE ^

Run a collection of tests on a manifold obtained from a manopt factory

SYNOPSIS ^

function checkmanifold(M)

DESCRIPTION ^

 Run a collection of tests on a manifold obtained from a manopt factory
 
 function checkmanifold(M)

 M should be a manifold structure obtained from a Manopt factory. This
 tool runs a collection of tests on M to verify (to some extent) that M is
 indeed a valid description of a Riemannian manifold.

 This tool is work in progress: your suggestions for additional tests are
 welcome on our forum.

 See also: checkretraction

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function checkmanifold(M)
0002 % Run a collection of tests on a manifold obtained from a manopt factory
0003 %
0004 % function checkmanifold(M)
0005 %
0006 % M should be a manifold structure obtained from a Manopt factory. This
0007 % tool runs a collection of tests on M to verify (to some extent) that M is
0008 % indeed a valid description of a Riemannian manifold.
0009 %
0010 % This tool is work in progress: your suggestions for additional tests are
0011 % welcome on our forum.
0012 %
0013 % See also: checkretraction
0014 
0015 % This file is part of Manopt: www.manopt.org.
0016 % Original author: Nicolas Boumal, Aug. 31, 2018.
0017 % Contributors:
0018 % Change log:
0019 
0020     assert(isstruct(M), 'M must be a structure.');
0021     
0022     %% List required fields that must be function handles here
0023     list_of_functions = {'name', 'dim', 'inner', 'norm', 'typicaldist', ...
0024                          'proj', 'tangent', 'egrad2rgrad', 'retr', ...
0025                          'rand', 'randvec', 'zerovec', 'lincomb'};
0026     for k = 1 : numel(list_of_functions)
0027         field = list_of_functions{k};
0028         if ~(isfield(M, field) && isa(M.(field), 'function_handle'))
0029             fprintf('M.%s must be a function handle.\n', field);
0030         end
0031     end
0032     
0033     %% List recommended fields that should be function handles here
0034     list_of_functions = {'dist', 'ehess2rhess', 'exp', 'log', 'hash', ...
0035                          'transp', 'pairmean', 'vec', 'mat', ...
0036                          'vecmatareisometries'};
0037     for k = 1 : numel(list_of_functions)
0038         field = list_of_functions{k};
0039         if ~(isfield(M, field) && isa(M.(field), 'function_handle'))
0040             fprintf('M.%s should be a function handle.\n', field);
0041         end
0042     end
0043     
0044     %% Checking exp and dist
0045     try
0046         x = M.rand();
0047         v = M.randvec(x);
0048         t = randn(1);
0049         y = M.exp(x, v, t);
0050         d = M.dist(x, y);
0051         fprintf('dist(x, M.exp(x, v, t)) - abs(t)*M.norm(x, v) = %g (should be zero)\n', d - abs(t)*M.norm(x, v));
0052     catch up %#ok<NASGU>
0053         fprintf('Couldn''t check exp and dist.\n');
0054         % Perhaps we want to rethrow(up) ?
0055     end
0056 
0057 end
0058

Generated on Mon 10-Sep-2018 11:48:06 by m2html © 2005