Home > manopt > core > getApproxHessian.m

# getApproxHessian

## PURPOSE

Computes an approximation of the Hessian of the cost fun. at x along d.

## SYNOPSIS

function approxhess = getApproxHessian(problem, x, d, storedb, key)

## DESCRIPTION

``` Computes an approximation of the Hessian of the cost fun. at x along d.

function approxhess = getApproxHessian(problem, x, d)
function approxhess = getApproxHessian(problem, x, d, storedb)
function approxhess = getApproxHessian(problem, x, d, storedb, key)

Returns an approximation of 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 no approximate Hessian was provided, this call is redirected to
getHessianFD.

## CROSS-REFERENCE INFORMATION

This function calls:
• StoreDB
• getHessianFD Computes an approx. of the Hessian w/ finite differences of the gradient.
This function is called by:
• getHessian Computes the Hessian of the cost function at x along d.

## SOURCE CODE

```0001 function approxhess = getApproxHessian(problem, x, d, storedb, key)
0002 % Computes an approximation of the Hessian of the cost fun. at x along d.
0003 %
0004 % function approxhess = getApproxHessian(problem, x, d)
0005 % function approxhess = getApproxHessian(problem, x, d, storedb)
0006 % function approxhess = getApproxHessian(problem, x, d, storedb, key)
0007 %
0008 % Returns an approximation of the Hessian at x along d of the cost function
0009 % described in the problem structure.
0010 %
0011 % storedb is a StoreDB object, key is the StoreDB key to point x.
0012 %
0013 % If no approximate Hessian was provided, this call is redirected to
0014 % getHessianFD.
0015 %
0017
0018 % This file is part of Manopt: www.manopt.org.
0019 % Original author: Nicolas Boumal, Dec. 30, 2012.
0020 % Contributors:
0021 % Change log:
0022 %
0023 %   April 3, 2015 (NB):
0024 %       Works with the new StoreDB class system.
0025
0026     % Allow omission of the key, and even of storedb.
0027     if ~exist('key', 'var')
0028         if ~exist('storedb', 'var')
0029             storedb = StoreDB();
0030         end
0031         key = storedb.getNewKey();
0032     end
0033
0034
0035     if isfield(problem, 'approxhess')
0036     %% Compute the approximate Hessian using approxhess.
0037
0038         % Check whether this function wants to deal with storedb or not.
0039         switch nargin(problem.approxhess)
0040             case 2
0041                 approxhess = problem.approxhess(x, d);
0042             case 3
0043                 % Obtain, pass along, and save the store for x.
0044                 store = storedb.getWithShared(key);
0045                 [approxhess, store] = problem.approxhess(x, d, store);
0046                 storedb.setWithShared(store, key);
0047             case 4
0048                 % Pass along the whole storedb (by reference), with key.
0049                 approxhess = problem.approxhess(x, d, storedb, key);
0050             otherwise
0052                     'approxhess should accept 2, 3 or 4 inputs.');
0053                 throw(up);
0054         end
0055
0056     else
0057     %% Try to fall back to a standard FD approximation.
0058
0059         approxhess = getHessianFD(problem, x, d, storedb, key);
0060
0061     end
0062
0063 end```

Generated on Mon 10-Sep-2018 11:48:06 by m2html © 2005