Plot the cost function along a geodesic or a retraction path. function plotprofile(problem) function plotprofile(problem, x) function plotprofile(problem, x, d) function plotprofile(problem, x, d, t) function plotprofile(problem, x, [], t) function plotprofile(problem, [], [], t) function costs = plotprofile(problem, x, d, t) Plot profile evaluates the cost function along a geodesic gamma(t) such that gamma(0) = x and the derivative of gamma at 0 is the direction d. The input t is a vector specifying for which values of t we must evaluate f(gamma(t)) (it may include negative values). If the function is called with an output, the plot is not drawn and the values of the cost are returned for the instants t. If x is omitted, a random point is picked. If d is omitted, a random tangent vector at x is picked. If t is omitted, it is generated as a linspace over [-1, 1].
0001 function cost = plotprofile(problem, x, d, t) 0002 % Plot the cost function along a geodesic or a retraction path. 0003 % 0004 % function plotprofile(problem) 0005 % function plotprofile(problem, x) 0006 % function plotprofile(problem, x, d) 0007 % function plotprofile(problem, x, d, t) 0008 % function plotprofile(problem, x, [], t) 0009 % function plotprofile(problem, [], [], t) 0010 % 0011 % function costs = plotprofile(problem, x, d, t) 0012 % 0013 % Plot profile evaluates the cost function along a geodesic gamma(t) such 0014 % that gamma(0) = x and the derivative of gamma at 0 is the direction d. 0015 % The input t is a vector specifying for which values of t we must evaluate 0016 % f(gamma(t)) (it may include negative values). 0017 % 0018 % If the function is called with an output, the plot is not drawn and the 0019 % values of the cost are returned for the instants t. 0020 % 0021 % If x is omitted, a random point is picked. If d is omitted, a random 0022 % tangent vector at x is picked. If t is omitted, it is generated as a 0023 % linspace over [-1, 1]. 0024 0025 % This file is part of Manopt: www.manopt.org. 0026 % Original author: Nicolas Boumal, Jan. 9, 2013. 0027 % Contributors: 0028 % Change log: 0029 % 0030 % April 3, 2015 (NB): 0031 % Works with the new StoreDB class system. 0032 % 0033 % Nov. 12, 2016 (NB): 0034 % Making more inputs optional. 0035 0036 % Verify that the problem description is sufficient. 0037 if ~canGetCost(problem) 0038 error('It seems no cost was provided.'); 0039 end 0040 0041 if ~exist('x', 'var') || isempty(x) 0042 x = problem.M.rand(); 0043 if exist('d', 'var') && ~isempty(d) 0044 error('If x is omitted, d should not be specified.'); 0045 end 0046 end 0047 if ~exist('d', 'var') || isempty(d) 0048 d = problem.M.randvec(x); 0049 end 0050 if ~exist('t', 'var') || isempty(t) 0051 t = linspace(-1, 1, 101); 0052 end 0053 0054 if isfield(problem.M, 'exp') 0055 expo = problem.M.exp; 0056 str = 'Exp'; 0057 else 0058 expo = problem.M.retr; 0059 str = 'Retr'; 0060 end 0061 0062 storedb = StoreDB(); 0063 linesearch_fun = @(t) getCost(problem, expo(x, d, t), storedb); 0064 0065 cost = zeros(size(t)); 0066 for i = 1 : numel(t) 0067 cost(i) = linesearch_fun(t(i)); 0068 end 0069 0070 if nargout == 0 0071 plot(t, cost); 0072 xlabel('t'); 0073 ylabel(['f(' str '_x(t*d))']); 0074 end 0075 0076 end