37 const boost::shared_ptr<Matrix> &
G)
44 throw std::invalid_argument(
45 "ShonanFactor: model with incorrect dimension.");
47 G_ = boost::make_shared<Matrix>();
50 if (static_cast<size_t>(
G_->rows()) !=
pp_ ||
52 throw std::invalid_argument(
"ShonanFactor: passed in generators " 53 "of incorrect dimension.");
60 std::cout << s <<
"ShonanFactor<" <<
p_ <<
">(" << keyFormatter(
key1()) <<
"," 61 << keyFormatter(
key2()) <<
")\n";
72 p_ ==
e->p_ &&
M_ ==
e->M_;
78 boost::optional<Matrix &> H1,
79 boost::optional<Matrix &> H2)
const {
80 gttic(ShonanFactor_Jacobians);
87 *H1 = Matrix::Zero(dim,
G_->cols());
88 for (
size_t j = 0;
j <
d;
j++) {
89 auto MG_j = M1 *
G_->middleRows(
j *
p_, p_);
90 for (
size_t i = 0;
i <
d;
i++) {
91 H1->middleRows(
i * p_, p_) -=
M_(
j,
i) * MG_j;
99 H2->resize(dim,
G_->cols());
100 for (
size_t i = 0;
i <
d;
i++) {
101 H2->middleRows(
i *
p_, p_) = M2 *
G_->middleRows(
i * p_, p_);
109 boost::optional<Matrix &> H1,
110 boost::optional<Matrix &> H2)
const {
111 gttic(ShonanFactor_evaluateError);
115 if (M1.rows() !=
static_cast<int>(
p_) || M2.rows() !=
static_cast<int>(
p_))
116 throw std::invalid_argument(
"Invalid dimension SOn values passed to " 117 "ShonanFactor<d>::evaluateError");
119 const size_t dim =
p_ *
d;
120 Vector fQ2(dim), hQ1(dim);
123 fQ2 << Eigen::Map<const Matrix>(M2.data(),
dim, 1);
126 const Matrix Q1PR12 = M1.leftCols<d>() *
M_;
127 hQ1 << Eigen::Map<const Matrix>(Q1PR12.data(),
dim, 1);
SharedNoiseModel ConvertNoiseModel(const SharedNoiseModel &model, size_t d, bool defaultToUnit)
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
Main factor type in Shonan averaging, on SO(n) pairs.
size_t dim() const override
Factor Graph consisting of non-linear factors.
JacobiRotation< float > G
noiseModel::Diagonal::shared_ptr model
boost::shared_ptr< Matrix > G_
matrix of vectorized generators
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print with optional string
static Matrix VectorizedGenerators()
Calculate N^2 x dim matrix of vectorized Lie algebra generators for SO(N)
const MatrixNN & matrix() const
Return matrix.
static size_t Dimension(size_t n)
const SharedNoiseModel & noiseModel() const
access to the noise model
size_t pp_
dimensionality constants
void fillJacobians(const Matrix &M1, const Matrix &M2, boost::optional< Matrix & > H1, boost::optional< Matrix & > H2) const
Calculate Jacobians if asked, Only implemented for d=2 and 3 in .cpp.
M1<< 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12;Map< MatrixXf > M2(M1.data(), 6, 2)
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Various factors that minimize some Frobenius norm.
SharedNoiseModel noiseModel_
Vector evaluateError(const SOn &Q1, const SOn &Q2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const override
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
assert equality up to a tolerance
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Matrix M_
measured rotation between R1 and R2
std::uint64_t Key
Integer nonlinear key type.
void Print(const CONTAINER &keys, const string &s, const KeyFormatter &keyFormatter)
typename std::conditional< d==2, Rot2, Rot3 >::type Rot
noiseModel::Base::shared_ptr SharedNoiseModel