38 template <
typename Traits>
41 _linearSolver(linearSolver)
61 template <
typename Traits>
63 int* blockLandmarkIndices,
int numLandmarkBlocks,
72 assert(
_sizePoses > 0 &&
"allocating with wrong size");
86 _coefficientsMutex.resize(numPoseBlocks);
91 template <
typename Traits>
114 template <
typename Traits>
121 template <
typename Traits>
126 size_t sparseDim = 0;
151 delete[] blockLandmarkIndices;
152 delete[] blockPoseIndices;
188 for (
size_t viIdx = 0; viIdx < e->
vertices().size(); ++viIdx) {
193 int indexV1Bak = ind1;
194 for (
size_t vjIdx = viIdx + 1; vjIdx < e->
vertices().size(); ++vjIdx) {
200 bool transposedBlock = ind1 > ind2;
201 if (transposedBlock){
202 std::swap(ind1, ind2);
210 schurMatrixLookup->
addBlock(ind1, ind2);
245 for (HyperGraph::EdgeSet::const_iterator it1=vedges.begin(); it1!=vedges.end(); ++it1){
246 for (
size_t i=0; i<(*it1)->vertices().size(); ++i)
251 for (HyperGraph::EdgeSet::const_iterator it2=vedges.begin(); it2!=vedges.end(); ++it2){
252 for (
size_t j=0; j<(*it2)->vertices().size(); ++j)
260 schurMatrixLookup->
addBlock(i1, i2);
270 delete schurMatrixLookup;
276 template <
typename Traits>
279 for (std::vector<HyperGraph::Vertex*>::const_iterator vit = vset.begin(); vit != vset.end(); ++vit) {
293 std::cerr <<
"updateStructure(): Schur not supported" << std::endl;
299 for (HyperGraph::EdgeSet::const_iterator it = edges.begin(); it != edges.end(); ++it) {
302 for (
size_t viIdx = 0; viIdx < e->
vertices().size(); ++viIdx) {
305 int indexV1Bak = ind1;
308 for (
size_t vjIdx = viIdx + 1; vjIdx < e->
vertices().size(); ++vjIdx) {
314 bool transposedBlock = ind1 > ind2;
316 std::swap(ind1, ind2);
332 template <
typename Traits>
358 # pragma omp parallel for default (shared) schedule(dynamic, 10) 360 for (
int landmarkIndex = 0; landmarkIndex < static_cast<int>(
_Hll->
blockCols().size()); ++landmarkIndex) {
362 assert(marginalizeColumn.size() == 1 &&
"more than one block in _Hll column");
366 assert (D && D->rows()==D->cols() &&
"Error in landmark matrix");
371 for (
int j=0; j<D->rows(); ++j) {
376 assert((
size_t)landmarkIndex < _HplCCS->blockCols().size() &&
"Index out of bounds");
380 it_outer != landmarkColumn.end(); ++it_outer) {
381 int i1 = it_outer->row;
392 Bb.noalias() += (*Bi)*db;
399 for (; it_inner != landmarkColumn.end(); ++it_inner) {
400 int i2 = it_inner->row;
403 while (targetColumnIt->row < i2 )
405 assert(targetColumnIt !=
_HschurTransposedCCS->
blockCols()[i1].end() && targetColumnIt->row == i2 &&
"invalid iterator, something wrong with the matrix structure");
408 (*Hi1i2).noalias() -= BDinv*Bj->transpose();
468 template <
typename Traits>
480 template <
typename Traits>
485 # pragma omp parallel for default (shared) if (_optimizer->indexMapping().size() > 1000) 506 # pragma omp parallel for default (shared) firstprivate(jacobianWorkspace) if (_optimizer->activeEdges().size() > 100) 513 for (
size_t i = 0; i < e->
vertices().size(); ++i) {
518 std::cerr <<
"buildSystem(): NaN within Jacobian for edge " << e <<
" for vertex " << i << std::endl;
528 # pragma omp parallel for default (shared) if (_optimizer->indexMapping().size() > 1000) 542 template <
typename Traits>
550 # pragma omp parallel for default (shared) if (_numPoses > 100) 556 b->diagonal().array() += lambda;
559 # pragma omp parallel for default (shared) if (_numLandmarks > 100) 565 b->diagonal().array() += lambda;
570 template <
typename Traits>
585 template <
typename Traits>
601 template <
typename Traits>
607 template <
typename Traits>
const std::vector< int > & rowBlockIndices() const
indices of the row blocks
SparseBlockMatrix< PoseMatrixType > * _Hschur
Traits::PoseHessianType PoseHessianType
double get_monotonic_time()
int fillSparseBlockMatrixCCS(SparseBlockMatrixCCS< MatrixType > &blockCCS) const
std::vector< LandmarkVectorType, Eigen::aligned_allocator< LandmarkVectorType > > _diagonalBackupLandmark
statistics about the optimization
Traits::LandmarkMatrixType LandmarkMatrixType
void setColInHessian(int c)
set the row of this vertex in the Hessian
const Vertex * vertex(size_t i) const
virtual bool solve(const SparseBlockMatrix< MatrixType > &A, double *x, double *b)=0
#define __PRETTY_FUNCTION__
some general case utility functions
virtual bool solvePattern(SparseBlockMatrix< MatrixXD > &spinv, const std::vector< std::pair< int, int > > &blockIndices, const SparseBlockMatrix< MatrixType > &A)
virtual bool saveHessian(const std::string &fileName) const
write the hessian to disk using the specified file name
int dimension() const
returns the dimensions of the error function
int cols() const
columns of the matrix
virtual void setWriteDebug(bool writeDebug)
SparseBlockMatrix< PoseMatrixType > * _Hpp
Traits::LandmarkHessianType LandmarkHessianType
virtual int copyB(double *b_) const =0
void rightMultiply(double *&dest, const double *src) const
double * workspaceForVertex(int vertexIndex)
bool writeOctave(const char *filename, bool upperTriangle=true) const
SparseOptimizer * _optimizer
SparseBlockMatrixDiagonal< LandmarkMatrixType > * _DInvSchur
SparseMatrixBlock * block(int r, int c, bool alloc=false)
returns the block at location r,c. if alloc=true he block is created if it does not exist ...
virtual bool init(SparseOptimizer *optmizer, bool online=false)
void resize(int *blockPoseIndices, int numPoseBlocks, int *blockLandmarkIndices, int numLandmarkBlocks, int totalDim)
lock a mutex within a scope
const EdgeContainer & activeEdges() const
the edges active in the current optimization
int hessianIndex() const
temporary index of this node in the parameter vector obtained from linearization
SparseBlockMatrixCCS< PoseLandmarkMatrixType > * _HplCCS
SparseBlockMatrix< LandmarkMatrixType > * _Hll
void clear(bool dealloc=false)
this zeroes all the blocks. If dealloc=true the blocks are removed from memory
virtual void linearizeOplus(JacobianWorkspace &jacobianWorkspace)=0
Traits::PoseMatrixType PoseMatrixType
bool arrayHasNaN(const double *array, int size, int *nanIndex=0)
size_t hessianPoseDimension
dimension of the pose matrix in Schur
utility functions for handling time related stuff
JacobianWorkspace & jacobianWorkspace()
the workspace for storing the Jacobians of the graph
const DiagonalVector & diagonal() const
the block matrices per block-column
Traits::LinearSolverType LinearSolverType
const std::vector< int > & colBlockIndices() const
indices of the column blocks
std::set< Edge * > EdgeSet
int dimension() const
dimension of the estimated state belonging to this node
virtual void setWriteDebug(bool)
virtual bool buildStructure(bool zeroBlocks=false)
void takePatternFromHash(SparseBlockMatrixHashMap< MatrixType > &hashMatrix)
MatrixType * addBlock(int r, int c, bool zeroBlock=false)
const VertexContainer & vertices() const
virtual bool setLambda(double lambda, bool backup=false)
const EdgeSet & edges() const
returns the set of hyper-edges that are leaving/entering in this vertex
SparseBlockMatrixCCS< PoseMatrixType > * _HschurTransposedCCS
Traits::PoseLandmarkHessianType PoseLandmarkHessianType
virtual void constructQuadraticForm()=0
std::vector< PoseVectorType, Eigen::aligned_allocator< PoseVectorType > > _diagonalBackupPose
const std::vector< SparseColumn > & blockCols() const
the block matrices per block-column
virtual bool updateStructure(const std::vector< HyperGraph::Vertex * > &vset, const HyperGraph::EdgeSet &edges)
int colInHessian() const
get the row of this vertex in the Hessian
size_t hessianLandmarkDimension
dimension of the landmark matrix in Schur
Traits::PoseLandmarkMatrixType PoseLandmarkMatrixType
int fillSparseBlockMatrixCCSTransposed(SparseBlockMatrixCCS< MatrixType > &blockCCS) const
Traits::LandmarkVectorType LandmarkVectorType
static G2OBatchStatistics * globalStats()
const VertexContainer & indexMapping() const
the index mapping of the vertices
virtual bool computeMarginals(SparseBlockMatrix< MatrixXD > &spinv, const std::vector< std::pair< int, int > > &blockIndices)
void multiply(double *&dest, const double *src) const
void resizeVector(size_t sx)
SparseOptimizer * optimizer() const
the optimizer (graph) on which the solver works
virtual bool buildSystem()
virtual void mapHessianMemory(double *d)=0
virtual void clearQuadraticForm()=0
bool marginalized() const
true => this node is marginalized out during the optimization
const std::vector< IntBlockMap > & blockCols() const
the block matrices per block-column
A general case Vertex for optimization.
SparseBlockMatrix< PoseLandmarkMatrixType > * _Hpl
size_t hessianDimension
rows / cols of the Hessian
double * b()
return b, the right hand side of the system
bool fixed() const
true => this node is fixed during the optimization
LinearSolver< PoseMatrixType > * _linearSolver
double timeSchurComplement
compute schur complement (0 if not done)
provide memory workspace for computing the Jacobians
Sparse matrix which uses blocks based on hash structures.
virtual void mapHessianMemory(double *d, int i, int j, bool rowMajor)=0
bool add(SparseBlockMatrix< MatrixType > *&dest) const
adds the current matrix to the destination
const std::vector< SparseColumn > & blockCols() const
the block matrices per block-column
virtual bool writeDebug() const
BlockSolver(LinearSolverType *linearSolver)
int rowBaseOfBlock(int r) const
where does the row at block-row r start?
int rowBaseOfBlock(int r) const
where does the row at block-row r starts?
base for the block solvers with some basic function interfaces
Sparse matrix which uses blocks.
double timeLinearSolver
time for solving, excluding Schur setup
double timeMarginals
computing the inverse elements (solve blocks) and thus the marginal covariances
virtual void restoreDiagonal()