Home > manopt > core > getPrecon.m

# getPrecon

## PURPOSE

Applies the preconditioner for the Hessian of the cost at x along d.

## SYNOPSIS

function Pd = getPrecon(problem, x, d, storedb, key)

## DESCRIPTION

``` Applies the preconditioner for the Hessian of the cost at x along d.

function Pd = getPrecon(problem, x, d)
function Pd = getPrecon(problem, x, d, storedb)
function Pd = getPrecon(problem, x, d, storedb, key)

Returns as Pd the result of applying the Hessian preconditioner to the
tangent vector d at point x. The preconditioner is supposed to be a
symmetric, positive definite approximation of the inverse of the Hessian.

If no preconditioner is available, Pd = d (identity).

storedb is a StoreDB object, key is the StoreDB key to point x.

## CROSS-REFERENCE INFORMATION

This function calls:
This function is called by:
• trs_tCG Truncated (Steihaug-Toint) Conjugate-Gradient method.
• trs_tCG_cached Truncated (Steihaug-Toint) Conjugate-Gradient method with caching.
• hessianspectrum Returns the eigenvalues of the (preconditioned) Hessian at x.

## SOURCE CODE

```0001 function Pd = getPrecon(problem, x, d, storedb, key)
0002 % Applies the preconditioner for the Hessian of the cost at x along d.
0003 %
0004 % function Pd = getPrecon(problem, x, d)
0005 % function Pd = getPrecon(problem, x, d, storedb)
0006 % function Pd = getPrecon(problem, x, d, storedb, key)
0007 %
0008 % Returns as Pd the result of applying the Hessian preconditioner to the
0009 % tangent vector d at point x. The preconditioner is supposed to be a
0010 % symmetric, positive definite approximation of the inverse of the Hessian.
0011 %
0012 % If no preconditioner is available, Pd = d (identity).
0013 %
0014 % storedb is a StoreDB object, key is the StoreDB key to point x.
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, 'precon')
0036     %% Precondition using precon.
0037
0038         % Check whether this function wants to deal with storedb or not.
0039         switch nargin(problem.precon)
0040             case 2
0041                 Pd = problem.precon(x, d);
0042             case 3
0043                 % Obtain, pass along, and save the store for x.
0044                 store = storedb.getWithShared(key);
0045                 [Pd, store] = problem.precon(x, d, store);
0046                 storedb.setWithShared(store, key);
0047             case 4
0048                 % Pass along the whole storedb (by reference), with key.
0049                 Pd = problem.precon(x, d, storedb, key);
0050             otherwise
0052                     'precon should accept 2, 3 or 4 inputs.');
0053                 throw(up);
0054         end
0055
0056     elseif canGetSqrtPrecon(problem)
0057     %% Precondition by applying the square root of the preconditioner twice.
0058
0059         sqrtPd = getSqrtPrecon(problem, x, d, storedb, key);
0060         Pd = getSqrtPrecon(problem, x, sqrtPd, storedb, key);
0061
0062     else
0063     %% No preconditioner provided, so just use the identity.
0064
0065         Pd = d;
0066
0067     end
0068
0069 end```

Generated on Fri 30-Sep-2022 13:18:25 by m2html © 2005