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
essential_ehessE2ehess that convert these ingredients to their R1/R2
counterparts.

essential_ehessE2ehess

## CROSS-REFERENCE INFORMATION

This function calls:
• essential_costE2cost Cost evaluation at X given function handle in the Essential matrix E.
• essential_ehessE2ehess Converts the Hessian in essential matrix E to the Hessian in X.
• essential_hat3 Compute the matrix representation of the cross product
• essentialfactory Manifold structure to optimize over the space of essential matrices.
• randrot Generates uniformly random rotation matrices.
• trustregions Riemannian trust-regions solver for optimization on manifolds.
• multiprod Matrix multiply 2-D slices of N-D arrays
• multisqnorm Returns the squared Frobenius norms of the slices of a 3D matrix.
This function is called by:

## 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
0013 % essential_ehessE2ehess that convert these ingredients to their R1/R2
0014 % counterparts.
0015 %
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
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
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
0061
0062     % Numerically check the differentials.
0073 end