Home > manopt > manifolds > euclidean > centeredmatrixfactory.m

centeredmatrixfactory

PURPOSE ^

Linear manifold struct. for optimization over matrices with centered cols

SYNOPSIS ^

function M = centeredmatrixfactory(m, n, rows_or_cols)

DESCRIPTION ^

 Linear manifold struct. for optimization over matrices with centered cols

 function M = centeredmatrixfactory(m, n)
 function M = centeredmatrixfactory(m, n, 'cols')
 function M = centeredmatrixfactory(m, n, 'rows')

 Returns M, a structure for Manopt describing the Euclidean space of
 m-by-n matrices whose columns sum to zero (or whose rows sum to zero,
 if 'rows' is passed as last input).

 The metric is the standard Frobenius distance and associated trace inner
 product. Matrices on M, denoted by X, have size mxn and obey
 X*ones(n, 1) = 0 (centered columns) or ones(1, m)*X = 0 (centered rows).

 See also: euclideanfactory

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function M = centeredmatrixfactory(m, n, rows_or_cols)
0002 % Linear manifold struct. for optimization over matrices with centered cols
0003 %
0004 % function M = centeredmatrixfactory(m, n)
0005 % function M = centeredmatrixfactory(m, n, 'cols')
0006 % function M = centeredmatrixfactory(m, n, 'rows')
0007 %
0008 % Returns M, a structure for Manopt describing the Euclidean space of
0009 % m-by-n matrices whose columns sum to zero (or whose rows sum to zero,
0010 % if 'rows' is passed as last input).
0011 %
0012 % The metric is the standard Frobenius distance and associated trace inner
0013 % product. Matrices on M, denoted by X, have size mxn and obey
0014 % X*ones(n, 1) = 0 (centered columns) or ones(1, m)*X = 0 (centered rows).
0015 %
0016 % See also: euclideanfactory
0017 
0018 % This file is part of Manopt: www.manopt.org.
0019 % Original author: Nicolas Boumal, July 3, 2015.
0020 % Contributors:
0021 % Change log:
0022 
0023     if ~exist('rows_or_cols', 'var') || isempty(rows_or_cols)
0024         rows_or_cols = 'cols';
0025     end
0026     
0027     % Define a centering operator: it subtracts the mean column or row.
0028     switch lower(rows_or_cols)
0029         case 'cols'
0030             center = @(X) bsxfun(@minus, X, mean(X, 2));
0031             M.dim = @() m*n - m;
0032         case 'rows'
0033             center = @(X) bsxfun(@minus, X, mean(X, 1));
0034             M.dim = @() m*n - n;
0035         otherwise
0036             error('The third input must be either ''rows'' or ''cols''.');
0037     end
0038     
0039     % This is a non-standard function to have in a Manopt manifold.
0040     % It is included because it might be helpful in some situations.
0041     M.center = center;
0042 
0043     M.name = @() sprintf('Space of size %d x %d matrices with centered %s', ...
0044                          m, n, lower(rows_or_cols));
0045     
0046     M.inner = @(x, d1, d2) d1(:).'*d2(:);
0047     
0048     M.norm = @(x, d) norm(d, 'fro');
0049     
0050     M.dist = @(x, y) norm(x-y, 'fro');
0051     
0052     M.typicaldist = @() sqrt(M.dim());
0053     
0054     M.proj = @(X, U) center(U);
0055     
0056     M.egrad2rgrad = M.proj;
0057     
0058     M.ehess2rhess = @(x, eg, eh, d) center(eh);
0059     
0060     M.tangent = @(x, d) d;
0061     
0062     M.exp = @exp;
0063     function y = exp(x, d, t)
0064         if nargin == 3
0065             y = x + t*d;
0066         else
0067             y = x + d;
0068         end
0069     end
0070     
0071     M.retr = M.exp;
0072     
0073     M.log = @(x, y) y-x;
0074 
0075     M.hash = @(x) ['z' hashmd5(x(:))];
0076     
0077     M.randvec = @(X) randvec();
0078     function U = randvec()
0079         U = center(randn(m, n));
0080         U = U / norm(U, 'fro');
0081     end
0082     
0083     M.rand = @() center(randn(m, n));
0084     
0085     M.lincomb = @matrixlincomb;
0086     
0087     M.zerovec = @(x) zeros(m, n);
0088     
0089     M.transp = @(x1, x2, d) d;
0090     
0091     M.pairmean = @(x1, x2) .5*(x1+x2);
0092     
0093     M.vec = @(x, u_mat) u_mat(:);
0094     M.mat = @(x, u_vec) reshape(u_vec, [m, n]);
0095     M.vecmatareisometries = @() true;
0096 
0097 end

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