A basic example that shows how to define the cost funtion for optimization problems on complex manifolds. Note that automatic differentiation for complex numbers is not supported for Matlab R2021a or earlier. To fully exploit the convenience of AD, please update to the latest version if possible. If the user cannot have access to Matlab R2021b or later, manopt provides an alternative way to deal with complex problems which requires the user to define the cost funtion using the basic functions listed in the folder /functions_AD or to define their own functions following the rules described in that file. See the following as an example. See also: manoptADhelp

- cprod Computes the product of A and B
- creal Extracts the real part of x
- ctransp Computes the conjugate-transpose of X
- manoptAD Preprocess automatic differentiation for a manopt problem structure
- spherecomplexfactory Returns a manifold struct to optimize over unit-norm complex matrices.
- trustregions Riemannian trust-regions solver for optimization on manifolds.
- checkgradient Checks the consistency of the cost function and the gradient.
- checkhessian Checks the consistency of the cost function and the Hessian.

0001 function complex_example_AD() 0002 % A basic example that shows how to define the cost funtion for 0003 % optimization problems on complex manifolds. 0004 % 0005 % Note that automatic differentiation for complex numbers is not supported 0006 % for Matlab R2021a or earlier. To fully exploit the convenience of AD, 0007 % please update to the latest version if possible. If the user cannot have 0008 % access to Matlab R2021b or later, manopt provides an alternative way to 0009 % deal with complex problems which requires the user to define the cost 0010 % funtion using the basic functions listed in the folder /functions_AD or 0011 % to define their own functions following the rules described in that file. 0012 % See the following as an example. 0013 % 0014 % See also: manoptADhelp 0015 0016 % This file is part of Manopt and is copyrighted. See the license file. 0017 % 0018 % Main author: Xiaowen Jiang, August, 31, 2021 0019 % Contributors: Nicolas Boumal 0020 % Change log: 0021 % 0022 0023 % Verify that the deep learning tool box was installed 0024 assert(exist('dlarray', 'file') == 2, ['Deep learning tool box is '... 0025 'needed for automatic differentiation.\n Please install the'... 0026 'latest version of the deep learning tool box and \nupgrade to Matlab'... 0027 ' R2021b if possible.']) 0028 0029 % Generate the problem data. 0030 n = 100; 0031 A = randn(n, n) + 1i*randn(n, n); 0032 A = .5*(A+A'); 0033 0034 % Create the problem structure. 0035 S = spherecomplexfactory(n); 0036 problem.M = S; 0037 0038 % Define the problem cost function 0039 % For Matlab R2021b or later, define the problem cost function as usual 0040 % problem.cost = @(X) -.5*real(X'*A*X); 0041 0042 % For Matlab R2021a or earlier, translate the cost function into a 0043 % particular format with the basic functions in /functions_AD 0044 problem.cost = @(X) -creal(cprod(cprod(ctransp(X), A), X)); 0045 0046 % Define the gradient and the hessian via automatic differentiation 0047 problem = manoptAD(problem); 0048 0049 % Numerically check gradient and Hessian consistency. 0050 figure; 0051 checkgradient(problem); 0052 figure; 0053 checkhessian(problem); 0054 0055 % Solve. 0056 [x, xcost, info] = trustregions(problem); %#ok<ASGLU> 0057 0058 % Display some statistics. 0059 figure; 0060 semilogy([info.iter], [info.gradnorm], '.-'); 0061 xlabel('Iteration #'); 0062 ylabel('Gradient norm'); 0063 title(['Convergence of the trust-regions algorithm on the'... 0064 'complex sphere power manifold']); 0065 0066 end

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