Home > manopt > core > applyStatsfun.m

applyStatsfun

PURPOSE ^

Apply the statsfun function to a stats structure (for solvers).

SYNOPSIS ^

function stats = applyStatsfun(problem, x, storedb, key, options, stats)

DESCRIPTION ^

 Apply the statsfun function to a stats structure (for solvers).

 function stats = applyStatsfun(problem, x, storedb, key, options, stats)

 Applies the options.statsfun user supplied function (if it was provided)
 to the stats structure, and returns the (possibly) modified stats
 structure.

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

 Note: if statsfun accepts a store structure as input, this structure can
 be read but not modified (modifications will be lost) ; the store
 structure will contain the store.shared field.

 See also: applyHook

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function stats = applyStatsfun(problem, x, storedb, key, options, stats)
0002 % Apply the statsfun function to a stats structure (for solvers).
0003 %
0004 % function stats = applyStatsfun(problem, x, storedb, key, options, stats)
0005 %
0006 % Applies the options.statsfun user supplied function (if it was provided)
0007 % to the stats structure, and returns the (possibly) modified stats
0008 % structure.
0009 %
0010 % storedb is a StoreDB object, key is the StoreDB key to point x.
0011 %
0012 % Note: if statsfun accepts a store structure as input, this structure can
0013 % be read but not modified (modifications will be lost) ; the store
0014 % structure will contain the store.shared field.
0015 %
0016 % See also: applyHook
0017 
0018 % This file is part of Manopt: www.manopt.org.
0019 % Original author: Nicolas Boumal, April 3, 2013.
0020 % Contributors:
0021 % Change log:
0022 %
0023 %   April 3, 2015 (NB):
0024 %       Works with the new StoreDB class system.
0025 %
0026 %   July 19, 2020 (NB):
0027 %       Creates a field called 'hooked' in stats structures, for applyHook.
0028 
0029     if isfield(options, 'statsfun')
0030         
0031         switch nargin(options.statsfun)
0032             case 3
0033                 stats = options.statsfun(problem, x, stats);
0034             case 4
0035                 % Obtain, pass along, and save the store for x.
0036                 % get/setWithShared must come in pairs.
0037                 store = storedb.getWithShared(key);
0038                 stats = options.statsfun(problem, x, stats, store);
0039                 storedb.setWithShared(store, key);
0040             otherwise
0041                 warning('manopt:statsfun', ...
0042                         'statsfun unused: wrong number of inputs');
0043         end
0044     end
0045     
0046     % Always create a field called 'hooked' for the benefit of applyHook.
0047     % This is to be set to either true or false by applyHook.
0048     stats.hooked = NaN;
0049 
0050 end

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