27#include <boost/make_shared.hpp>
28#include <boost/serialization/version.hpp>
29#include <boost/serialization/split_member.hpp>
36 class GaussianFactorGraph;
37 class GaussianConditional;
48 GTSAM_EXPORT std::pair<boost::shared_ptr<GaussianConditional>, boost::shared_ptr<JacobianFactor> >
49 EliminateQR(
const GaussianFactorGraph& factors,
const Ordering& keys);
98 typedef VerticalBlockMatrix::Block ABlock;
99 typedef VerticalBlockMatrix::constBlock constABlock;
100 typedef ABlock::ColXpr BVector;
101 typedef constABlock::ConstColXpr constBVector;
106 noiseModel::Diagonal::shared_ptr model_;
127 const Vector& b,
const SharedDiagonal& model = SharedDiagonal());
131 Key i2,
const Matrix& A2,
132 const Vector& b,
const SharedDiagonal& model = SharedDiagonal());
136 const Matrix& A2,
Key i3,
const Matrix& A3,
137 const Vector& b,
const SharedDiagonal& model = SharedDiagonal());
142 template<
typename TERMS>
143 JacobianFactor(
const TERMS& terms,
const Vector& b,
const SharedDiagonal& model = SharedDiagonal());
149 template<
typename KEYS>
151 const KEYS& keys,
const VerticalBlockMatrix& augmentedMatrix,
const SharedDiagonal& sigmas = SharedDiagonal());
190 return boost::static_pointer_cast<GaussianFactor>(
191 boost::make_shared<JacobianFactor>(*
this));
195 void print(
const std::string& s =
"",
196 const KeyFormatter& formatter = DefaultKeyFormatter)
const override;
211 Matrix augmentedInformation()
const override;
216 Matrix information()
const override;
219 using Base::hessianDiagonal;
222 void hessianDiagonalAdd(
VectorValues& d)
const override;
225 void hessianDiagonal(
double* d)
const override;
228 std::map<Key,Matrix> hessianBlockDiagonal()
const override;
233 std::pair<Matrix, Vector> jacobian()
const override;
238 std::pair<Matrix, Vector> jacobianUnweighted()
const;
243 Matrix augmentedJacobian()
const override;
248 Matrix augmentedJacobianUnweighted()
const;
264 bool empty()
const override {
return size() == 0 ; }
268 return model_ && model_->isConstrained();
275 return Ab_(variable - begin()).
cols();
289 const SharedDiagonal&
get_model()
const {
return model_; }
295 const constBVector
getb()
const {
return Ab_(size()).col(0); }
301 constABlock
getA()
const {
return Ab_.
range(0, size()); }
304 BVector
getb() {
return Ab_(size()).col(0); }
324 void transposeMultiplyAdd(
double alpha,
const Vector& e,
328 void multiplyHessianAdd(
double alpha,
const VectorValues& x,
339 void multiplyHessianAdd(
double alpha,
const double* x,
double* y,
340 const std::vector<size_t>& accumulatedDims)
const;
346 void gradientAtZero(
double* d)
const override;
355 std::pair<boost::shared_ptr<GaussianConditional>, shared_ptr>
359 void setModel(
bool anyConstrained,
const Vector& sigmas);
372 friend GTSAM_EXPORT std::pair<boost::shared_ptr<GaussianConditional>, shared_ptr>
382 boost::shared_ptr<GaussianConditional> splitConditional(
size_t nrFrontals);
387 template<
typename TERMS>
388 void fillTerms(
const TERMS& terms,
const Vector& b,
const SharedDiagonal& noiseModel);
396 void JacobianFactorHelper(
398 const FastVector<VariableSlots::const_iterator>& orderedSlots);
406 template<
class KEYS,
class DIMENSIONS>
408 const SharedDiagonal& model = SharedDiagonal()) :
409 Base(keys), Ab_(dims.begin(), dims.end(), m, true), model_(model) {
413 template<
typename T>
friend class ExpressionFactor;
416 friend class boost::serialization::access;
417 template<
class ARCHIVE>
418 void save(ARCHIVE & ar,
const unsigned int version)
const {
423 ar << BOOST_SERIALIZATION_BASE_OBJECT_NVP(
Base);
424 ar << BOOST_SERIALIZATION_NVP(Ab_);
425 bool model_null =
false;
426 if(model_.get() ==
nullptr) {
428 ar << boost::serialization::make_nvp(
"model_null", model_null);
430 ar << boost::serialization::make_nvp(
"model_null", model_null);
431 ar << BOOST_SERIALIZATION_NVP(model_);
435 template<
class ARCHIVE>
436 void load(ARCHIVE & ar,
const unsigned int version) {
438 ar >> BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
439 ar >> BOOST_SERIALIZATION_NVP(Ab_);
441 ar >> BOOST_SERIALIZATION_NVP(model_);
444 ar >> BOOST_SERIALIZATION_NVP(model_null);
446 ar >> BOOST_SERIALIZATION_NVP(model_);
451 BOOST_SERIALIZATION_SPLIT_MEMBER()
462#include <gtsam/linear/JacobianFactor-inl.h>
A matrix with column blocks of pre-defined sizes.
VariableSlots describes the structure of a combined factor in terms of where each block comes from in...
A factor with a quadratic error function - a Gaussian.
Included from all GTSAM files.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:75
void save(const Matrix &A, const string &s, const string &filename)
save a matrix to file, which can be loaded by matlab
Definition: Matrix.cpp:166
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:47
std::pair< GaussianConditional::shared_ptr, JacobianFactor::shared_ptr > EliminateQR(const GaussianFactorGraph &factors, const Ordering &keys)
Multiply all factors and eliminate the given keys from the resulting factor using a QR variant that h...
Definition: JacobianFactor.cpp:789
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Definition: SymmetricBlockMatrix.h:52
Template to create a binary predicate.
Definition: Testable.h:111
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:151
Definition: VerticalBlockMatrix.h:42
Block range(DenseIndex startBlock, DenseIndex endBlock)
access ranges of blocks at a time
Definition: VerticalBlockMatrix.h:129
DenseIndex rows() const
Row size.
Definition: VerticalBlockMatrix.h:114
DenseIndex cols() const
Column size.
Definition: VerticalBlockMatrix.h:117
This is the base class for all factor types.
Definition: Factor.h:56
KeyVector::const_iterator const_iterator
Const iterator over keys.
Definition: Factor.h:68
KeyVector::iterator iterator
Iterator over keys.
Definition: Factor.h:65
Definition: Ordering.h:34
A combined factor is assembled as one block of rows for each component factor.
Definition: VariableSlots.h:52
An abstract virtual base class for JacobianFactor and HessianFactor.
Definition: GaussianFactor.h:39
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactor.h:42
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition: GaussianFactorGraph.h:69
A Gaussian factor using the canonical parameters (information form)
Definition: HessianFactor.h:101
A Gaussian factor in the squared-error form.
Definition: JacobianFactor.h:91
const constBVector getb() const
Get a view of the r.h.s.
Definition: JacobianFactor.h:295
bool empty() const override
Check if the factor is empty.
Definition: JacobianFactor.h:264
BVector getb()
Get a view of the r.h.s.
Definition: JacobianFactor.h:304
const SharedDiagonal & get_model() const
get a copy of model
Definition: JacobianFactor.h:289
JacobianFactor(const JacobianFactor &jf)
Copy constructor.
Definition: JacobianFactor.h:114
JacobianFactor This
Typedef to this class.
Definition: JacobianFactor.h:94
bool isConstrained() const
is noise model constrained ?
Definition: JacobianFactor.h:267
constABlock getA() const
Get a view of the A matrix, not weighted by noise.
Definition: JacobianFactor.h:301
GaussianFactor::shared_ptr clone() const override
Clone this JacobianFactor.
Definition: JacobianFactor.h:189
ABlock getA(iterator variable)
Get a view of the A matrix for the variable pointed to by the given key iterator (non-const version)
Definition: JacobianFactor.h:307
SharedDiagonal & get_model()
get a copy of model (non-const version)
Definition: JacobianFactor.h:292
DenseIndex getDim(const_iterator variable) const override
Return the dimension of the variable pointed to by the given key iterator todo: Remove this in favor ...
Definition: JacobianFactor.h:274
VerticalBlockMatrix & matrixObject()
Mutable access to the full augmented Jacobian matrix of this factor as a VerticalBlockMatrix object.
Definition: JacobianFactor.h:254
ABlock getA()
Get a view of the A matrix.
Definition: JacobianFactor.h:310
GaussianFactor Base
Typedef to base class.
Definition: JacobianFactor.h:95
~JacobianFactor() override
Virtual destructor.
Definition: JacobianFactor.h:186
const VerticalBlockMatrix & matrixObject() const
Return the full augmented Jacobian matrix of this factor as a VerticalBlockMatrix object.
Definition: JacobianFactor.h:251
size_t rows() const
return the number of rows in the corresponding linear system
Definition: JacobianFactor.h:281
size_t cols() const
return the number of columns in the corresponding linear system
Definition: JacobianFactor.h:286
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: JacobianFactor.h:96
constABlock getA(const_iterator variable) const
Get a view of the A matrix for the variable pointed to by the given key iterator.
Definition: JacobianFactor.h:298
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:74