Home > manopt > solvers > neldermead > centroid.m

centroid

PURPOSE ^

Attempts the computation of a centroid of a set of points on a manifold.

SYNOPSIS ^

function y = centroid(M, x)

DESCRIPTION ^

 Attempts the computation of a centroid of a set of points on a manifold.
 
 function y = centroid(M, x)

 M is a structure representing a manifold.
 x is a cell of points on that manifold.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function y = centroid(M, x)
0002 % Attempts the computation of a centroid of a set of points on a manifold.
0003 %
0004 % function y = centroid(M, x)
0005 %
0006 % M is a structure representing a manifold.
0007 % x is a cell of points on that manifold.
0008 
0009 % This file is part of Manopt: www.manopt.org.
0010 % Original author: Nicolas Boumal, Dec. 30, 2012.
0011 % Contributors:
0012 % Change log:
0013 
0014 
0015     % For now, just apply a few steps of gradient descent for Karcher means
0016     
0017     n = numel(x);
0018     
0019     problem.M = M;
0020     
0021     problem.cost = @cost;
0022     function val = cost(y)
0023         val = 0;
0024         for i = 1 : n
0025             val = val + M.dist(y, x{i})^2;
0026         end
0027         val = val/2;
0028     end
0029 
0030     problem.grad = @grad;
0031     function g = grad(y)
0032         g = M.zerovec(y);
0033         for i = 1 : n
0034             g = M.lincomb(y, 1, g, -1, M.log(y, x{i}));
0035         end
0036     end
0037 
0038     % This line can be uncommented to check that the gradient is indeed
0039     % correct. This should always be the case if the dist and the log
0040     % functions in the manifold are correct.
0041     % checkgradient(problem); pause;
0042     
0043     query = warning('query', 'manopt:getHessian:approx');
0044     warning('off', 'manopt:getHessian:approx');
0045     options.verbosity = 0;
0046     options.maxiter = 15;
0047     y = trustregions(problem, x{randi(n)}, options);
0048     warning(query.state, 'manopt:getHessian:approx');
0049 
0050 end

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