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).

## CROSS-REFERENCE INFORMATION

This function calls:
• minus MINUS Substraction of two TT/MPS tensors.
• norm NORM Norm of a TT/MPS tensor.
• minus MINUS Substraction of two TT/MPS block-mu tensors.
• norm NORM Norm of a TT/MPS block-mu tensor.
• hashmd5 Computes the MD5 hash of input data.
• matrixlincomb Linear combination function for tangent vectors represented as matrices.
This function is called by:

## 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 %
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 %   Jan. 6, 2017 (NB):
0024 %       M.tangent = M.proj now, instead of being identity. This is notably
0025 %       necessary so that checkgradient will pick up on gradients that do
0026 %       not lie in the appropriate tangent space.
0027
0028     if ~exist('rows_or_cols', 'var') || isempty(rows_or_cols)
0029         rows_or_cols = 'cols';
0030     end
0031
0032     % Define a centering operator: it subtracts the mean column or row.
0033     switch lower(rows_or_cols)
0034         case 'cols'
0035             center = @(X) bsxfun(@minus, X, mean(X, 2));
0036             M.dim = @() m*n - m;
0037         case 'rows'
0038             center = @(X) bsxfun(@minus, X, mean(X, 1));
0039             M.dim = @() m*n - n;
0040         otherwise
0041             error('The third input must be either ''rows'' or ''cols''.');
0042     end
0043
0044     % This is a non-standard function to have in a Manopt manifold.
0045     % It is included because it might be helpful in some situations.
0046     M.center = center;
0047
0048     M.name = @() sprintf('Space of size %d x %d matrices with centered %s', ...
0049                          m, n, lower(rows_or_cols));
0050
0051     M.inner = @(x, d1, d2) d1(:).'*d2(:);
0052
0053     M.norm = @(x, d) norm(d, 'fro');
0054
0055     M.dist = @(x, y) norm(x-y, 'fro');
0056
0057     M.typicaldist = @() sqrt(M.dim());
0058
0059     M.proj = @(x, d) center(d);
0060
0062
0063     M.ehess2rhess = @(x, eg, eh, d) center(eh);
0064
0065     M.tangent = M.proj;
0066
0067     M.exp = @exp;
0068     function y = exp(x, d, t)
0069         if nargin == 3
0070             y = x + t*d;
0071         else
0072             y = x + d;
0073         end
0074     end
0075
0076     M.retr = M.exp;
0077
0078     M.log = @(x, y) y-x;
0079
0080     M.hash = @(x) ['z' hashmd5(x(:))];
0081
0082     M.randvec = @(X) randvec();
0083     function U = randvec()
0084         U = center(randn(m, n));
0085         U = U / norm(U, 'fro');
0086     end
0087
0088     M.rand = @() center(randn(m, n));
0089
0090     M.lincomb = @matrixlincomb;
0091
0092     M.zerovec = @(x) zeros(m, n);
0093
0094     M.transp = @(x1, x2, d) d;
0095
0096     M.pairmean = @(x1, x2) .5*(x1+x2);
0097
0098     M.vec = @(x, u_mat) u_mat(:);
0099     M.mat = @(x, u_vec) reshape(u_vec, [m, n]);
0100     M.vecmatareisometries = @() true;
0101
0102 end

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