#include <ShonanAveraging.h>
Public Types | |
using | Measurements = std::vector< BinaryMeasurement< Rot > > |
using | Parameters = ShonanAveragingParameters< d > |
using | Rot = typename Parameters::Rot |
using | Sparse = Eigen::SparseMatrix< double > |
Public Member Functions | |
template<typename T > | |
std::vector< BinaryMeasurement< T > > | maybeRobust (const std::vector< BinaryMeasurement< T >> &measurements, bool useRobustModel=false) const |
Values | projectFrom (size_t p, const Values &values) const |
Values | projectFrom (size_t p, const Values &values) const |
Values | roundSolutionS (const Matrix &S) const |
Values | roundSolutionS (const Matrix &S) const |
Standard Constructors | |
ShonanAveraging (const Measurements &measurements, const Parameters ¶meters=Parameters()) | |
Query properties | |
size_t | nrUnknowns () const |
Return number of unknowns. More... | |
size_t | numberMeasurements () const |
Return number of measurements. More... | |
const BinaryMeasurement< Rot > & | measurement (size_t k) const |
k^th binary measurement More... | |
Measurements | makeNoiseModelRobust (const Measurements &measurements, double k=1.345) const |
const Rot & | measured (size_t k) const |
k^th measurement, as a Rot. More... | |
const KeyVector & | keys (size_t k) const |
Keys for k^th measurement, as a vector of Key values. More... | |
Basic API | |
double | cost (const Values &values) const |
Values | initializeRandomly (std::mt19937 &rng) const |
Values | initializeRandomly () const |
Random initialization for wrapper, fixed random seed. More... | |
std::pair< Values, double > | run (const Values &initialEstimate, size_t pMin=d, size_t pMax=10) const |
Private Member Functions | |
Sparse | buildD () const |
Build 3Nx3N sparse degree matrix D. More... | |
Sparse | buildQ () const |
Private Attributes | |
Sparse | D_ |
Sparse | L_ |
Measurements | measurements_ |
size_t | nrUnknowns_ |
Parameters | parameters_ |
Sparse | Q_ |
Matrix API (advanced use, debugging) | |
Sparse | computeLambda (const Matrix &S) const |
Version that takes pxdN Stiefel manifold elements. More... | |
Matrix | computeLambda_ (const Values &values) const |
Dense versions of computeLambda for wrapper/testing. More... | |
Matrix | computeLambda_ (const Matrix &S) const |
Dense versions of computeLambda for wrapper/testing. More... | |
Sparse | computeA (const Values &values) const |
Compute A matrix whose Eigenvalues we will examine. More... | |
Sparse | computeA (const Matrix &S) const |
Version that takes pxdN Stiefel manifold elements. More... | |
Matrix | computeA_ (const Values &values) const |
Dense version of computeA for wrapper/testing. More... | |
double | computeMinEigenValue (const Values &values, Vector *minEigenVector=nullptr) const |
double | computeMinEigenValueAP (const Values &values, Vector *minEigenVector=nullptr) const |
Values | roundSolutionS (const Matrix &S) const |
Project pxdN Stiefel manifold matrix S to Rot3^N. More... | |
Matrix | riemannianGradient (size_t p, const Values &values) const |
Calculate the riemannian gradient of F(values) at values. More... | |
Values | initializeWithDescent (size_t p, const Values &values, const Vector &minEigenVector, double minEigenValue, double gradienTolerance=1e-2, double preconditionedGradNormTolerance=1e-4) const |
static Matrix | StiefelElementMatrix (const Values &values) |
Project to pxdN Stiefel manifold. More... | |
static VectorValues | TangentVectorValues (size_t p, const Vector &v) |
Create a VectorValues with eigenvector v_i. More... | |
static Values | LiftwithDescent (size_t p, const Values &values, const Vector &minEigenVector) |
Advanced API | |
NonlinearFactorGraph | buildGraphAt (size_t p) const |
Values | initializeRandomlyAt (size_t p, std::mt19937 &rng) const |
Values | initializeRandomlyAt (size_t p) const |
Version of initializeRandomlyAt with fixed random seed. More... | |
double | costAt (size_t p, const Values &values) const |
Sparse | computeLambda (const Values &values) const |
std::pair< double, Vector > | computeMinEigenVector (const Values &values) const |
bool | checkOptimality (const Values &values) const |
std::shared_ptr< LevenbergMarquardtOptimizer > | createOptimizerAt (size_t p, const Values &initial) const |
Values | tryOptimizingAt (size_t p, const Values &initial) const |
Values | projectFrom (size_t p, const Values &values) const |
Values | roundSolution (const Values &values) const |
template<class T > | |
static Values | LiftTo (size_t p, const Values &values) |
Lift Values of type T to SO(p) More... | |
Class that implements Shonan Averaging from our ECCV'20 paper. Note: The "basic" API uses all Rot values (Rot2 or Rot3, depending on value of d), whereas the different levels and "advanced" API at SO(p) needs Values of type SOn<Dynamic>.
The template parameter d can be 2 or 3. Both are specialized in the .cpp file.
If you use this code in your work, please consider citing our paper: Shonan Rotation Averaging, Global Optimality by Surfing SO(p)^n Frank Dellaert, David M. Rosen, Jing Wu, Robert Mahony, and Luca Carlone, European Computer Vision Conference, 2020. You can view our ECCV spotlight video at https://youtu.be/5ppaqMyHtE0
Definition at line 123 of file ShonanAveraging.h.
using gtsam::ShonanAveraging< d >::Measurements = std::vector<BinaryMeasurement<Rot> > |
Definition at line 132 of file ShonanAveraging.h.
using gtsam::ShonanAveraging< d >::Parameters = ShonanAveragingParameters<d> |
Definition at line 128 of file ShonanAveraging.h.
using gtsam::ShonanAveraging< d >::Rot = typename Parameters::Rot |
Definition at line 129 of file ShonanAveraging.h.
using gtsam::ShonanAveraging< d >::Sparse = Eigen::SparseMatrix<double> |
Definition at line 125 of file ShonanAveraging.h.
gtsam::ShonanAveraging< d >::ShonanAveraging | ( | const Measurements & | measurements, |
const Parameters & | parameters = Parameters() |
||
) |
Construct from set of relative measurements (given as BetweenFactor<Rot3> for now) NoiseModel must be isotropic.
Definition at line 117 of file ShonanAveraging.cpp.
|
private |
Build 3Nx3N sparse degree matrix D.
Definition at line 362 of file ShonanAveraging.cpp.
NonlinearFactorGraph gtsam::ShonanAveraging< d >::buildGraphAt | ( | size_t | p | ) | const |
Build graph for SO(p)
p | the dimensionality of the rotation manifold to optimize over |
Definition at line 138 of file ShonanAveraging.cpp.
|
private |
Build 3Nx3N sparse matrix consisting of rotation measurements, arranged as (i,j) and (j,i) blocks within a sparse matrix.
Definition at line 397 of file ShonanAveraging.cpp.
bool gtsam::ShonanAveraging< d >::checkOptimality | ( | const Values & | values | ) | const |
Check optimality
values | should be of type SOn |
Definition at line 756 of file ShonanAveraging.cpp.
Sparse gtsam::ShonanAveraging< d >::computeA | ( | const Matrix & | S | ) | const |
Version that takes pxdN Stiefel manifold elements.
Definition at line 486 of file ShonanAveraging.cpp.
Sparse gtsam::ShonanAveraging< d >::computeA | ( | const Values & | values | ) | const |
Compute A matrix whose Eigenvalues we will examine.
Definition at line 477 of file ShonanAveraging.cpp.
|
inline |
Dense version of computeA for wrapper/testing.
Definition at line 242 of file ShonanAveraging.h.
Sparse gtsam::ShonanAveraging< d >::computeLambda | ( | const Matrix & | S | ) | const |
Version that takes pxdN Stiefel manifold elements.
Definition at line 437 of file ShonanAveraging.cpp.
Sparse gtsam::ShonanAveraging< d >::computeLambda | ( | const Values & | values | ) | const |
Given an estimated local minimum Yopt for the (possibly lifted) relaxation, this function computes and returns the block-diagonal elements of the corresponding Lagrange multiplier.
Definition at line 468 of file ShonanAveraging.cpp.
|
inline |
Dense versions of computeLambda for wrapper/testing.
Definition at line 231 of file ShonanAveraging.h.
|
inline |
Dense versions of computeLambda for wrapper/testing.
Definition at line 226 of file ShonanAveraging.h.
double gtsam::ShonanAveraging< d >::computeMinEigenValue | ( | const Values & | values, |
Vector * | minEigenVector = nullptr |
||
) | const |
Compute minimum eigenvalue for optimality check.
values | should be of type SOn |
Definition at line 713 of file ShonanAveraging.cpp.
double gtsam::ShonanAveraging< d >::computeMinEigenValueAP | ( | const Values & | values, |
Vector * | minEigenVector = nullptr |
||
) | const |
Compute minimum eigenvalue with accelerated power method.
values | should be of type SOn |
Definition at line 730 of file ShonanAveraging.cpp.
std::pair< double, Vector > gtsam::ShonanAveraging< d >::computeMinEigenVector | ( | const Values & | values | ) | const |
Compute minimum eigenvalue for optimality check.
values | should be of type SOn |
Definition at line 747 of file ShonanAveraging.cpp.
double gtsam::ShonanAveraging< d >::cost | ( | const Values & | values | ) | const |
Calculate cost for SO(3) Values should be of type Rot3
Definition at line 311 of file ShonanAveraging.cpp.
double gtsam::ShonanAveraging< d >::costAt | ( | size_t | p, |
const Values & | values | ||
) | const |
Calculate cost for SO(p) Values should be of type SO(p)
Definition at line 163 of file ShonanAveraging.cpp.
std::shared_ptr< LevenbergMarquardtOptimizer > gtsam::ShonanAveraging< d >::createOptimizerAt | ( | size_t | p, |
const Values & | initial | ||
) | const |
Try to create optimizer at SO(p)
p | the dimensionality of the rotation manifold to optimize over |
initial | initial SO(p) values |
Definition at line 171 of file ShonanAveraging.cpp.
Values gtsam::ShonanAveraging< d >::initializeRandomly |
Random initialization for wrapper, fixed random seed.
Definition at line 869 of file ShonanAveraging.cpp.
Values gtsam::ShonanAveraging< d >::initializeRandomly | ( | std::mt19937 & | rng | ) | const |
Initialize randomly at SO(d)
rng | random number generator Example: std::mt19937 rng(42); Values initial = initializeRandomly(rng, p); |
Definition at line 859 of file ShonanAveraging.cpp.
Values gtsam::ShonanAveraging< d >::initializeRandomlyAt | ( | size_t | p | ) | const |
Version of initializeRandomlyAt with fixed random seed.
Definition at line 883 of file ShonanAveraging.cpp.
Values gtsam::ShonanAveraging< d >::initializeRandomlyAt | ( | size_t | p, |
std::mt19937 & | rng | ||
) | const |
Create initial Values of type SO(p)
p | the dimensionality of the rotation manifold |
rng | random number generator |
Definition at line 875 of file ShonanAveraging.cpp.
Values gtsam::ShonanAveraging< d >::initializeWithDescent | ( | size_t | p, |
const Values & | values, | ||
const Vector & | minEigenVector, | ||
double | minEigenValue, | ||
double | gradienTolerance = 1e-2 , |
||
double | preconditionedGradNormTolerance = 1e-4 |
||
) | const |
Given some values at p-1, return new values at p, by doing a line search along the descent direction, computed from the minimum eigenvector at p-1.
values | should be of type SO(p-1) |
minEigenVector | corresponding to minEigenValue at level p-1 |
Definition at line 820 of file ShonanAveraging.cpp.
|
inline |
Keys for k^th measurement, as a vector of Key values.
Definition at line 209 of file ShonanAveraging.h.
|
inlinestatic |
Lift Values of type T to SO(p)
Definition at line 367 of file ShonanAveraging.h.
|
static |
Lift up the dimension of values in type SO(p-1) with descent direction provided by minEigenVector and return new values in type SO(p)
Definition at line 811 of file ShonanAveraging.cpp.
|
inline |
Update factors to use robust Huber loss.
measurements | Vector of BinaryMeasurements. |
k | Huber noise model threshold. |
Definition at line 181 of file ShonanAveraging.h.
|
inline |
Helper function to convert measurements to robust noise model if flag is set.
T | the type of measurement, e.g. Rot3. |
measurements | vector of BinaryMeasurements of type T. |
useRobustModel | flag indicating whether use robust noise model instead. |
Definition at line 418 of file ShonanAveraging.h.
|
inline |
k^th measurement, as a Rot.
Definition at line 206 of file ShonanAveraging.h.
|
inline |
k^th binary measurement
Definition at line 171 of file ShonanAveraging.h.
|
inline |
Return number of unknowns.
Definition at line 165 of file ShonanAveraging.h.
|
inline |
Return number of measurements.
Definition at line 168 of file ShonanAveraging.h.
Values gtsam::ShonanAveraging< 2 >::projectFrom | ( | size_t | p, |
const Values & | values | ||
) | const |
Definition at line 212 of file ShonanAveraging.cpp.
Values gtsam::ShonanAveraging< 3 >::projectFrom | ( | size_t | p, |
const Values & | values | ||
) | const |
Definition at line 224 of file ShonanAveraging.cpp.
Values gtsam::ShonanAveraging< d >::projectFrom | ( | size_t | p, |
const Values & | values | ||
) | const |
Matrix gtsam::ShonanAveraging< d >::riemannianGradient | ( | size_t | p, |
const Values & | values | ||
) | const |
Calculate the riemannian gradient of F(values) at values.
Definition at line 785 of file ShonanAveraging.cpp.
Values gtsam::ShonanAveraging< d >::roundSolution | ( | const Values & | values | ) | const |
Project from SO(p)^N to Rot2^N or Rot3^N Values should be of type SO(p)
Definition at line 302 of file ShonanAveraging.cpp.
Values gtsam::ShonanAveraging< d >::roundSolutionS | ( | const Matrix & | S | ) | const |
Project pxdN Stiefel manifold matrix S to Rot3^N.
Values gtsam::ShonanAveraging< 2 >::roundSolutionS | ( | const Matrix & | S | ) | const |
Definition at line 273 of file ShonanAveraging.cpp.
Values gtsam::ShonanAveraging< 3 >::roundSolutionS | ( | const Matrix & | S | ) | const |
Definition at line 287 of file ShonanAveraging.cpp.
std::pair< Values, double > gtsam::ShonanAveraging< d >::run | ( | const Values & | initialEstimate, |
size_t | pMin = d , |
||
size_t | pMax = 10 |
||
) | const |
Optimize at different values of p until convergence.
initial | initial Rot3 values |
pMin | value of p to start Riemanian staircase at (default: d). |
pMax | maximum value of p to try (default: 10) |
Definition at line 889 of file ShonanAveraging.cpp.
|
static |
Project to pxdN Stiefel manifold.
Definition at line 199 of file ShonanAveraging.cpp.
|
static |
Create a VectorValues with eigenvector v_i.
Definition at line 763 of file ShonanAveraging.cpp.
Values gtsam::ShonanAveraging< d >::tryOptimizingAt | ( | size_t | p, |
const Values & | initial | ||
) | const |
Try to optimize at SO(p)
p | the dimensionality of the rotation manifold to optimize over |
initial | initial SO(p) values |
Definition at line 190 of file ShonanAveraging.cpp.
|
private |
Definition at line 138 of file ShonanAveraging.h.
|
private |
Definition at line 140 of file ShonanAveraging.h.
|
private |
Definition at line 136 of file ShonanAveraging.h.
|
private |
Definition at line 137 of file ShonanAveraging.h.
|
private |
Definition at line 135 of file ShonanAveraging.h.
|
private |
Definition at line 139 of file ShonanAveraging.h.