Home > manopt > tools > checkretraction.m

checkretraction

PURPOSE ^

Check the order of agreement of a retraction with an exponential.

SYNOPSIS ^

function checkretraction(M, x, v)

DESCRIPTION ^

 Check the order of agreement of a retraction with an exponential.
 
 function checkretraction(problem)
 function checkretraction(problem, x)
 function checkretraction(problem, x, v)

 checkretraction performs a numerical test to check the order of agreement
 between the retraction and the exponential map in a given Manopt
 manifold structure M. The test is performed at the point x if it is
 provided (otherwise, the point is picked at random) and along the tangent
 vector v at x if one is provided (otherwise, a tangent vector at x is
 picked at random.)

 See also: checkdiff checkgradient checkhessian

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function checkretraction(M, x, v)
0002 % Check the order of agreement of a retraction with an exponential.
0003 %
0004 % function checkretraction(problem)
0005 % function checkretraction(problem, x)
0006 % function checkretraction(problem, x, v)
0007 %
0008 % checkretraction performs a numerical test to check the order of agreement
0009 % between the retraction and the exponential map in a given Manopt
0010 % manifold structure M. The test is performed at the point x if it is
0011 % provided (otherwise, the point is picked at random) and along the tangent
0012 % vector v at x if one is provided (otherwise, a tangent vector at x is
0013 % picked at random.)
0014 %
0015 % See also: checkdiff checkgradient checkhessian
0016 
0017 % This file is part of Manopt: www.manopt.org.
0018 % Original author: Nicolas Boumal, Oct. 21, 2016.
0019 % Contributors:
0020 % Change log:
0021 
0022     if ~exist('x', 'var') || isempty(x)
0023         x = M.rand();
0024         v = M.randvec(x);
0025     end
0026     
0027     if ~exist('v', 'var') || isempty(v)
0028         v = M.randvec(x);
0029     end
0030     
0031     % Compare the retraction and the exponential over steps of varying
0032     % length, on a wide log-scale.
0033     tt = logspace(-12, 0, 251);
0034     ee = zeros(size(tt));
0035     for k = 1 : numel(tt)
0036         t = tt(k);
0037         ee(k) = M.dist(M.exp(x, v, t), M.retr(x, v, t));
0038     end
0039     
0040     % Plot the difference between the exponential and the retration over
0041     % that span of steps, in log-log scale.
0042     loglog(tt, ee);
0043     
0044     % We hope to see a slope of 3, to confirm a second-order retraction. If
0045     % the slope is only 2, we have a first-order retration. If the slope is
0046     % less than 2, this is not a retraction.
0047     % Slope 3
0048     line('xdata', [1e-12 1e0], 'ydata', [1e-30 1e6], ...
0049          'color', 'k', 'LineStyle', '--', ...
0050          'YLimInclude', 'off', 'XLimInclude', 'off');
0051     % Slope 2
0052     line('xdata', [1e-14 1e0], 'ydata', [1e-20 1e8], ...
0053          'color', 'k', 'LineStyle', ':', ...
0054          'YLimInclude', 'off', 'XLimInclude', 'off');
0055      
0056 
0057     % Figure out the slope of the error in log-log, by identifying a piece
0058     % of the error curve which is mostly linear.
0059     window_len = 10;
0060     [range, poly] = identify_linear_piece(log10(tt), log10(ee), window_len);
0061     hold all;
0062     loglog(tt(range), 10.^polyval(poly, log10(tt(range))), 'LineWidth', 3);
0063     hold off;
0064     
0065     xlabel('Step size multiplier t');
0066     ylabel('Distance between Exp(x, v, t) and Retr(x, v, t)');
0067     title(sprintf('Retraction check.\nA slope of 2 is required, 3 is desired.'));
0068     
0069     fprintf('Check agreement between M.exp and M.retr. Please check the\n');
0070     fprintf('factory file of M to ensure M.exp is a proper exponential.\n');
0071     fprintf('The slope must be at least 2 to have a proper retraction.\n');
0072     fprintf('For the retraction to be second order, the slope should be 3.\n');
0073     fprintf('It appears the slope is: %g.\n', poly(1));
0074 
0075 end

Generated on Sat 12-Nov-2016 14:11:22 by m2html © 2005