Home > manopt > core > getHessian.m

getHessian

PURPOSE ^

Computes the Hessian of the cost function at x along d.

SYNOPSIS ^

function hess = getHessian(problem, x, d, storedb, key)

DESCRIPTION ^

 Computes the Hessian of the cost function at x along d.

 function hess = getHessian(problem, x, d)
 function hess = getHessian(problem, x, d, storedb)
 function hess = getHessian(problem, x, d, storedb, key)

 Returns the Hessian 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.

 If an exact Hessian is not provided, an approximate Hessian is returned
 if possible, without warning. If not possible, an exception will be
 thrown. To check whether an exact Hessian is available or not (typically
 to issue a warning if not), use canGetHessian.

 See also: getPrecon getApproxHessian canGetHessian

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function hess = getHessian(problem, x, d, storedb, key)
0002 % Computes the Hessian of the cost function at x along d.
0003 %
0004 % function hess = getHessian(problem, x, d)
0005 % function hess = getHessian(problem, x, d, storedb)
0006 % function hess = getHessian(problem, x, d, storedb, key)
0007 %
0008 % Returns the Hessian 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 % If an exact Hessian is not provided, an approximate Hessian is returned
0014 % if possible, without warning. If not possible, an exception will be
0015 % thrown. To check whether an exact Hessian is available or not (typically
0016 % to issue a warning if not), use canGetHessian.
0017 %
0018 % See also: getPrecon getApproxHessian canGetHessian
0019 
0020 % This file is part of Manopt: www.manopt.org.
0021 % Original author: Nicolas Boumal, Dec. 30, 2012.
0022 % Contributors:
0023 % Change log:
0024 %
0025 %   April 3, 2015 (NB):
0026 %       Works with the new StoreDB class system.
0027 
0028     % Allow omission of the key, and even of storedb.
0029     if ~exist('key', 'var')
0030         if ~exist('storedb', 'var')
0031             storedb = StoreDB();
0032         end
0033         key = storedb.getNewKey();
0034     end
0035     
0036     
0037     if isfield(problem, 'hess')
0038     %% Compute the Hessian using hess.
0039     
0040         % Check whether this function wants to deal with storedb or not.
0041         switch nargin(problem.hess)
0042             case 2
0043                 hess = problem.hess(x, d);
0044             case 3
0045                 % Obtain, pass along, and save the store for x.
0046                 store = storedb.getWithShared(key);
0047                 [hess, store] = problem.hess(x, d, store);
0048                 storedb.setWithShared(store, key);
0049             case 4
0050                 % Pass along the whole storedb (by reference), with key.
0051                 hess = problem.hess(x, d, storedb, key);
0052             otherwise
0053                 up = MException('manopt:getHessian:badhess', ...
0054                     'hess should accept 2, 3 or 4 inputs.');
0055                 throw(up);
0056         end
0057     
0058     elseif isfield(problem, 'ehess') && canGetEuclideanGradient(problem)
0059     %% Compute the Hessian using ehess.
0060     
0061         % We will need the Euclidean gradient for the conversion from the
0062         % Euclidean Hessian to the Riemannian Hessian.
0063         egrad = getEuclideanGradient(problem, x, storedb, key);
0064         
0065         % Check whether this function wants to deal with storedb or not.
0066         switch nargin(problem.ehess)
0067             case 2
0068                 ehess = problem.ehess(x, d);
0069             case 3
0070                 % Obtain, pass along, and save the store for x.
0071                 store = storedb.getWithShared(key);
0072                 [ehess, store] = problem.ehess(x, d, store);
0073                 storedb.setWithShared(store, key);
0074             case 4
0075                 % Pass along the whole storedb (by reference), with key.
0076                 ehess = problem.ehess(x, d, storedb, key);
0077             otherwise
0078                 up = MException('manopt:getHessian:badehess', ...
0079                     'ehess should accept 2, 3 or 4 inputs.');
0080                 throw(up);
0081         end
0082         
0083         % Convert to the Riemannian Hessian
0084         hess = problem.M.ehess2rhess(x, egrad, ehess, d);
0085         
0086     else
0087     %% Attempt the computation of an approximation of the Hessian.
0088         
0089         hess = getApproxHessian(problem, x, d, storedb, key);
0090         
0091     end
0092     
0093 end

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