Skip to content

Commit 891c40b

Browse files
committed
Working on adapting the SE-Sync code to the new Optimization interface.
1 parent f1d1595 commit 891c40b

12 files changed

+305
-300
lines changed

Diff for: C++/SE-Sync/include/SESync/RelativePoseMeasurement.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ struct RelativePoseMeasurement {
3030
Vector t;
3131

3232
/** Rotational measurement precision */
33-
double kappa;
33+
Scalar kappa;
3434

3535
/** Translational measurement precision */
36-
double tau;
36+
Scalar tau;
3737

3838
/** Simple default constructor; does nothing */
3939
RelativePoseMeasurement() {}
@@ -42,8 +42,8 @@ struct RelativePoseMeasurement {
4242
RelativePoseMeasurement(size_t first_pose, size_t second_pose,
4343
const Matrix &relative_rotation,
4444
const Vector &relative_translation,
45-
double rotational_precision,
46-
double translational_precision)
45+
Scalar rotational_precision,
46+
Scalar translational_precision)
4747
: i(first_pose), j(second_pose), R(relative_rotation),
4848
t(relative_translation), kappa(rotational_precision),
4949
tau(translational_precision) {}
@@ -64,4 +64,4 @@ struct RelativePoseMeasurement {
6464

6565
/** Typedef for a vector of RelativePoseMeasurements */
6666
typedef std::vector<SESync::RelativePoseMeasurement> measurements_t;
67-
}
67+
} // namespace SESync

Diff for: C++/SE-Sync/include/SESync/SESync.h

+35-35
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/** This file provides a convenient functional interface to the SESync
2-
* algorithm.
3-
*
4-
* Copyright (C) 2016 - 2018 by David M. Rosen
5-
*/
2+
* algorithm.
3+
*
4+
* Copyright (C) 2016 - 2018 by David M. Rosen
5+
*/
66

77
#pragma once
88

@@ -22,25 +22,25 @@ struct SESyncOpts {
2222
/// OPTIMIZATION STOPPING CRITERIA
2323

2424
/** Stopping tolerance for the norm of the Riemannian gradient */
25-
double grad_norm_tol = 1e-2;
25+
Scalar grad_norm_tol = 1e-2;
2626

2727
/** Stopping tolerance for the norm of the preconditioned Riemannian gradient
2828
*/
29-
double preconditioned_grad_norm_tol = 1e-4;
29+
Scalar preconditioned_grad_norm_tol = 1e-4;
3030

3131
/** Stopping criterion based upon the relative decrease in function value */
32-
double rel_func_decrease_tol = 1e-7;
32+
Scalar rel_func_decrease_tol = 1e-7;
3333

3434
/** Stopping criterion based upon the norm of an accepted update step */
35-
double stepsize_tol = 1e-3;
35+
Scalar stepsize_tol = 1e-3;
3636

3737
/** Maximum permitted number of (outer) iterations of the Riemannian
3838
* trust-region method when solving each instance of Problem 9 */
39-
unsigned int max_iterations = 1000;
39+
size_t max_iterations = 1000;
4040

4141
/** Maximum number of inner (truncated conjugate-gradient) iterations to
4242
* perform per out iteration */
43-
unsigned int max_tCG_iterations = 10000;
43+
size_t max_tCG_iterations = 10000;
4444

4545
/// These next two parameters define the stopping criteria for the truncated
4646
/// preconditioned conjugate-gradient solver running in the inner loop --
@@ -53,14 +53,14 @@ struct SESyncOpts {
5353
/** Gradient tolerance for the truncated preconditioned conjugate
5454
gradient solver: stop if ||g|| < kappa * ||g_0||. This parameter should be in
5555
the range (0,1). */
56-
double STPCG_kappa = .1;
56+
Scalar STPCG_kappa = .1;
5757

5858
/** Gradient tolerance based upon a fractional-power reduction in the norm of
5959
* the gradient: stop if ||g|| < ||kappa||^{1+ theta}. This value should be
6060
* positive, and controls the asymptotic convergence rate of the
6161
* truncated-Newton trust-region solver: specifically, for theta > 0, the TNT
6262
* algorithm converges q-superlinearly with order (1+theta). */
63-
double STPCG_theta = .5;
63+
Scalar STPCG_theta = .5;
6464

6565
/** Maximum elapsed computation time (in seconds) */
6666
double max_computation_time = std::numeric_limits<double>::max();
@@ -76,24 +76,24 @@ struct SESyncOpts {
7676
Formulation formulation = Formulation::Simplified;
7777

7878
/** The initial level of the Riemannian Staircase */
79-
unsigned int r0 = 5;
79+
size_t r0 = 5;
8080

8181
/** The maximum level of the Riemannian Staircase to explore */
82-
unsigned int rmax = 10;
82+
size_t rmax = 10;
8383

8484
/** The maximum number of Lanczos iterations to admit for eigenvalue
8585
* computations */
86-
unsigned int max_eig_iterations = 10000;
86+
size_t max_eig_iterations = 10000;
8787

8888
/** A numerical tolerance for acceptance of the minimum eigenvalue of Q -
8989
* Lambda(Y*) as numerically nonnegative; this should be a small positive
9090
* value e.g. 10^-4 */
91-
double min_eig_num_tol = 1e-5;
91+
Scalar min_eig_num_tol = 1e-5;
9292

9393
/** The number of working vectors to use in the minimum eigenvalue computation
9494
(using the implicitly-restarted Arnoldi algorithm); must be in the range [1,
9595
(#poses) * (#problem dimension) - 1] */
96-
unsigned int num_Lanczos_vectors = 20;
96+
size_t num_Lanczos_vectors = 20;
9797

9898
/** Whether to use the Cholesky or QR factorization when computing the
9999
* orthogonal projection */
@@ -106,11 +106,11 @@ struct SESyncOpts {
106106

107107
/** Maximum admissible condition number for the regularized Cholesky
108108
* preconditioner */
109-
double reg_Cholesky_precon_max_condition_number = 1e6;
109+
Scalar reg_Cholesky_precon_max_condition_number = 1e6;
110110

111111
/** If no initial iterate Y0 is supplied, this boolean determines the
112-
* initialization strategy employed by SE-Sync: 'true' -> chordal, 'false' ->
113-
* random sampling */
112+
* initialization strategy employed by SE-Sync: 'true' -> chordal, 'false' ->
113+
* random sampling */
114114
Initialization initialization = Initialization::Chordal;
115115

116116
/** Whether to print output as the algorithm runs */
@@ -122,7 +122,7 @@ struct SESyncOpts {
122122

123123
/** The number of threads to use for parallelization (assuming that SE-Sync is
124124
* built using a compiler that supports OpenMP */
125-
unsigned int num_threads = 1;
125+
size_t num_threads = 1;
126126
};
127127

128128
/** These enumerations describe the termination status of the SE-Sync algorithm
@@ -158,10 +158,10 @@ struct SESyncResult {
158158
Matrix Yopt;
159159

160160
/** The value of the objective F(Y^T Y) = F(Z) attained by the Yopt */
161-
double SDPval;
161+
Scalar SDPval;
162162

163163
/** The norm of the Riemannian gradient at Yopt */
164-
double gradnorm;
164+
Scalar gradnorm;
165165

166166
/** The Lagrange multiplier matrix Lambda corresponding to Yopt, computed
167167
* according to eq. (119) in the SE-Sync tech report. If Z = Y^T Y is an
@@ -171,31 +171,31 @@ struct SESyncResult {
171171

172172
/** The trace of Lambda; this is the value of Lambda under the objective of
173173
* the (primal) semidefinite relaxation Problem 6. */
174-
double trace_Lambda;
174+
Scalar trace_Lambda;
175175

176176
/** The duality gap between the estimates for the primal and dual solutions
177177
* Lambda and Z = Y^T Y of Problems 7 and 6, respectively; it is given by:
178178
*
179179
* SDP_duality_gap := F(Y^T Y) - tr(Lambda)
180180
*
181181
*/
182-
double SDP_duality_gap;
182+
Scalar SDP_duality_gap;
183183

184184
/** The minimum eigenvalue of the matrix S - Lambda */
185-
double lambda_min;
185+
Scalar lambda_min;
186186

187187
/** The corresponding eigenvector of the minimum eigenvalue */
188188
Vector v_min;
189189

190190
/** The value of the rounded solution xhat in SE(d)^n */
191-
double Fxhat;
191+
Scalar Fxhat;
192192

193193
/** The rounded solution xhat = [t | R] in SE(d)^n */
194194
Matrix xhat;
195195

196196
/** Upper bound on the global suboptimality of the recovered pose estimates
197197
* xhat; this is equal to F(xhat) - tr(Lambda) */
198-
double suboptimality_upper_bound;
198+
Scalar suboptimality_upper_bound;
199199

200200
/** The total elapsed computation time for the SE-Sync algorithm */
201201
double total_computation_time;
@@ -206,12 +206,12 @@ struct SESyncResult {
206206

207207
/** A vector containing the sequence of function values obtained during the
208208
* optimization at each level of the Riemannian Staircase */
209-
std::vector<std::vector<double>> function_values;
209+
std::vector<std::vector<Scalar>> function_values;
210210

211211
/** A vector containing the sequence of norms of the Riemannian gradients
212212
* obtained during the optimization at each level of the Riemannian Staircase
213213
*/
214-
std::vector<std::vector<double>> gradient_norms;
214+
std::vector<std::vector<Scalar>> gradient_norms;
215215

216216
/** A vector containing the sequence of (# Hessian-vector product operations)
217217
* carried out during the optimization at each level of the Riemannian
@@ -226,12 +226,12 @@ struct SESyncResult {
226226
/** A vector containing the sequence of minimum eigenvalues of the certificate
227227
* matrix constructed from the critical point recovered from the
228228
* optimization at each level of the Riemannian Staircase */
229-
std::vector<double> minimum_eigenvalues;
229+
std::vector<Scalar> minimum_eigenvalues;
230230

231231
/** A vector containing the number of matrix-vector multiplication operations
232232
* performed for the minimum-eigenvalue computation at each level of the
233233
* Riemannian Staircase */
234-
std::vector<unsigned int> minimum_eigenvalue_matrix_ops;
234+
std::vector<size_t> minimum_eigenvalue_matrix_ops;
235235

236236
/** A vector containing the elapsed time of the minimum eigenvalue computation
237237
* at each level of the Riemannian Staircase */
@@ -292,8 +292,8 @@ SESyncResult SESync(const measurements_t &measurements,
292292
* of the Riemannian Staircase
293293
*/
294294
bool escape_saddle(const SESyncProblem &problem, const Matrix &Y,
295-
double lambda_min, const Vector &v_min,
296-
double gradient_tolerance,
297-
double preconditioned_gradient_tolerance, Matrix &Yplus);
295+
Scalar lambda_min, const Vector &v_min,
296+
Scalar gradient_tolerance,
297+
Scalar preconditioned_gradient_tolerance, Matrix &Yplus);
298298

299299
} // namespace SESync

0 commit comments

Comments
 (0)