Home > manopt > core > getPartialEuclideanGradient.m

getPartialEuclideanGradient

PURPOSE ^

Computes the Euclidean gradient of a subset of terms in cost function.

SYNOPSIS ^

function egrad = getPartialEuclideanGradient(problem, x, I, storedb, key)

DESCRIPTION ^

 Computes the Euclidean gradient of a subset of terms in cost function.

 function egrad = getPartialEuclideanGradient(problem, x, I)
 function egrad = getPartialEuclideanGradient(problem, x, I, storedb)
 function egrad = getPartialEuclideanGradient(problem, x, I, storedb, key)

 Assume the cost function described in the problem structure is a sum of
 many terms, as

    f(x) = sum_i f_i(x) for i = 1:d,

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function egrad = getPartialEuclideanGradient(problem, x, I, storedb, key)
0002 % Computes the Euclidean gradient of a subset of terms in cost function.
0003 %
0004 % function egrad = getPartialEuclideanGradient(problem, x, I)
0005 % function egrad = getPartialEuclideanGradient(problem, x, I, storedb)
0006 % function egrad = getPartialEuclideanGradient(problem, x, I, storedb, key)
0007 %
0008 % Assume the cost function described in the problem structure is a sum of
0009 % many terms, as
0010 %
0011 %    f(x) = sum_i f_i(x) for i = 1:d,
0012 
0013 % where d is specified as d = problem.ncostterms.
0014 %
0015 % For a subset I of 1:d, getPartialEuclideanGradient obtains the Euclidean
0016 % gradient of the partial cost function
0017 %
0018 %    f_I(x) = sum_i f_i(x) for i = I.
0019 %
0020 % storedb is a StoreDB object, key is the StoreDB key to point x.
0021 %
0022 % See also: getGradient canGetPartialEuclidean Gradient getPartialGradient
0023 
0024 % This file is part of Manopt: www.manopt.org.
0025 % Original author: Nicolas Boumal, June 28, 2016
0026 % Contributors:
0027 % Change log:
0028 
0029 
0030     % Allow omission of the key, and even of storedb.
0031     if ~exist('key', 'var')
0032         if ~exist('storedb', 'var')
0033             storedb = StoreDB();
0034         end
0035         key = storedb.getNewKey();
0036     end
0037     
0038     % Make sure I is a row vector, so that it is natural to loop over it
0039     % with " for i = I ".
0040     I = (I(:)).';
0041     
0042     
0043     if isfield(problem, 'partialegrad')
0044     %% Compute the partial Euclidean gradient using partialegrad.
0045     
0046         % Check whether this function wants to deal with storedb or not.
0047         switch nargin(problem.partialegrad)
0048             case 2
0049                 egrad = problem.partialegrad(x, I);
0050             case 3
0051                 % Obtain, pass along, and save the store for x.
0052                 store = storedb.getWithShared(key);
0053                 [egrad, store] = problem.partialegrad(x, I, store);
0054                 storedb.setWithShared(store, key);
0055             case 4
0056                 % Pass along the whole storedb (by reference), with key.
0057                 egrad = problem.partialegrad(x, I, storedb, key);
0058             otherwise
0059                 up = MException('manopt:getPartialEuclideanGradient:badpartialegrad', ...
0060                     'partialegrad should accept 2, 3 or 4 inputs.');
0061                 throw(up);
0062         end
0063     
0064     else
0065     %% Abandon computing the partial Euclidean gradient.
0066     
0067         up = MException('manopt:getPartialEuclideanGradient:fail', ...
0068             ['The problem description is not explicit enough to ' ...
0069              'compute the partial Euclidean gradient of the cost.']);
0070         throw(up);
0071         
0072     end
0073     
0074 end

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