39 #ifndef INCLUDE_OKVIS_CERES_MARGINALIZATIONERROR_HPP_
40 #define INCLUDE_OKVIS_CERES_MARGINALIZATIONERROR_HPP_
49 #include "ceres/ceres.h"
69 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
73 typedef ::ceres::CostFunction
base_t;
91 Map& map, std::vector< ::ceres::ResidualBlockId > & residualBlockIds);
104 const std::vector< ::ceres::ResidualBlockId > & residualBlockIds,
105 const std::vector<bool> & keepResidualBlocks = std::vector<bool>());
113 bool keepResidualBlock =
false);
125 bool marginalizeOut(
const std::vector<uint64_t> & parameterBlockIds,
126 const std::vector<bool> & keepParameterBlocks =
127 std::vector<bool>());
136 std::vector<std::shared_ptr<okvis::ceres::ParameterBlock> >& parameterBlockPtrs);
146 virtual bool Evaluate(
double const*
const * parameters,
double* residuals,
147 double** jacobians)
const;
159 double* residuals,
double** jacobians,
160 double** jacobiansMinimal)
const;
166 return base_t::num_residuals();
172 return base_t::parameter_block_sizes().size();
180 return base_t::parameter_block_sizes().at(parameterBlockId);
186 return "MarginalizationError";
201 template<
typename Derived>
203 const Eigen::MatrixBase<Derived>&a,
204 const Eigen::MatrixBase<Derived>&result,
double epsilon =
205 std::numeric_limits<typename Derived::Scalar>::epsilon(),
int * rank = 0);
218 template<
typename Derived>
220 const Eigen::MatrixBase<Derived>&a,
221 const Eigen::MatrixBase<Derived>&result,
double epsilon =
222 std::numeric_limits<typename Derived::Scalar>::epsilon(),
236 template<
typename Derived,
int blockDim>
238 const Eigen::MatrixBase<Derived>& M_in,
239 const Eigen::MatrixBase<Derived>& M_out,
double epsilon =
240 std::numeric_limits<typename Derived::Scalar>::epsilon());
255 template<
typename Derived,
int blockDim>
257 const Eigen::MatrixBase<Derived>& M_in,
258 const Eigen::MatrixBase<Derived>& M_out,
double epsilon =
259 std::numeric_limits<typename Derived::Scalar>::epsilon());
273 Eigen::VectorXd& DeltaChi)
const;
276 template<
typename Derived_A,
typename Derived_U,
typename Derived_W,
279 const std::vector<std::pair<int, int> >& marginalizationStartIdxAndLengthPairs,
280 const Eigen::MatrixBase<Derived_A>& A,
281 const Eigen::MatrixBase<Derived_U>& U,
282 const Eigen::MatrixBase<Derived_W>& W,
283 const Eigen::MatrixBase<Derived_V>& V);
286 template<
typename Derived_b,
typename Derived_b_a,
typename Derived_b_b>
288 const std::vector<std::pair<int, int> >& marginalizationStartIdxAndLengthPairs,
289 const Eigen::MatrixBase<Derived_b>& b,
290 const Eigen::MatrixBase<Derived_b_a>& b_a,
291 const Eigen::MatrixBase<Derived_b_b>& b_b);
329 : parameterBlockId(0),
341 : parameterBlockId(parameterBlockId),
342 parameterBlockPtr(parameterBlockPtr),
343 orderingIdx(orderingIdx),
344 isLandmark(isLandmark)
346 dimension = parameterBlockPtr->dimension();
348 if (parameterBlockPtr->localParameterizationPtr()) {
354 if (parameterBlockPtr->fixed()) {
359 std::default_delete<
double[]>());
361 dimension *
sizeof(double));
size_t residualDim() const
Residual dimension.
Definition: MarginalizationError.hpp:164
Eigen::MatrixXd U_
H_ = _U*_S*_U^T lhs Eigen decomposition.
Definition: MarginalizationError.hpp:307
Header file for the HomogeneousPointLocalParameterization class.
Header file for the ErrorInterface class. A simple interface class that other error classes should in...
virtual std::string typeInfo() const
Return parameter block type as string.
Definition: MarginalizationError.hpp:184
Eigen::VectorXd S_
singular values
Definition: MarginalizationError.hpp:308
Eigen::VectorXd p_inv_
Definition: MarginalizationError.hpp:313
Eigen::VectorXd b0_
rhs constant part
Definition: MarginalizationError.hpp:304
Eigen::VectorXd S_pinv_
pseudo inverse of _S
Definition: MarginalizationError.hpp:310
static void splitSymmetricMatrix(const std::vector< std::pair< int, int > > &marginalizationStartIdxAndLengthPairs, const Eigen::MatrixBase< Derived_A > &A, const Eigen::MatrixBase< Derived_U > &U, const Eigen::MatrixBase< Derived_W > &W, const Eigen::MatrixBase< Derived_V > &V)
Split for Schur complement op.
Definition: MarginalizationError.hpp:47
uint64_t parameterBlockId
Definition: MarginalizationError.hpp:320
Header file for the PoseParameterBlock class.
static void splitVector(const std::vector< std::pair< int, int > > &marginalizationStartIdxAndLengthPairs, const Eigen::MatrixBase< Derived_b > &b, const Eigen::MatrixBase< Derived_b_a > &b_a, const Eigen::MatrixBase< Derived_b_b > &b_b)
Split for Schur complement op.
Definition: MarginalizationError.hpp:125
Header file for the Map class. This essentially encapsulates the ceres::Problem.
volatile bool errorComputationValid_
adding residual blocks will invalidate this. before optimizing, call updateErrorComputation() ...
Definition: MarginalizationError.hpp:314
Eigen::MatrixXd H_
lhs - Hessian
Definition: MarginalizationError.hpp:303
bool isLandmark
Definition: MarginalizationError.hpp:327
Book-keeping of the ordering.
Definition: MarginalizationError.hpp:317
static bool pseudoInverseSymmSqrt(const Eigen::MatrixBase< Derived > &a, const Eigen::MatrixBase< Derived > &result, double epsilon=std::numeric_limits< typename Derived::Scalar >::epsilon(), int *rank=NULL)
Pseudo inversion and square root (Cholesky decomposition) of a symmetric matrix.
Definition: MarginalizationError.hpp:215
bool addResidualBlocks(const std::vector< ::ceres::ResidualBlockId > &residualBlockIds, const std::vector< bool > &keepResidualBlocks=std::vector< bool >())
Add some residuals to this marginalisation error. This means, they will get linearised.
Definition: MarginalizationError.cpp:111
bool addResidualBlock(::ceres::ResidualBlockId residualBlockId, bool keepResidualBlock=false)
Add one residual to this marginalisation error. This means, it will get linearised.
Definition: MarginalizationError.cpp:127
This file contains the templated measurement structs, structs encapsulating Sensor data and related t...
Simple interface class the errors implemented here should inherit from.
Definition: ErrorInterface.hpp:53
void getParameterBlockPtrs(std::vector< std::shared_ptr< okvis::ceres::ParameterBlock > > ¶meterBlockPtrs)
Call this in order to (re-)add this error term after whenever it had been modified.
Definition: MarginalizationError.cpp:497
Header file for the HomogeneousPointParameterBlock class.
static void blockPinverseSqrt(const Eigen::MatrixBase< Derived > &M_in, const Eigen::MatrixBase< Derived > &M_out, double epsilon=std::numeric_limits< typename Derived::Scalar >::epsilon())
Block-wise pseudo inversion and square root (Cholesky decomposition) of a symmetric matrix with non-z...
Definition: MarginalizationError.hpp:275
size_t dimension
Definition: MarginalizationError.hpp:323
std::vector< ParameterBlockInfo > parameterBlockInfos_
Book keeper.
Definition: MarginalizationError.hpp:374
Eigen::MatrixXd J_
Jacobian such that _J^T * J == _H.
Definition: MarginalizationError.hpp:306
#define OKVIS_DEFINE_EXCEPTION(exceptionName, exceptionParent)
Macro for defining an exception with a given parent.
Definition: assert_macros.hpp:52
virtual bool Evaluate(double const *const *parameters, double *residuals, double **jacobians) const
This evaluates the error term and additionally computes the Jacobians.
Definition: MarginalizationError.cpp:885
This file contains some useful assert macros.
Header file for the SpeedAndBiasParameterBlock class.
bool marginalizeOut(const std::vector< uint64_t > ¶meterBlockIds, const std::vector< bool > &keepParameterBlocks=std::vector< bool >())
Marginalise out a set of parameter blocks.
Definition: MarginalizationError.cpp:507
void resetLinearizationPoint(std::shared_ptr< ParameterBlock > parameterBlockPtr)
Reset the linearisation point. Use with caution.
Definition: MarginalizationError.hpp:365
std::map< uint64_t, size_t > parameterBlockId2parameterBlockInfoIdx_
Maps parameter block Ids to index in _parameterBlockInfos.
Definition: MarginalizationError.hpp:375
Eigen::VectorXd p_
Definition: MarginalizationError.hpp:312
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef::ceres::CostFunction base_t
The base class type.
Definition: MarginalizationError.hpp:73
bool computeDeltaChi(Eigen::VectorXd &DeltaChi) const
Computes the linearized deviation from the references (linearization points)
Definition: MarginalizationError.cpp:849
This file contains some typedefs related to state variables.
void setMap(Map &map)
Set the underlying okvis::ceres::Map.
Definition: MarginalizationError.cpp:105
std::shared_ptr< double > linearizationPoint
Definition: MarginalizationError.hpp:326
ParameterBlockInfo(uint64_t parameterBlockId, std::shared_ptr< ParameterBlock > parameterBlockPtr, size_t orderingIdx, bool isLandmark)
Definition: MarginalizationError.hpp:338
void check()
Checks the internal datastructure (debug)
Definition: MarginalizationError.cpp:451
Eigen::VectorXd S_sqrt_
cwise sqrt of _S, i.e. _S_sqrt*_S_sqrt=_S; _J=_U^T*_S_sqrt
Definition: MarginalizationError.hpp:309
::ceres::ResidualBlockId residualBlockId_
The residual block id of this.
Definition: MarginalizationError.hpp:263
void updateErrorComputation()
This must be called before optimization after adding residual blocks and/or marginalizing, since it performs all the lhs and rhs computations on from a given _H and _b.
Definition: MarginalizationError.cpp:806
std::shared_ptr< ParameterBlock > parameterBlockPtr
Definition: MarginalizationError.hpp:321
size_t denseIndices_
Keep track of the size of the dense part of the equation system.
Definition: MarginalizationError.hpp:376
bool isParameterBlockConnected(uint64_t parameterBlockId)
Info: is this parameter block connected to this marginalization error?
Definition: MarginalizationError.cpp:438
size_t minimalDimension
Definition: MarginalizationError.hpp:324
Eigen::VectorXd S_pinv_sqrt_
cwise sqrt of _S_pinv, i.e. pinv(J^T)=_U^T*_S_pinv_sqrt
Definition: MarginalizationError.hpp:311
Definition: MarginalizationError.hpp:65
size_t localDimension
Definition: MarginalizationError.hpp:325
MarginalizationError()
Default constructor. Initialises a new okvis::ceres::Map.
Definition: MarginalizationError.cpp:76
The Map class. This keeps track of how parameter blocks are connected to residual blocks...
Definition: Map.hpp:63
Header implementation file for the MarginalizationError class.
bool EvaluateWithMinimalJacobians(double const *const *parameters, double *residuals, double **jacobians, double **jacobiansMinimal) const
This evaluates the error term and additionally computes the Jacobians in the minimal internal represe...
Definition: MarginalizationError.cpp:893
size_t parameterBlockDim(size_t parameterBlockId) const
Dimension of an individual parameter block.
Definition: MarginalizationError.hpp:178
#define OKVIS_ASSERT_TRUE_DBG(exceptionType, condition, message)
Definition: assert_macros.hpp:211
Map * mapPtr_
The underlying map.
Definition: MarginalizationError.hpp:262
static bool pseudoInverseSymm(const Eigen::MatrixBase< Derived > &a, const Eigen::MatrixBase< Derived > &result, double epsilon=std::numeric_limits< typename Derived::Scalar >::epsilon(), int *rank=0)
Pseudo inversion of a symmetric matrix.
Definition: MarginalizationError.hpp:182
size_t orderingIdx
Definition: MarginalizationError.hpp:322
static void blockPinverse(const Eigen::MatrixBase< Derived > &M_in, const Eigen::MatrixBase< Derived > &M_out, double epsilon=std::numeric_limits< typename Derived::Scalar >::epsilon())
Block-wise pseudo inversion of a symmetric matrix with non-zero diagonal blocks.
Definition: MarginalizationError.hpp:249
size_t parameterBlocks() const
Number of parameter blocks.
Definition: MarginalizationError.hpp:170
Base class providing the interface for parameter blocks.
Definition: ParameterBlock.hpp:53
Eigen::VectorXd e0_
_e0 := pinv(J^T) * _b0
Definition: MarginalizationError.hpp:305