Returns a hint for line-search algorithms. function t = getLinesearch(problem, x, d) function t = getLinesearch(problem, x, d, storedb) function t = getLinesearch(problem, x, d, storedb, key) For a line-search problem at x along the tangent direction d, computes and returns t such that retracting t*d at x yields a good point around where to look for a line-search solution. That is: t is a hint as to "how far to look" along the line. storedb is a StoreDB object, key is the StoreDB key to point x. See also: canGetLinesearch
0001 function t = getLinesearch(problem, x, d, storedb, key) 0002 % Returns a hint for line-search algorithms. 0003 % 0004 % function t = getLinesearch(problem, x, d) 0005 % function t = getLinesearch(problem, x, d, storedb) 0006 % function t = getLinesearch(problem, x, d, storedb, key) 0007 % 0008 % For a line-search problem at x along the tangent direction d, computes 0009 % and returns t such that retracting t*d at x yields a good point around 0010 % where to look for a line-search solution. That is: t is a hint as to 0011 % "how far to look" along the line. 0012 % 0013 % storedb is a StoreDB object, key is the StoreDB key to point x. 0014 % 0015 % See also: canGetLinesearch 0016 0017 % This file is part of Manopt: www.manopt.org. 0018 % Original author: Nicolas Boumal, July 17, 2014. 0019 % Contributors: 0020 % Change log: 0021 % 0022 % April 3, 2015 (NB): 0023 % Works with the new StoreDB class system. 0024 0025 % Allow omission of the key, and even of storedb. 0026 if ~exist('key', 'var') 0027 if ~exist('storedb', 'var') 0028 storedb = StoreDB(); 0029 end 0030 key = storedb.getNewKey(); 0031 end 0032 0033 0034 if isfield(problem, 'linesearch') 0035 %% Compute the line-search hint function using linesearch. 0036 0037 % Check whether this function wants to deal with storedb or not. 0038 switch nargin(problem.linesearch) 0039 case 2 0040 t = problem.linesearch(x, d); 0041 case 3 0042 % Obtain, pass along, and save the store for x. 0043 store = storedb.getWithShared(key); 0044 [t, store] = problem.linesearch(x, d, store); 0045 storedb.setWithShared(store, key); 0046 case 4 0047 % Pass along the whole storedb (by reference), with key. 0048 t = problem.linesearch(x, d, storedb, key); 0049 otherwise 0050 up = MException('manopt:getLinesearch:badfun', ... 0051 'linesearch should accept 2, 3 or 4 inputs.'); 0052 throw(up); 0053 end 0054 0055 else 0056 %% Abandon computing the line-search function. 0057 0058 up = MException('manopt:getLinesearch:fail', ... 0059 ['The problem description is not explicit enough to ' ... 0060 'compute a line-search hint.']); 0061 throw(up); 0062 0063 end 0064 0065 end