Home > manopt > core > getPartialEuclideanGradient.m

## PURPOSE

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

## DESCRIPTION

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

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 %
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 %
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
0045
0046         % Check whether this function wants to deal with storedb or not.
0048             case 2
0050             case 3
0051                 % Obtain, pass along, and save the store for x.
0052                 store = storedb.getWithShared(key);
0054                 storedb.setWithShared(store, key);
0055             case 4
0056                 % Pass along the whole storedb (by reference), with key.
0058             otherwise
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