11#include " SESync/RelativePoseMeasurement.h"
22#include " SESync/SESync.h"
3+ #include " SESync/SESyncProblem.h"
34#include " SESync/SESync_types.h"
45#include " SESync/SESync_utils.h"
56
@@ -149,6 +150,9 @@ PYBIND11_MODULE(PySESync, m) {
149150 &SESync::SESyncOpts::projection_factorization,
150151 " Type of cached matrix factorization to use for computing "
151152 " orthogonal projections" )
153+ .def_readwrite (" preconditioner" , &SESync::SESyncOpts::preconditioner,
154+ " The preconditioning strategy to use in the Riemannian "
155+ " trust-region algorithm" )
152156 .def_readwrite (
153157 " reg_Chol_precon_max_cond" ,
154158 &SESync::SESyncOpts::reg_Cholesky_precon_max_condition_number)
@@ -367,6 +371,109 @@ PYBIND11_MODULE(PySESync, m) {
367371 " a pair consisting of (1) the orbit distance d_O(X,Y) between them and "
368372 " (2) the optimal registration G_O in O(d) aligning Y to X" );
369373
374+ // / Bindings for SESyncProblem class
375+ py::class_<SESync::SESyncProblem>(
376+ m, " SESyncProblem" ,
377+ " This class encapsulates an instance of the rank-restricted Riemannian "
378+ " form of the semidefinite relaxation of a special Euclidean. It "
379+ " contains all of the precomputed and cached data matrices necessary to "
380+ " describe the problem and run the optimization algorithm, as well as "
381+ " functions for performing geometric operations on the underlying "
382+ " manifold (tangent space projection and retraction) and evaluating the "
383+ " optimization objective and its gradient and Hessian operator. " )
384+ .def (py::init<>(), " Default constructor: produces an empyt "
385+ " (uninitialized) problem instance" )
386+ .def (py::init<SESync::measurements_t , SESync::Formulation,
387+ SESync::ProjectionFactorization, SESync::Preconditioner,
388+ SESync::Scalar>(),
389+ py::arg (" measurements" ),
390+ py::arg (" formulation" ) = SESync::Formulation::Simplified,
391+ py::arg (" projection_factorization" ) =
392+ SESync::ProjectionFactorization::Cholesky,
393+ py::arg (" preconditioner" ) =
394+ SESync::Preconditioner::IncompleteCholesky,
395+ py::arg (" reg_chol_precon_max_cond" ) = 1e6 , " Basic constructor." )
396+ .def (" set_relaxation_rank" , &SESync::SESyncProblem::set_relaxation_rank,
397+ " Set maximum rank of the rank-restricted semidefinite relaxation." )
398+ .def (" formulation" , &SESync::SESyncProblem::formulation,
399+ " Get the specific formulation of this problem" )
400+ .def (
401+ " projection_factorization" ,
402+ &SESync::SESyncProblem::projection_factorization,
403+ " Returns the type of matrix factorization used to compute the action "
404+ " of the orthogonal projection operator Pi when solving a Simplified "
405+ " instance of the special Euclidean synchronization problem" )
406+ .def (" preconditioner" , &SESync::SESyncProblem::preconditioner,
407+ " Get the preconditioning strategy" )
408+ .def (" num_states" , &SESync::SESyncProblem::num_states,
409+ " Get the number of states (poses or rotations) appearing in this "
410+ " problem" )
411+ .def (" num_measurements" , &SESync::SESyncProblem::num_measurements,
412+ " Get the number of measurements appearing in this problem" )
413+ .def (" dimension" , &SESync::SESyncProblem::dimension,
414+ " Get the dimension d of the group SE(d) or SO(d) over which this "
415+ " problem is defined" )
416+ .def (" relaxation_rank" , &SESync::SESyncProblem::relaxation_rank,
417+ " Get the current relaxation rank r of this problem" )
418+ .def (" oriented_incidence_matrix" ,
419+ &SESync::SESyncProblem::oriented_incidence_matrix,
420+ " Returns the oriented incidence matrix A of the underlying "
421+ " measurement graph over which the problem is defined" )
422+ .def (" Pi_product" , &SESync::SESyncProblem::Pi_product,
423+ " Given a matrix X, this function computes and returns the "
424+ " orthogonal projection Pi*X" )
425+ .def (" Q_product" , &SESync::SESyncProblem::Q_product,
426+ " Given a matrix X, computes the product Q*X" )
427+ .def (" data_matrix_product" , &SESync::SESyncProblem::data_matrix_product,
428+ " Given a matrix Y, this function computes and returns the matrix "
429+ " product SY, where S is the symmetric matrix parameterizing the "
430+ " quadratic objective" )
431+ .def (" evaluate_objective" , &SESync::SESyncProblem::evaluate_objective,
432+ " Evaluate the objective of the rank-restricted relaxation" )
433+ .def (" Euclidean_gradient" , &SESync::SESyncProblem::Euclidean_gradient,
434+ " Evaluate the Euclidean gradient of the objective" )
435+ .def (" Riemannian_gradient" ,
436+ static_cast <SESync::Matrix (SESync::SESyncProblem::*)(
437+ const SESync::Matrix &) const >(
438+ &SESync::SESyncProblem::Riemannian_gradient),
439+ " Evaluate the Riemannian gradient of the objective" )
440+ .def (" Riemannian_Hessian_vector_product" ,
441+ static_cast <SESync::Matrix (SESync::SESyncProblem::*)(
442+ const SESync::Matrix &, const SESync::Matrix &) const >(
443+ &SESync::SESyncProblem::Riemannian_Hessian_vector_product),
444+ " Given a matrix Y in the domain D of the relaxation and a tangent "
445+ " vector dotY in T_Y(D), this function computes and returns Hess "
446+ " F(Y)[dotY], the action of the Riemannian Hessian on dotY" )
447+ .def (" precondition" , &SESync::SESyncProblem::precondition,
448+ " Given a matrix Y in the domain D of the relaxation and a tangent "
449+ " vector dotY in T_D(Y), this function applies the selected "
450+ " preconditioning strategy to dotY" )
451+ .def (" tangent_space_projection" ,
452+ &SESync::SESyncProblem::tangent_space_projection,
453+ " Given a matrix Y in the domain D of the relaxation and a tangent "
454+ " vector dotY of the ambient Eucliean space at Y, this function "
455+ " computes and returns the orthogonal projection of dotY onto T_D(Y)" )
456+ .def (" retract" , &SESync::SESyncProblem::retract,
457+ " Given a matrix Y in the domain of the relaxation and a tangent "
458+ " vector dotY in T_Y(D), this function computes the retraction of Y "
459+ " along dotY" )
460+ .def (" round_solution" , &SESync::SESyncProblem::round_solution,
461+ " Given a point Y in the domain D of the rank-r relaxation, this "
462+ " function computes and returns a matrix X = [t|R] composed of "
463+ " translations and rotations for a set of feasible poses for the "
464+ " original estimation problem obtained by rounding the point Y" )
465+ .def (" compute_Lambda" , &SESync::SESyncProblem::compute_Lambda,
466+ " Given a critical point Y of the rank-r relaxation, this function "
467+ " computes and returns the corresponding Lagrange multiplier matrix "
468+ " Lambda" )
469+ .def (" chordal_initialization" ,
470+ &SESync::SESyncProblem::chordal_initialization,
471+ " This function computes and returns a chordal initialization for "
472+ " the rank-restricted semidefinite relaxation" )
473+ .def (" random_sample" , &SESync::SESyncProblem::random_sample,
474+ " Randomly sample a point in the domain of the rank-restricted "
475+ " semidefinite relaxation" );
476+
370477 // / Bindings for the main SESync driver
371478 m.def (
372479 " SESync" ,
@@ -381,7 +488,23 @@ PYBIND11_MODULE(PySESync, m) {
381488 py::arg (" measurements" ), py::arg (" options" ) = SESync::SESyncOpts (),
382489 py::arg (" Y0" ) = SESync::Matrix (),
383490 " Main SE-Sync function: Given a list of relative pose measurements "
384- " specifying a special Euclidean synchronization problem, this function "
491+ " specifying a special Euclidean synchronization problem, this "
492+ " function "
385493 " computes and returns an estimated solution using the SE-Sync "
386494 " algorithm " );
495+
496+ m.def (
497+ " SESync" ,
498+ [](SESync::SESyncProblem &problem, const SESync::SESyncOpts &options,
499+ const SESync::Matrix &Y0) -> SESync::SESyncResult {
500+ // Redirect emitted output from (C++) stdout to (Python) sys.stdout
501+ py::scoped_ostream_redirect stream (
502+ std::cout, py::module::import (" sys" ).attr (" stdout" ));
503+ return SESync::SESync (problem, options, Y0);
504+ },
505+ py::arg (" problem" ), py::arg (" options" ) = SESync::SESyncOpts (),
506+ py::arg (" Y0" ) = SESync::Matrix (),
507+ " Main SE-Sync function: Given an SESyncProblem instance, this "
508+ " function computes and returns an estimated solution using the SE-Sync "
509+ " algorithm " );
387510}
0 commit comments