Home > examples > essential_svd.m

essential_svd

PURPOSE ^

Sample solution of an optimization problem on the essential manifold.

SYNOPSIS ^

function essential_svd

DESCRIPTION ^

 Sample solution of an optimization problem on the essential manifold.

 Solves the problem \sum_{i=1}^N ||E_i-A_i||^2, where E_i are essential
 matrices. Essential matrices are used in computer vision to represent the
 epipolar constraint between projected points in two perspective views.

 Note: the essentialfactory file uses a quotient R1/R2 representation to
 work with essential matrices. On the other hand, from a user point of 
 view, it is convenient to use the E representation  (a matrix of size
 3-by-3) to give cost, gradient, and Hessian  information. To this end, we
 provide auxiliary files essential_costE2cost, essential_egradE2egrad, and
 essential_ehessE2ehess that convert these ingredients to their R1/R2
 counterparts.

 See also: essentialfactory essential_costE2cost essential_egradE2egrad
 essential_ehessE2ehess

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function essential_svd
0002 % Sample solution of an optimization problem on the essential manifold.
0003 %
0004 % Solves the problem \sum_{i=1}^N ||E_i-A_i||^2, where E_i are essential
0005 % matrices. Essential matrices are used in computer vision to represent the
0006 % epipolar constraint between projected points in two perspective views.
0007 %
0008 % Note: the essentialfactory file uses a quotient R1/R2 representation to
0009 % work with essential matrices. On the other hand, from a user point of
0010 % view, it is convenient to use the E representation  (a matrix of size
0011 % 3-by-3) to give cost, gradient, and Hessian  information. To this end, we
0012 % provide auxiliary files essential_costE2cost, essential_egradE2egrad, and
0013 % essential_ehessE2ehess that convert these ingredients to their R1/R2
0014 % counterparts.
0015 %
0016 % See also: essentialfactory essential_costE2cost essential_egradE2egrad
0017 % essential_ehessE2ehess
0018  
0019 % This file is part of Manopt: www.manopt.org.
0020 % Original author: Roberto Tron, Aug. 8, 2014
0021 % Contributors: Bamdev Mishra, May 15, 2015.
0022 % Change log:
0023 %
0024 %    Xiaowen Jiang Aug. 20, 2021
0025 %       Added AD to compute the egrad and the ehess
0026 
0027     % Make data for the test
0028     N = 2;    % Number of matrices to process in parallel.
0029     A = multiprod(multiprod(randrot(3, N), essential_hat3([0; 0; 1])), randrot(3, N));
0030     
0031     % The essential manifold
0032     M = essentialfactory(N);
0033     problem.M = M;
0034     
0035     % Function handles of the essential matrix E and Euclidean gradient and Hessian
0036     costE  = @(E) 0.5*sum(multisqnorm(E-A));
0037     egradE = @(E) E - A;
0038     ehessE = @(E, U) U;
0039 
0040     
0041     % Manopt descriptions
0042     problem.cost = @cost;
0043     function val = cost(X)
0044         val = essential_costE2cost(X, costE); % Cost
0045     end
0046     
0047     problem.egrad = @egrad;
0048     function g = egrad(X)
0049         g = essential_egradE2egrad(X, egradE); % Converts gradient in E to X.
0050     end
0051     
0052     problem.ehess = @ehess;
0053     function gdot = ehess(X, S)
0054         gdot = essential_ehessE2ehess(X, egradE, ehessE, S); % Converts Hessian in E to X.
0055     end
0056     
0057     % An alternative way to compute the egrad and the ehess is to use
0058     % automatic differentiation provided in the deep learning toolbox (slower)
0059     % call manoptAD to automatically obtain the egrad and the ehess
0060     % problem = manoptAD(problem);
0061     
0062     % Numerically check the differentials.
0063     % checkgradient(problem); pause;
0064     % checkhessian(problem); pause;
0065     
0066     %Solve the problem
0067     Xsol = trustregions(problem);
0068     
0069     % Distance between original matrices and decompositions
0070     val = essential_costE2cost(Xsol, costE);
0071     fprintf('Distance between original matrices and decompositions is %e \n', val);
0072 
0073 end

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