Computes the directional derivative of the cost function at x along d. function diff = getDirectionalDerivative(problem, x, d) function diff = getDirectionalDerivative(problem, x, d, storedb) function diff = getDirectionalDerivative(problem, x, d, storedb, key) Returns the derivative at x along d of the cost function described in the problem structure. storedb is a StoreDB object, key is the StoreDB key to point x. See also: getGradient canGetDirectionalDerivative

- StoreDB
- canGetGradient Checks whether the gradient can be computed for a problem structure.
- getGradient Computes the gradient of the cost function at x.

- getGradient Computes the gradient of the cost function at x.
- trustregions Riemannian trust-regions solver for optimization on manifolds.
- checkdiff Checks the consistency of the cost function and directional derivatives.

0001 function diff = getDirectionalDerivative(problem, x, d, storedb, key) 0002 % Computes the directional derivative of the cost function at x along d. 0003 % 0004 % function diff = getDirectionalDerivative(problem, x, d) 0005 % function diff = getDirectionalDerivative(problem, x, d, storedb) 0006 % function diff = getDirectionalDerivative(problem, x, d, storedb, key) 0007 % 0008 % Returns the derivative at x along d of the cost function described in the 0009 % problem structure. 0010 % 0011 % storedb is a StoreDB object, key is the StoreDB key to point x. 0012 % 0013 % See also: getGradient canGetDirectionalDerivative 0014 0015 % This file is part of Manopt: www.manopt.org. 0016 % Original author: Nicolas Boumal, Dec. 30, 2012. 0017 % Contributors: 0018 % Change log: 0019 % 0020 % April 3, 2015 (NB): 0021 % Works with the new StoreDB class system. 0022 0023 % Allow omission of the key, and even of storedb. 0024 if ~exist('key', 'var') 0025 if ~exist('storedb', 'var') 0026 storedb = StoreDB(); 0027 end 0028 key = storedb.getNewKey(); 0029 end 0030 0031 0032 if isfield(problem, 'diff') 0033 %% Compute the directional derivative using diff. 0034 0035 % Check whether this function wants to deal with storedb or not. 0036 switch nargin(problem.diff) 0037 case 2 0038 diff = problem.diff(x, d); 0039 case 3 0040 % Obtain, pass along, and save the store for x. 0041 store = storedb.getWithShared(key); 0042 [diff, store] = problem.diff(x, d, store); 0043 storedb.setWithShared(store, key); 0044 case 4 0045 % Pass along the whole storedb (by reference), with key. 0046 diff = problem.diff(x, d, storedb, key); 0047 otherwise 0048 up = MException('manopt:getDirectionalDerivative:baddiff', ... 0049 'diff should accept 2, 3 or 4 inputs.'); 0050 throw(up); 0051 end 0052 0053 elseif canGetGradient(problem) 0054 %% Compute the directional derivative using the gradient. 0055 0056 % Compute the gradient at x, then compute its inner product with d. 0057 grad = getGradient(problem, x, storedb, key); 0058 diff = problem.M.inner(x, grad, d); 0059 0060 else 0061 %% Abandon computing the directional derivative. 0062 0063 up = MException('manopt:getDirectionalDerivative:fail', ... 0064 ['The problem description is not explicit enough to ' ... 0065 'compute the directional derivatives of f.']); 0066 throw(up); 0067 0068 end 0069 0070 end

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