g2o
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
g2o::SparseOptimizer Class Reference

#include <sparse_optimizer.h>

Inheritance diagram for g2o::SparseOptimizer:
Inheritance graph
[legend]
Collaboration diagram for g2o::SparseOptimizer:
Collaboration graph
[legend]

Public Types

enum  { AT_COMPUTEACTIVERROR = OptimizableGraph::AT_NUM_ELEMENTS , AT_NUM_ELEMENTS }
 
- Public Types inherited from g2o::OptimizableGraph
enum  ActionType { AT_PREITERATION , AT_POSTITERATION , AT_NUM_ELEMENTS }
 
typedef std::set< HyperGraphAction * > HyperGraphActionSet
 
typedef std::vector< OptimizableGraph::Vertex * > VertexContainer
 vector container for vertices
 
typedef std::vector< OptimizableGraph::Edge * > EdgeContainer
 vector container for edges
 
- Public Types inherited from g2o::HyperGraph
typedef std::bitset< HyperGraph::HGET_NUM_ELEMS > GraphElemBitset
 
typedef std::set< Edge * > EdgeSet
 
typedef std::set< Vertex * > VertexSet
 
typedef std::unordered_map< int, Vertex * > VertexIDMap
 
typedef std::vector< Vertex * > VertexContainer
 

Public Member Functions

 SparseOptimizer ()
 
virtual ~SparseOptimizer ()
 
virtual bool initializeOptimization (HyperGraph::EdgeSet &eset)
 
virtual bool initializeOptimization (HyperGraph::VertexSet &vset, int level=0)
 
virtual bool initializeOptimization (int level=0)
 
virtual bool updateInitialization (HyperGraph::VertexSet &vset, HyperGraph::EdgeSet &eset)
 
virtual void computeInitialGuess ()
 
virtual void computeInitialGuess (EstimatePropagatorCost &propagator)
 
virtual void setToOrigin ()
 
int optimize (int iterations, bool online=false)
 
bool computeMarginals (SparseBlockMatrix< MatrixX > &spinv, const std::vector< std::pair< int, int > > &blockIndices)
 
bool computeMarginals (SparseBlockMatrix< MatrixX > &spinv, const Vertex *vertex)
 
bool computeMarginals (SparseBlockMatrix< MatrixX > &spinv, const VertexContainer &vertices)
 
virtual VertexfindGauge ()
 finds a gauge in the graph to remove the undefined dof.
 
bool gaugeFreedom ()
 
double activeChi2 () const
 
double activeRobustChi2 () const
 
bool verbose () const
 verbose information during optimization
 
void setVerbose (bool verbose)
 
void setForceStopFlag (bool *flag)
 
bool * forceStopFlag () const
 
bool terminate ()
 if external stop flag is given, return its state. False otherwise
 
const VertexContainerindexMapping () const
 the index mapping of the vertices
 
const VertexContaineractiveVertices () const
 the vertices active in the current optimization
 
const EdgeContaineractiveEdges () const
 the edges active in the current optimization
 
virtual bool removeVertex (HyperGraph::Vertex *v, bool detach=false)
 
VertexContainer::const_iterator findActiveVertex (const OptimizableGraph::Vertex *v) const
 
EdgeContainer::const_iterator findActiveEdge (const OptimizableGraph::Edge *e) const
 
const OptimizationAlgorithmalgorithm () const
 the solver used by the optimizer
 
OptimizationAlgorithmsolver ()
 
void setAlgorithm (OptimizationAlgorithm *algorithm)
 
void push (SparseOptimizer::VertexContainer &vlist)
 push the estimate of a subset of the variables onto a stack
 
void push (HyperGraph::VertexSet &vlist)
 push the estimate of a subset of the variables onto a stack
 
void push ()
 push all the active vertices onto a stack
 
void pop (SparseOptimizer::VertexContainer &vlist)
 pop (restore) the estimate a subset of the variables from the stack
 
void pop (HyperGraph::VertexSet &vlist)
 pop (restore) the estimate a subset of the variables from the stack
 
void pop ()
 pop (restore) the estimate of the active vertices from the stack
 
void discardTop (SparseOptimizer::VertexContainer &vlist)
 
void discardTop ()
 same as above, but for the active vertices
 
virtual void clear ()
 
void computeActiveErrors ()
 
 G2O_ATTRIBUTE_DEPRECATED (void linearizeSystem())
 
void update (const double *update)
 
const BatchStatisticsContainerbatchStatistics () const
 
BatchStatisticsContainerbatchStatistics ()
 
void setComputeBatchStatistics (bool computeBatchStatistics)
 
bool computeBatchStatistics () const
 
bool addComputeErrorAction (HyperGraphAction *action)
 add an action to be executed before the error vectors are computed
 
bool removeComputeErrorAction (HyperGraphAction *action)
 
virtual void discardTop ()
 
virtual void discardTop (HyperGraph::VertexSet &vset)
 
- Public Member Functions inherited from g2o::OptimizableGraph
Vertexvertex (int id)
 returns the vertex number id appropriately casted
 
const Vertexvertex (int id) const
 returns the vertex number id appropriately casted
 
 OptimizableGraph ()
 empty constructor
 
virtual ~OptimizableGraph ()
 
virtual bool addVertex (HyperGraph::Vertex *v, Data *userData)
 
virtual bool addVertex (HyperGraph::Vertex *v)
 
bool addVertex (OptimizableGraph::Vertex *v, Data *userData)
 
bool addVertex (OptimizableGraph::Vertex *v)
 
virtual bool addEdge (HyperGraph::Edge *e)
 
bool addEdge (OptimizableGraph::Edge *e)
 
virtual bool setEdgeVertex (HyperGraph::Edge *e, int pos, HyperGraph::Vertex *v)
 
double chi2 () const
 returns the chi2 of the current configuration
 
int maxDimension () const
 return the maximum dimension of all vertices in the graph
 
void recomputeJacobianWorkspaceSize ()
 
std::set< int > dimensions () const
 
virtual void preIteration (int)
 
virtual void postIteration (int)
 
bool addPreIterationAction (HyperGraphAction *action)
 add an action to be executed before each iteration
 
bool addPostIterationAction (HyperGraphAction *action)
 add an action to be executed after each iteration
 
bool removePreIterationAction (HyperGraphAction *action)
 remove an action that should no longer be executed before each iteration
 
bool removePostIterationAction (HyperGraphAction *action)
 remove an action that should no longer be executed after each iteration
 
virtual bool load (std::istream &is)
 
bool load (const char *filename)
 
virtual bool save (std::ostream &os, int level=0) const
 save the graph to a stream. Again uses the Factory system.
 
bool save (const char *filename, int level=0) const
 function provided for convenience, see save() above
 
bool saveSubset (std::ostream &os, HyperGraph::VertexSet &vset, int level=0)
 save a subgraph to a stream. Again uses the Factory system.
 
bool saveSubset (std::ostream &os, HyperGraph::EdgeSet &eset)
 save a subgraph to a stream. Again uses the Factory system.
 
virtual void setFixed (HyperGraph::VertexSet &vset, bool fixed)
 fixes/releases a set of vertices
 
void setRenamedTypesFromString (const std::string &types)
 
bool isSolverSuitable (const OptimizationAlgorithmProperty &solverProperty, const std::set< int > &vertDims=std::set< int >()) const
 
virtual void clearParameters ()
 
bool addParameter (Parameter *p)
 
Parameterparameter (int id)
 
bool verifyInformationMatrices (bool verbose=false) const
 
bool saveVertex (std::ostream &os, Vertex *v) const
 
bool saveParameter (std::ostream &os, Parameter *v) const
 
bool saveEdge (std::ostream &os, Edge *e) const
 
bool saveUserData (std::ostream &os, HyperGraph::Data *v) const
 
JacobianWorkspacejacobianWorkspace ()
 the workspace for storing the Jacobians of the graph
 
const JacobianWorkspacejacobianWorkspace () const
 
ParameterContainerparameters ()
 
const ParameterContainerparameters () const
 
void forEachVertex (std::function< void(OptimizableGraph::Vertex *)> fn)
 apply a unary function to all vertices
 
void forEachVertex (HyperGraph::VertexSet &vset, std::function< void(OptimizableGraph::Vertex *)> fn)
 apply a unary function to the vertices in vset
 
- Public Member Functions inherited from g2o::HyperGraph
 HyperGraph ()
 constructs an empty hyper graph
 
virtual ~HyperGraph ()
 destroys the hyper-graph and all the vertices of the graph
 
Vertexvertex (int id)
 
const Vertexvertex (int id) const
 
virtual bool removeEdge (Edge *e)
 
const VertexIDMapvertices () const
 
VertexIDMapvertices ()
 
const EdgeSetedges () const
 
EdgeSetedges ()
 
virtual bool mergeVertices (Vertex *vBig, Vertex *vSmall, bool erase)
 
virtual bool detachVertex (Vertex *v)
 
virtual bool changeId (Vertex *v, int newId)
 

Protected Member Functions

void sortVectorContainers ()
 
bool buildIndexMapping (SparseOptimizer::VertexContainer &vlist)
 
void clearIndexMapping ()
 
- Protected Member Functions inherited from g2o::OptimizableGraph
void performActions (int iter, HyperGraphActionSet &actions)
 

Protected Attributes

bool * _forceStopFlag
 
bool _verbose
 
VertexContainer _ivMap
 
VertexContainer _activeVertices
 sorted according to VertexIDCompare
 
EdgeContainer _activeEdges
 sorted according to EdgeIDCompare
 
OptimizationAlgorithm_algorithm
 
BatchStatisticsContainer _batchStatistics
 
bool _computeBatchStatistics
 
- Protected Attributes inherited from g2o::OptimizableGraph
std::map< std::string, std::string > _renamedTypesLookup
 
long long _nextEdgeId
 
std::vector< HyperGraphActionSet_graphActions
 
ParameterContainer _parameters
 
JacobianWorkspace _jacobianWorkspace
 
- Protected Attributes inherited from g2o::HyperGraph
VertexIDMap _vertices
 
EdgeSet _edges
 

Friends

class ActivePathCostFunction
 

Additional Inherited Members

- Static Public Member Functions inherited from g2o::OptimizableGraph
static bool initMultiThreading ()
 
- Public Attributes inherited from g2o::OptimizableGraph
class G2O_CORE_API Vertex
 
class G2O_CORE_API Edge
 
- Public Attributes inherited from g2o::HyperGraph
class G2O_CORE_API Data
 
class G2O_CORE_API DataContainer
 
class G2O_CORE_API Vertex
 
class G2O_CORE_API Edge
 
- Static Public Attributes inherited from g2o::HyperGraph
static const int UnassignedId = -1
 
static const int InvalidId = -2
 

Detailed Description

Definition at line 42 of file sparse_optimizer.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
AT_COMPUTEACTIVERROR 
AT_NUM_ELEMENTS 

Definition at line 44 of file sparse_optimizer.h.

Constructor & Destructor Documentation

◆ SparseOptimizer()

g2o::SparseOptimizer::SparseOptimizer ( )

Definition at line 52 of file sparse_optimizer.cpp.

53 : _forceStopFlag(0),
54 _verbose(false),
55 _algorithm(nullptr),
58}
OptimizationAlgorithm * _algorithm
std::vector< HyperGraphActionSet > _graphActions

References g2o::OptimizableGraph::_graphActions, and AT_NUM_ELEMENTS.

◆ ~SparseOptimizer()

g2o::SparseOptimizer::~SparseOptimizer ( )
virtual

Definition at line 60 of file sparse_optimizer.cpp.

60 {
63}
void release(T *obj)
Definition ownership.h:8
static void setGlobalStats(G2OBatchStatistics *b)

References _algorithm, g2o::release(), and g2o::G2OBatchStatistics::setGlobalStats().

Member Function Documentation

◆ activeChi2()

double g2o::SparseOptimizer::activeChi2 ( ) const

returns the cached chi2 of the active portion of the graph

Definition at line 94 of file sparse_optimizer.cpp.

94 {
95 double chi = 0.0;
96 for (EdgeContainer::const_iterator it = _activeEdges.begin();
97 it != _activeEdges.end(); ++it) {
98 const OptimizableGraph::Edge* e = *it;
99 chi += e->chi2();
100 }
101 return chi;
102}
EdgeContainer _activeEdges
sorted according to EdgeIDCompare

References _activeEdges, and g2o::OptimizableGraph::Edge::chi2().

Referenced by computeInitialGuess(), main(), g2o::SparseOptimizerIncremental::optimize(), and g2o::SparseOptimizerOnline::optimize().

◆ activeEdges()

const EdgeContainer & g2o::SparseOptimizer::activeEdges ( ) const
inline

◆ activeRobustChi2()

double g2o::SparseOptimizer::activeRobustChi2 ( ) const

returns the cached chi2 of the active portion of the graph. In contrast to activeChi2() this functions considers the weighting of the error according to the robustification of the error functions.

Definition at line 104 of file sparse_optimizer.cpp.

104 {
105 Vector3 rho;
106 double chi = 0.0;
107 for (EdgeContainer::const_iterator it = _activeEdges.begin();
108 it != _activeEdges.end(); ++it) {
109 const OptimizableGraph::Edge* e = *it;
110 if (e->robustKernel()) {
111 e->robustKernel()->robustify(e->chi2(), rho);
112 chi += rho[0];
113 } else
114 chi += e->chi2();
115 }
116 return chi;
117}
VectorN< 3 > Vector3
Definition eigen_types.h:51

References _activeEdges, g2o::OptimizableGraph::Edge::chi2(), g2o::RobustKernel::robustify(), and g2o::OptimizableGraph::Edge::robustKernel().

Referenced by g2o::SparseOptimizerTerminateAction::operator()(), optimize(), g2o::OptimizationAlgorithmDogleg::solve(), and g2o::OptimizationAlgorithmLevenberg::solve().

◆ activeVertices()

const VertexContainer & g2o::SparseOptimizer::activeVertices ( ) const
inline

the vertices active in the current optimization

Definition at line 188 of file sparse_optimizer.h.

188{ return _activeVertices; }
VertexContainer _activeVertices
sorted according to VertexIDCompare

Referenced by g2o::OptimizationAlgorithmWithHessian::init(), g2o::StructureOnlySolver< PointDoF >::init(), g2o::Star::labelStarEdges(), main(), and testMarginals().

◆ addComputeErrorAction()

bool g2o::SparseOptimizer::addComputeErrorAction ( HyperGraphAction action)

add an action to be executed before the error vectors are computed

Definition at line 614 of file sparse_optimizer.cpp.

614 {
615 std::pair<HyperGraphActionSet::iterator, bool> insertResult =
616 _graphActions[AT_COMPUTEACTIVERROR].insert(action);
617 return insertResult.second;
618}

References g2o::OptimizableGraph::_graphActions, and AT_COMPUTEACTIVERROR.

◆ algorithm()

const OptimizationAlgorithm * g2o::SparseOptimizer::algorithm ( ) const
inline

the solver used by the optimizer

Definition at line 214 of file sparse_optimizer.h.

214{ return _algorithm; }

Referenced by setAlgorithm().

◆ batchStatistics() [1/2]

BatchStatisticsContainer & g2o::SparseOptimizer::batchStatistics ( )
inline

returns the set of batch statistics about the optimisation

Definition at line 274 of file sparse_optimizer.h.

274{ return _batchStatistics; }
BatchStatisticsContainer _batchStatistics

◆ batchStatistics() [2/2]

const BatchStatisticsContainer & g2o::SparseOptimizer::batchStatistics ( ) const
inline

returns the set of batch statistics about the optimisation

Definition at line 268 of file sparse_optimizer.h.

268 {
269 return _batchStatistics;
270 }

Referenced by main().

◆ buildIndexMapping()

bool g2o::SparseOptimizer::buildIndexMapping ( SparseOptimizer::VertexContainer vlist)
protected

builds the mapping of the active vertices to the (block) row / column in the Hessian

Definition at line 162 of file sparse_optimizer.cpp.

163 {
164 if (!vlist.size()) {
165 _ivMap.clear();
166 return false;
167 }
168
169 _ivMap.resize(vlist.size());
170 size_t i = 0;
171 for (int k = 0; k < 2; k++)
172 for (VertexContainer::iterator it = vlist.begin(); it != vlist.end();
173 ++it) {
174 OptimizableGraph::Vertex* v = *it;
175 if (!v->fixed()) {
176 if (static_cast<int>(v->marginalized()) == k) {
177 v->setHessianIndex(i);
178 _ivMap[i] = v;
179 i++;
180 }
181 } else {
182 v->setHessianIndex(-1);
183 }
184 }
185 _ivMap.resize(i);
186 return true;
187}

References _ivMap, g2o::OptimizableGraph::Vertex::fixed(), g2o::OptimizableGraph::Vertex::marginalized(), g2o::HyperGraph::Edge::resize(), and g2o::OptimizableGraph::Vertex::setHessianIndex().

Referenced by initializeOptimization(), and initializeOptimization().

◆ clear()

void g2o::SparseOptimizer::clear ( )
virtual

clears the graph, and polishes some intermediate structures Note that this only removes nodes / edges. Parameters can be removed with clearParameters().

Reimplemented from g2o::HyperGraph.

Definition at line 513 of file sparse_optimizer.cpp.

513 {
514 _ivMap.clear();
515 _activeVertices.clear();
516 _activeEdges.clear();
518}
virtual void clear()
clears the graph and empties all structures.

References _activeEdges, _activeVertices, _ivMap, and g2o::HyperGraph::clear().

Referenced by g2o::BlockSolver< Traits >::init(), main(), main(), and g2o::Gm2dlIO::readGm2dl().

◆ clearIndexMapping()

void g2o::SparseOptimizer::clearIndexMapping ( )
protected

Definition at line 189 of file sparse_optimizer.cpp.

189 {
190 for (size_t i = 0; i < _ivMap.size(); ++i) {
191 _ivMap[i]->setHessianIndex(-1);
192 _ivMap[i] = 0;
193 }
194}

References _ivMap.

Referenced by initializeOptimization(), initializeOptimization(), and removeVertex().

◆ computeActiveErrors()

void g2o::SparseOptimizer::computeActiveErrors ( )

computes the error vectors of all edges in the activeSet, and caches them

Definition at line 65 of file sparse_optimizer.cpp.

65 {
66 // call the callbacks in case there is something registered
68 if (actions.size() > 0) {
69 for (HyperGraphActionSet::iterator it = actions.begin();
70 it != actions.end(); ++it)
71 (*(*it))(this);
72 }
73
74#ifdef G2O_OPENMP
75#pragma omp parallel for default(shared) if (_activeEdges.size() > 50)
76#endif
77 for (int k = 0; k < static_cast<int>(_activeEdges.size()); ++k) {
78 OptimizableGraph::Edge* e = _activeEdges[k];
79 e->computeError();
80 }
81
82#ifndef NDEBUG
83 for (int k = 0; k < static_cast<int>(_activeEdges.size()); ++k) {
84 OptimizableGraph::Edge* e = _activeEdges[k];
85 bool hasNan = arrayHasNaN(e->errorData(), e->dimension());
86 if (hasNan) {
87 G2O_WARN("computeActiveErrors(): found NaN in error for edge {}",
88 static_cast<void*>(e));
89 }
90 }
91#endif
92}
#define G2O_WARN(...)
Definition logger.h:88
bool arrayHasNaN(const double *array, int size, int *nanIndex=0)
Definition misc.h:168
std::set< HyperGraphAction * > HyperGraphActionSet

References _activeEdges, g2o::OptimizableGraph::_graphActions, g2o::arrayHasNaN(), AT_COMPUTEACTIVERROR, g2o::OptimizableGraph::Edge::computeError(), g2o::OptimizableGraph::Edge::dimension(), g2o::OptimizableGraph::Edge::errorData(), and G2O_WARN.

Referenced by computeInitialGuess(), g2o::computeSimpleStars(), g2o::Star::labelStarEdges(), main(), main(), optimize(), g2o::SparseOptimizerIncremental::optimize(), g2o::SparseOptimizerOnline::optimize(), g2o::OptimizationAlgorithmDogleg::solve(), g2o::OptimizationAlgorithmGaussNewton::solve(), and g2o::OptimizationAlgorithmLevenberg::solve().

◆ computeBatchStatistics()

bool g2o::SparseOptimizer::computeBatchStatistics ( ) const
inline

Definition at line 278 of file sparse_optimizer.h.

278{ return _computeBatchStatistics; }

Referenced by setComputeBatchStatistics().

◆ computeInitialGuess() [1/2]

void g2o::SparseOptimizer::computeInitialGuess ( )
virtual

Propagates an initial guess from the vertex specified as origin. It should be called after initializeOptimization(...), as it relies on the _activeVertices/_edges structures. It constructs a set of trees starting from the nodes in the graph which are fixed and eligible for preforming optimization. The trees are constructed by utlizing a cost-function specified.

Parameters
costFunctionthe cost function used @patam maxDistance: the distance where to stop the search

Definition at line 320 of file sparse_optimizer.cpp.

320 {
321 EstimatePropagator::PropagateCost costFunction(this);
322 computeInitialGuess(costFunction);
323}
EstimatePropagatorCost PropagateCost
virtual void computeInitialGuess()

References computeInitialGuess().

Referenced by computeInitialGuess(), g2o::computeSimpleStars(), g2o::Star::labelStarEdges(), and main().

◆ computeInitialGuess() [2/2]

void g2o::SparseOptimizer::computeInitialGuess ( EstimatePropagatorCost propagator)
virtual

Same as above but using a specific propagator

Definition at line 325 of file sparse_optimizer.cpp.

326 {
328 std::set<Vertex*> backupVertices;
329 HyperGraph::VertexSet fixedVertices; // these are the root nodes where to
330 // start the initialization
331 for (EdgeContainer::iterator it = _activeEdges.begin();
332 it != _activeEdges.end(); ++it) {
333 OptimizableGraph::Edge* e = *it;
334 for (size_t i = 0; i < e->vertices().size(); ++i) {
335 OptimizableGraph::Vertex* v =
336 static_cast<OptimizableGraph::Vertex*>(e->vertex(i));
337 if (!v) continue;
338 if (v->fixed())
339 fixedVertices.insert(v);
340 else { // check for having a prior which is able to fully initialize a
341 // vertex
342 for (EdgeSet::const_iterator vedgeIt = v->edges().begin();
343 vedgeIt != v->edges().end(); ++vedgeIt) {
344 OptimizableGraph::Edge* vedge =
345 static_cast<OptimizableGraph::Edge*>(*vedgeIt);
346 if (vedge->vertices().size() == 1 &&
347 vedge->initialEstimatePossible(emptySet, v) > 0.) {
348 vedge->initialEstimate(emptySet, v);
349 fixedVertices.insert(v);
350 }
351 }
352 }
353 if (v->hessianIndex() == -1) {
354 std::set<Vertex*>::const_iterator foundIt = backupVertices.find(v);
355 if (foundIt == backupVertices.end()) {
356 v->push();
357 backupVertices.insert(v);
358 }
359 }
360 }
361 }
362
363 EstimatePropagator estimatePropagator(this);
364 estimatePropagator.propagate(fixedVertices, costFunction);
365
366 // restoring the vertices that should not be initialized
367 for (std::set<Vertex*>::iterator it = backupVertices.begin();
368 it != backupVertices.end(); ++it) {
369 Vertex* v = *it;
370 v->pop();
371 }
372 if (verbose()) {
374 cerr << "iteration= -1\t chi2= " << activeChi2() << "\t time= 0.0"
375 << "\t cumTime= 0.0"
376 << "\t (using initial guess from " << costFunction.name() << ")"
377 << endl;
378 }
379}
std::set< Vertex * > VertexSet
bool verbose() const
verbose information during optimization
class G2O_CORE_API Vertex

References _activeEdges, activeChi2(), computeActiveErrors(), g2o::HyperGraph::Vertex::edges(), g2o::OptimizableGraph::Vertex::fixed(), g2o::OptimizableGraph::Vertex::hessianIndex(), g2o::OptimizableGraph::Edge::initialEstimate(), g2o::OptimizableGraph::Edge::initialEstimatePossible(), g2o::EstimatePropagatorCost::name(), g2o::EstimatePropagator::propagate(), g2o::OptimizableGraph::Vertex::push(), verbose(), g2o::HyperGraph::Edge::vertex(), and g2o::HyperGraph::Edge::vertices().

◆ computeMarginals() [1/3]

bool g2o::SparseOptimizer::computeMarginals ( SparseBlockMatrix< MatrixX > &  spinv,
const std::vector< std::pair< int, int > > &  blockIndices 
)

computes the blocks of the inverse of the specified pattern. the pattern is given via pairs <row, col> of the blocks in the hessian

Parameters
blockIndicesthe pattern
spinvthe sparse block matrix with the result
Returns
false if the operation is not supported by the solver

Definition at line 576 of file sparse_optimizer.cpp.

578 {
579 return _algorithm->computeMarginals(spinv, blockIndices);
580}
virtual bool computeMarginals(SparseBlockMatrix< MatrixX > &spinv, const std::vector< std::pair< int, int > > &blockIndices)=0

References _algorithm, and g2o::OptimizationAlgorithm::computeMarginals().

Referenced by computeMarginals(), computeMarginals(), g2o::EdgeLabeler::computePartialInverse(), main(), main(), and testMarginals().

◆ computeMarginals() [2/3]

bool g2o::SparseOptimizer::computeMarginals ( SparseBlockMatrix< MatrixX > &  spinv,
const Vertex vertex 
)

computes the inverse of the specified vertex.

Parameters
vertexthe vertex whose state is to be marginalised
spinvthe sparse block matrix with the result
Returns
false if the operation is not supported by the solver

Definition at line 582 of file sparse_optimizer.cpp.

583 {
584 if (vertex->hessianIndex() < 0) {
585 return false;
586 }
587 std::vector<std::pair<int, int> > index{
588 std::make_pair<int, int>(vertex->hessianIndex(), vertex->hessianIndex())};
589 return computeMarginals(spinv, index);
590}
bool computeMarginals(SparseBlockMatrix< MatrixX > &spinv, const std::vector< std::pair< int, int > > &blockIndices)
Vertex * vertex(int id)
returns the vertex number id appropriately casted

References computeMarginals(), and g2o::OptimizableGraph::vertex().

◆ computeMarginals() [3/3]

bool g2o::SparseOptimizer::computeMarginals ( SparseBlockMatrix< MatrixX > &  spinv,
const VertexContainer vertices 
)

computes the inverse of the set specified vertices, assembled into a single covariance matrix.

Parameters
vertexthe pattern
spinvthe sparse block matrix with the result
Returns
false if the operation is not supported by the solver

Definition at line 592 of file sparse_optimizer.cpp.

593 {
594 std::vector<std::pair<int, int> > indices;
595 indices.reserve(vertices.size());
596 for (VertexContainer::const_iterator it = vertices.begin();
597 it != vertices.end(); ++it) {
598 indices.emplace_back((*it)->hessianIndex(), (*it)->hessianIndex());
599 }
600 return computeMarginals(spinv, indices);
601}
const VertexIDMap & vertices() const

References computeMarginals(), and g2o::HyperGraph::vertices().

◆ discardTop() [1/4]

void g2o::SparseOptimizer::discardTop ( )
virtual

same as above, but for the active vertices

Reimplemented from g2o::OptimizableGraph.

Definition at line 628 of file sparse_optimizer.cpp.

void discardTop()
same as above, but for the active vertices

References _activeVertices, and discardTop().

Referenced by discardTop().

◆ discardTop() [2/4]

void g2o::OptimizableGraph::discardTop ( )
virtual

discard the last backup of the estimate for all variables by removing it from the stack

Reimplemented from g2o::OptimizableGraph.

Definition at line 665 of file optimizable_graph.cpp.

309 {
310 forEachVertex([](OptimizableGraph::Vertex* v) { v->discardTop(); });
311}
void forEachVertex(std::function< void(OptimizableGraph::Vertex *)> fn)
apply a unary function to all vertices

References g2o::OptimizationAlgorithmProperty::landmarkDim, g2o::OptimizationAlgorithmProperty::poseDim, and g2o::OptimizationAlgorithmProperty::requiresMarginalize.

◆ discardTop() [3/4]

void g2o::OptimizableGraph::discardTop ( HyperGraph::VertexSet vset)
virtual

ignore the latest stored element on the stack, remove it from the stack but do not restore the estimate

Reimplemented from g2o::OptimizableGraph.

Definition at line 688 of file optimizable_graph.cpp.

321 {
322 forEachVertex(vset, [](OptimizableGraph::Vertex* v) { v->discardTop(); });
323}

◆ discardTop() [4/4]

void g2o::SparseOptimizer::discardTop ( SparseOptimizer::VertexContainer vlist)

ignore the latest stored element on the stack, remove it from the stack but do not restore the estimate

Definition at line 556 of file sparse_optimizer.cpp.

556 {
557 for (VertexContainer::iterator it = vlist.begin(); it != vlist.end(); ++it)
558 (*it)->discardTop();
559}

Referenced by g2o::OptimizationAlgorithmDogleg::solve(), and g2o::OptimizationAlgorithmLevenberg::solve().

◆ findActiveEdge()

SparseOptimizer::EdgeContainer::const_iterator g2o::SparseOptimizer::findActiveEdge ( const OptimizableGraph::Edge e) const

search for an edge in _activeEdges and return the iterator pointing to it getActiveEdges().end() if not found

Definition at line 529 of file sparse_optimizer.cpp.

530 {
531 EdgeContainer::const_iterator lower =
532 lower_bound(_activeEdges.begin(), _activeEdges.end(), e, EdgeIDCompare());
533 if (lower == _activeEdges.end()) return _activeEdges.end();
534 if ((*lower) == e) return lower;
535 return _activeEdges.end();
536}

References _activeEdges.

Referenced by g2o::activeVertexChi(), g2o::EstimatePropagatorCost::operator()(), and g2o::EstimatePropagatorCostOdometry::operator()().

◆ findActiveVertex()

SparseOptimizer::VertexContainer::const_iterator g2o::SparseOptimizer::findActiveVertex ( const OptimizableGraph::Vertex v) const

search for an edge in _activeVertices and return the iterator pointing to it getActiveVertices().end() if not found

Definition at line 521 of file sparse_optimizer.cpp.

521 {
522 VertexContainer::const_iterator lower = lower_bound(
523 _activeVertices.begin(), _activeVertices.end(), v, VertexIDCompare());
524 if (lower == _activeVertices.end()) return _activeVertices.end();
525 if ((*lower) == v) return lower;
526 return _activeVertices.end();
527}

References _activeVertices.

◆ findGauge()

OptimizableGraph::Vertex * g2o::SparseOptimizer::findGauge ( )
virtual

finds a gauge in the graph to remove the undefined dof.

Definition at line 119 of file sparse_optimizer.cpp.

119 {
120 if (vertices().empty()) return nullptr;
121
122 int maxDim = maxDimension();
123
124 OptimizableGraph::Vertex* rut = 0;
125 for (HyperGraph::VertexIDMap::iterator it = vertices().begin();
126 it != vertices().end(); ++it) {
127 OptimizableGraph::Vertex* v =
128 static_cast<OptimizableGraph::Vertex*>(it->second);
129 if (v->dimension() == maxDim) {
130 rut = v;
131 break;
132 }
133 }
134 return rut;
135}
int maxDimension() const
return the maximum dimension of all vertices in the graph

References g2o::OptimizableGraph::Vertex::dimension(), g2o::OptimizableGraph::maxDimension(), and g2o::HyperGraph::vertices().

Referenced by main().

◆ forceStopFlag()

bool * g2o::SparseOptimizer::forceStopFlag ( ) const
inline

Definition at line 180 of file sparse_optimizer.h.

180{ return _forceStopFlag; };

Referenced by g2o::SparseOptimizerTerminateAction::setOptimizerStopFlag().

◆ G2O_ATTRIBUTE_DEPRECATED()

g2o::SparseOptimizer::G2O_ATTRIBUTE_DEPRECATED ( void   linearizeSystem())
inline

Linearizes the system by computing the Jacobians for the nodes and edges in the graph

Definition at line 254 of file sparse_optimizer.h.

254 {
255 // nothing needed, linearization is now done inside the solver
256 }

◆ gaugeFreedom()

bool g2o::SparseOptimizer::gaugeFreedom ( )

Definition at line 137 of file sparse_optimizer.cpp.

137 {
138 if (vertices().empty()) return false;
139
140 int maxDim = maxDimension();
141
142 for (HyperGraph::VertexIDMap::iterator it = vertices().begin();
143 it != vertices().end(); ++it) {
144 OptimizableGraph::Vertex* v =
145 static_cast<OptimizableGraph::Vertex*>(it->second);
146 if (v->dimension() == maxDim) {
147 // test for fixed vertex
148 if (v->fixed()) {
149 return false;
150 }
151 // test for full dimension prior
152 for (HyperGraph::EdgeSet::const_iterator eit = v->edges().begin();
153 eit != v->edges().end(); ++eit) {
154 OptimizableGraph::Edge* e = static_cast<OptimizableGraph::Edge*>(*eit);
155 if (e->vertices().size() == 1 && e->dimension() == maxDim) return false;
156 }
157 }
158 }
159 return true;
160}

References g2o::OptimizableGraph::Vertex::dimension(), g2o::OptimizableGraph::Edge::dimension(), g2o::HyperGraph::Vertex::edges(), g2o::OptimizableGraph::Vertex::fixed(), g2o::OptimizableGraph::maxDimension(), g2o::HyperGraph::Edge::vertices(), and g2o::HyperGraph::vertices().

Referenced by main().

◆ indexMapping()

const VertexContainer & g2o::SparseOptimizer::indexMapping ( ) const
inline

◆ initializeOptimization() [1/3]

bool g2o::SparseOptimizer::initializeOptimization ( HyperGraph::EdgeSet eset)
virtual

Initializes the structures for optimizing a portion of the graph specified by a subset of edges. Before calling it be sure to invoke marginalized() and fixed() to the vertices you want to include in the schur complement or to set as fixed during the optimization.

Parameters
esetthe subgraph to be optimized.
Returns
false if somethings goes wrong

Definition at line 277 of file sparse_optimizer.cpp.

277 {
278 preIteration(-1);
279 bool workspaceAllocated = _jacobianWorkspace.allocate();
280 (void)workspaceAllocated;
281 assert(workspaceAllocated &&
282 "Error while allocating memory for the Jacobians");
284 _activeVertices.clear();
285 _activeEdges.clear();
286 _activeEdges.reserve(eset.size());
287 set<Vertex*> auxVertexSet; // temporary structure to avoid duplicates
288 for (HyperGraph::EdgeSet::iterator it = eset.begin(); it != eset.end();
289 ++it) {
290 OptimizableGraph::Edge* e = (OptimizableGraph::Edge*)(*it);
291 if (e->numUndefinedVertices()) continue;
292 for (vector<HyperGraph::Vertex*>::const_iterator vit =
293 e->vertices().begin();
294 vit != e->vertices().end(); ++vit) {
295 auxVertexSet.insert(static_cast<OptimizableGraph::Vertex*>(*vit));
296 }
297 _activeEdges.push_back(reinterpret_cast<OptimizableGraph::Edge*>(*it));
298 }
299
300 _activeVertices.reserve(auxVertexSet.size());
301 for (set<Vertex*>::iterator it = auxVertexSet.begin();
302 it != auxVertexSet.end(); ++it)
303 _activeVertices.push_back(*it);
304
306 bool indexMappingStatus = buildIndexMapping(_activeVertices);
307 postIteration(-1);
308 return indexMappingStatus;
309}
bool buildIndexMapping(SparseOptimizer::VertexContainer &vlist)
JacobianWorkspace _jacobianWorkspace
virtual void postIteration(int)
virtual void preIteration(int)

References _activeEdges, _activeVertices, g2o::OptimizableGraph::_jacobianWorkspace, g2o::JacobianWorkspace::allocate(), buildIndexMapping(), clearIndexMapping(), g2o::HyperGraph::Edge::numUndefinedVertices(), g2o::OptimizableGraph::postIteration(), g2o::OptimizableGraph::preIteration(), sortVectorContainers(), and g2o::HyperGraph::Edge::vertices().

Referenced by g2o::computeSimpleStars(), initializeOptimization(), g2o::Star::labelStarEdges(), main(), main(), main(), and g2o::G2oSlamInterface::solve().

◆ initializeOptimization() [2/3]

bool g2o::SparseOptimizer::initializeOptimization ( HyperGraph::VertexSet vset,
int  level = 0 
)
virtual

Initializes the structures for optimizing a portion of the graph specified by a subset of vertices. Before calling it be sure to invoke marginalized() and fixed() to the vertices you want to include in the schur complement or to set as fixed during the optimization.

Parameters
vsetthe subgraph to be optimized.
levelis the level (in multilevel optimization)
Returns
false if somethings goes wrong

Definition at line 204 of file sparse_optimizer.cpp.

205 {
206 if (edges().size() == 0) {
207 G2O_WARN("Attempt to initialize an empty graph");
208 return false;
209 }
210 preIteration(-1);
211 bool workspaceAllocated = _jacobianWorkspace.allocate();
212 (void)workspaceAllocated;
213 assert(workspaceAllocated &&
214 "Error while allocating memory for the Jacobians");
216 _activeVertices.clear();
217 _activeVertices.reserve(vset.size());
218 _activeEdges.clear();
219 set<Edge*> auxEdgeSet; // temporary structure to avoid duplicates
220 for (HyperGraph::VertexSet::iterator it = vset.begin(); it != vset.end();
221 ++it) {
222 OptimizableGraph::Vertex* v = (OptimizableGraph::Vertex*)*it;
223 const OptimizableGraph::EdgeSet& vEdges = v->edges();
224 // count if there are edges in that level. If not remove from the pool
225 int levelEdges = 0;
226 for (OptimizableGraph::EdgeSet::const_iterator it = vEdges.begin();
227 it != vEdges.end(); ++it) {
228 OptimizableGraph::Edge* e =
229 reinterpret_cast<OptimizableGraph::Edge*>(*it);
230 if (level < 0 || e->level() == level) {
231 bool allVerticesOK = true;
232 for (vector<HyperGraph::Vertex*>::const_iterator vit =
233 e->vertices().begin();
234 vit != e->vertices().end(); ++vit) {
235 if (vset.find(*vit) == vset.end()) {
236 allVerticesOK = false;
237 break;
238 }
239 }
240 if (allVerticesOK && !e->allVerticesFixed()) {
241 auxEdgeSet.insert(e);
242 levelEdges++;
243 }
244 }
245 }
246 if (levelEdges) {
247 _activeVertices.push_back(v);
248
249 // test for NANs in the current estimate if we are debugging
250#ifndef NDEBUG
251 int estimateDim = v->estimateDimension();
252 if (estimateDim > 0) {
253 VectorX estimateData(estimateDim);
254 if (v->getEstimateData(estimateData.data()) == true) {
255 int k;
256 bool hasNan = arrayHasNaN(estimateData.data(), estimateDim, &k);
257 if (hasNan)
258 G2O_WARN("{}: Vertex {} contains a nan entry at index {}",
259 __PRETTY_FUNCTION__, v->id(), k);
260 }
261 }
262#endif
263 }
264 }
265
266 _activeEdges.reserve(auxEdgeSet.size());
267 for (set<Edge*>::iterator it = auxEdgeSet.begin(); it != auxEdgeSet.end();
268 ++it)
269 _activeEdges.push_back(*it);
270
272 bool indexMappingStatus = buildIndexMapping(_activeVertices);
273 postIteration(-1);
274 return indexMappingStatus;
275}
std::set< Edge * > EdgeSet
const EdgeSet & edges() const
#define __PRETTY_FUNCTION__
Definition macros.h:90
VectorN< Eigen::Dynamic > VectorX
Definition eigen_types.h:55

References __PRETTY_FUNCTION__, _activeEdges, _activeVertices, g2o::OptimizableGraph::_jacobianWorkspace, g2o::JacobianWorkspace::allocate(), g2o::OptimizableGraph::Edge::allVerticesFixed(), g2o::arrayHasNaN(), buildIndexMapping(), clearIndexMapping(), g2o::HyperGraph::Vertex::edges(), g2o::HyperGraph::edges(), g2o::OptimizableGraph::Vertex::estimateDimension(), G2O_WARN, g2o::OptimizableGraph::Vertex::getEstimateData(), g2o::HyperGraph::Vertex::id(), g2o::OptimizableGraph::postIteration(), g2o::OptimizableGraph::preIteration(), sortVectorContainers(), and g2o::HyperGraph::Edge::vertices().

◆ initializeOptimization() [3/3]

bool g2o::SparseOptimizer::initializeOptimization ( int  level = 0)
virtual

Initializes the structures for optimizing the whole graph. Before calling it be sure to invoke marginalized() and fixed() to the vertices you want to include in the schur complement or to set as fixed during the optimization.

Parameters
levelis the level (in multilevel optimization)
Returns
false if somethings goes wrong

Definition at line 196 of file sparse_optimizer.cpp.

196 {
198 for (VertexIDMap::iterator it = vertices().begin(); it != vertices().end();
199 ++it)
200 vset.insert(it->second);
201 return initializeOptimization(vset, level);
202}
virtual bool initializeOptimization(HyperGraph::EdgeSet &eset)

References initializeOptimization(), and g2o::HyperGraph::vertices().

◆ optimize()

int g2o::SparseOptimizer::optimize ( int  iterations,
bool  online = false 
)
virtual

starts one optimization run given the current configuration of the graph, and the current settings stored in the class instance. It can be called only after initializeOptimization

Reimplemented from g2o::OptimizableGraph.

Reimplemented in g2o::SparseOptimizerIncremental, and g2o::SparseOptimizerOnline.

Definition at line 381 of file sparse_optimizer.cpp.

381 {
382 if (_ivMap.size() == 0) {
383 G2O_WARN(
384 "{}: 0 vertices to optimize, maybe forgot to call "
385 "initializeOptimization()",
387 return -1;
388 }
389
390 int cjIterations = 0;
391 double cumTime = 0;
392 bool ok = true;
393
394 ok = _algorithm->init(online);
395 if (!ok) {
396 G2O_ERROR("{}: Error while initializing", __PRETTY_FUNCTION__);
397 return -1;
398 }
399
400 _batchStatistics.clear();
401 if (_computeBatchStatistics) _batchStatistics.resize(iterations);
402
403 OptimizationAlgorithm::SolverResult result = OptimizationAlgorithm::OK;
404 for (int i = 0; i < iterations && !terminate() && ok; i++) {
405 preIteration(i);
406
408 G2OBatchStatistics& cstat = _batchStatistics[i];
410 cstat.iteration = i;
411 cstat.numEdges = _activeEdges.size();
412 cstat.numVertices = _activeVertices.size();
413 }
414
415 double ts = get_monotonic_time();
416 result = _algorithm->solve(i, online);
417 ok = (result == OptimizationAlgorithm::OK);
418
419 bool errorComputed = false;
422 errorComputed = true;
424 _batchStatistics[i].timeIteration = get_monotonic_time() - ts;
425 }
426
427 if (verbose()) {
428 double dts = get_monotonic_time() - ts;
429 cumTime += dts;
430 if (!errorComputed) computeActiveErrors();
431 cerr << "iteration= " << i << "\t chi2= " << FIXED(activeRobustChi2())
432 << "\t time= " << dts << "\t cumTime= " << cumTime
433 << "\t edges= " << _activeEdges.size();
435 cerr << endl;
436 }
437 ++cjIterations;
438 postIteration(i);
439 }
440 if (result == OptimizationAlgorithm::Fail) {
441 return 0;
442 }
443 return cjIterations;
444}
virtual void printVerbose(std::ostream &os) const
virtual SolverResult solve(int iteration, bool online=false)=0
virtual bool init(bool online=false)=0
double activeRobustChi2() const
bool terminate()
if external stop flag is given, return its state. False otherwise
#define G2O_ERROR(...)
Definition logger.h:89
double get_monotonic_time()
Definition timeutil.cpp:43

References __PRETTY_FUNCTION__, _activeEdges, _activeVertices, _algorithm, _batchStatistics, _computeBatchStatistics, _ivMap, activeRobustChi2(), computeActiveErrors(), G2O_ERROR, G2O_WARN, g2o::get_monotonic_time(), g2o::OptimizationAlgorithm::init(), g2o::G2OBatchStatistics::iteration, g2o::G2OBatchStatistics::numEdges, g2o::G2OBatchStatistics::numVertices, g2o::OptimizableGraph::postIteration(), g2o::OptimizableGraph::preIteration(), g2o::OptimizationAlgorithm::printVerbose(), g2o::G2OBatchStatistics::setGlobalStats(), g2o::OptimizationAlgorithm::solve(), terminate(), and verbose().

Referenced by g2o::computeSimpleStars(), g2o::Star::labelStarEdges(), main(), main(), and main().

◆ pop() [1/3]

void g2o::SparseOptimizer::pop ( )
virtual

pop (restore) the estimate of the active vertices from the stack

Reimplemented from g2o::OptimizableGraph.

Definition at line 626 of file sparse_optimizer.cpp.

void pop()
pop (restore) the estimate of the active vertices from the stack

References _activeVertices, and pop().

Referenced by pop().

◆ pop() [2/3]

void g2o::SparseOptimizer::pop ( HyperGraph::VertexSet vlist)
virtual

pop (restore) the estimate a subset of the variables from the stack

Reimplemented from g2o::OptimizableGraph.

Definition at line 552 of file sparse_optimizer.cpp.

552 {
554}
virtual void pop()
pop (restore) the estimate of all variables from the stack

References g2o::OptimizableGraph::pop().

◆ pop() [3/3]

void g2o::SparseOptimizer::pop ( SparseOptimizer::VertexContainer vlist)

pop (restore) the estimate a subset of the variables from the stack

Definition at line 543 of file sparse_optimizer.cpp.

543 {
544 for (VertexContainer::iterator it = vlist.begin(); it != vlist.end(); ++it)
545 (*it)->pop();
546}

Referenced by g2o::computeSimpleStars(), g2o::OptimizationAlgorithmDogleg::solve(), and g2o::OptimizationAlgorithmLevenberg::solve().

◆ push() [1/3]

void g2o::SparseOptimizer::push ( )
virtual

push all the active vertices onto a stack

Reimplemented from g2o::OptimizableGraph.

Definition at line 624 of file sparse_optimizer.cpp.

void push()
push all the active vertices onto a stack

References _activeVertices, and push().

Referenced by push().

◆ push() [2/3]

void g2o::SparseOptimizer::push ( HyperGraph::VertexSet vlist)
virtual

push the estimate of a subset of the variables onto a stack

Reimplemented from g2o::OptimizableGraph.

Definition at line 548 of file sparse_optimizer.cpp.

548 {
550}
virtual void push()
push the estimate of all variables onto a stack

References g2o::OptimizableGraph::push().

◆ push() [3/3]

void g2o::SparseOptimizer::push ( SparseOptimizer::VertexContainer vlist)

push the estimate of a subset of the variables onto a stack

Definition at line 538 of file sparse_optimizer.cpp.

538 {
539 for (VertexContainer::iterator it = vlist.begin(); it != vlist.end(); ++it)
540 (*it)->push();
541}

Referenced by g2o::computeSimpleStars(), g2o::OptimizationAlgorithmDogleg::solve(), and g2o::OptimizationAlgorithmLevenberg::solve().

◆ removeComputeErrorAction()

bool g2o::SparseOptimizer::removeComputeErrorAction ( HyperGraphAction action)

remove an action that should no longer be executed before computing the error vectors

Definition at line 620 of file sparse_optimizer.cpp.

620 {
621 return _graphActions[AT_COMPUTEACTIVERROR].erase(action) > 0;
622}

References g2o::OptimizableGraph::_graphActions, and AT_COMPUTEACTIVERROR.

◆ removeVertex()

bool g2o::SparseOptimizer::removeVertex ( HyperGraph::Vertex v,
bool  detach = false 
)
virtual

Remove a vertex. If the vertex is contained in the currently active set of vertices, then the internal temporary structures are cleaned, e.g., the index mapping is erased. In case you need the index mapping for manipulating the graph, you have to store it in your own copy.

Reimplemented from g2o::HyperGraph.

Definition at line 605 of file sparse_optimizer.cpp.

605 {
606 OptimizableGraph::Vertex* vv = static_cast<OptimizableGraph::Vertex*>(v);
607 if (vv->hessianIndex() >= 0) {
609 _ivMap.clear();
610 }
611 return HyperGraph::removeVertex(v, detach);
612}
virtual bool removeVertex(Vertex *v, bool detach=false)

References _ivMap, clearIndexMapping(), g2o::OptimizableGraph::Vertex::hessianIndex(), and g2o::HyperGraph::removeVertex().

◆ setAlgorithm()

void g2o::SparseOptimizer::setAlgorithm ( OptimizationAlgorithm algorithm)

Definition at line 563 of file sparse_optimizer.cpp.

563 {
564 if (_algorithm) {
565 // reset the optimizer for the formerly used solver in case release() won't
566 // delete it
567 _algorithm->setOptimizer(nullptr);
569 }
570
572
574}
void setOptimizer(SparseOptimizer *optimizer)
const OptimizationAlgorithm * algorithm() const
the solver used by the optimizer

References _algorithm, algorithm(), g2o::release(), and g2o::OptimizationAlgorithm::setOptimizer().

Referenced by g2o::allocateSolverForSclam(), g2o::SparseOptimizerIncremental::initSolver(), g2o::SparseOptimizerOnline::initSolver(), main(), main(), and main().

◆ setComputeBatchStatistics()

void g2o::SparseOptimizer::setComputeBatchStatistics ( bool  computeBatchStatistics)

◆ setForceStopFlag()

void g2o::SparseOptimizer::setForceStopFlag ( bool *  flag)

sets a variable checked at every iteration to force a user stop. The iteration exits when the variable is true;

Definition at line 603 of file sparse_optimizer.cpp.

603{ _forceStopFlag = flag; }

References _forceStopFlag.

Referenced by main().

◆ setToOrigin()

void g2o::SparseOptimizer::setToOrigin ( )
virtual

sets all vertices to their origin.

Definition at line 311 of file sparse_optimizer.cpp.

311 {
312 for (VertexIDMap::iterator it = vertices().begin(); it != vertices().end();
313 ++it) {
314 OptimizableGraph::Vertex* v =
315 static_cast<OptimizableGraph::Vertex*>(it->second);
316 v->setToOrigin();
317 }
318}

References g2o::OptimizableGraph::Vertex::setToOrigin(), and g2o::HyperGraph::vertices().

◆ setVerbose()

void g2o::SparseOptimizer::setVerbose ( bool  verbose)

Definition at line 561 of file sparse_optimizer.cpp.

561{ _verbose = verbose; }

References _verbose, and verbose().

Referenced by main(), main(), and main().

◆ solver()

OptimizationAlgorithm * g2o::SparseOptimizer::solver ( )
inline

◆ sortVectorContainers()

void g2o::SparseOptimizer::sortVectorContainers ( )
protected

Definition at line 507 of file sparse_optimizer.cpp.

507 {
508 // sort vector structures to get deterministic ordering based on IDs
509 sort(_activeVertices.begin(), _activeVertices.end(), VertexIDCompare());
510 sort(_activeEdges.begin(), _activeEdges.end(), EdgeIDCompare());
511}

References _activeEdges, and _activeVertices.

Referenced by initializeOptimization(), and initializeOptimization().

◆ terminate()

bool g2o::SparseOptimizer::terminate ( )
inline

if external stop flag is given, return its state. False otherwise

Definition at line 183 of file sparse_optimizer.h.

183{ return _forceStopFlag ? (*_forceStopFlag) : false; }

Referenced by optimize(), and g2o::OptimizationAlgorithmLevenberg::solve().

◆ update()

void g2o::SparseOptimizer::update ( const double *  update)

update the estimate of the active vertices

Parameters
updatethe double vector containing the stacked elements of the increments on the vertices.

Definition at line 446 of file sparse_optimizer.cpp.

446 {
447 // update the graph by calling oplus on the vertices
448 for (size_t i = 0; i < _ivMap.size(); ++i) {
449 OptimizableGraph::Vertex* v = _ivMap[i];
450#ifndef NDEBUG
451 bool hasNan = arrayHasNaN(update, v->dimension());
452 if (hasNan)
453 G2O_WARN("{}: Update contains a nan for vertex {}", __PRETTY_FUNCTION__,
454 v->id());
455#endif
456 v->oplus(update);
457 update += v->dimension();
458 }
459}
void update(const double *update)

References __PRETTY_FUNCTION__, _ivMap, g2o::arrayHasNaN(), g2o::OptimizableGraph::Vertex::dimension(), G2O_WARN, g2o::HyperGraph::Vertex::id(), g2o::OptimizableGraph::Vertex::oplus(), and update().

Referenced by g2o::OptimizationAlgorithmDogleg::solve(), g2o::OptimizationAlgorithmGaussNewton::solve(), g2o::OptimizationAlgorithmLevenberg::solve(), and update().

◆ updateInitialization()

bool g2o::SparseOptimizer::updateInitialization ( HyperGraph::VertexSet vset,
HyperGraph::EdgeSet eset 
)
virtual

HACK updating the internal structures for online processing

Reimplemented in g2o::SparseOptimizerIncremental, and g2o::SparseOptimizerOnline.

Definition at line 469 of file sparse_optimizer.cpp.

470 {
471 std::vector<HyperGraph::Vertex*> newVertices;
472 newVertices.reserve(vset.size());
473 _activeVertices.reserve(_activeVertices.size() + vset.size());
474 _activeEdges.reserve(_activeEdges.size() + eset.size());
475 for (HyperGraph::EdgeSet::iterator it = eset.begin(); it != eset.end();
476 ++it) {
477 OptimizableGraph::Edge* e = static_cast<OptimizableGraph::Edge*>(*it);
478 if (!e->allVerticesFixed()) _activeEdges.push_back(e);
479 }
480
481 // update the index mapping
482 size_t next = _ivMap.size();
483 for (HyperGraph::VertexSet::iterator it = vset.begin(); it != vset.end();
484 ++it) {
485 OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(*it);
486 if (!v->fixed()) {
487 if (!v->marginalized()) {
488 v->setHessianIndex(next);
489 _ivMap.push_back(v);
490 newVertices.push_back(v);
491 _activeVertices.push_back(v);
492 next++;
493 } else // not supported right now
494 abort();
495 } else {
496 v->setHessianIndex(-1);
497 }
498 }
499
500 if (newVertices.size() != vset.size()) {
501 G2O_ERROR("{}: something went wrong, size mismatch {} != {}", vset.size(),
502 newVertices.size());
503 }
504 return _algorithm->updateStructure(newVertices, eset);
505}
virtual bool updateStructure(const std::vector< HyperGraph::Vertex * > &vset, const HyperGraph::EdgeSet &edges)=0

References _activeEdges, _activeVertices, _algorithm, _ivMap, g2o::OptimizableGraph::Edge::allVerticesFixed(), g2o::OptimizableGraph::Vertex::fixed(), G2O_ERROR, g2o::OptimizableGraph::Vertex::marginalized(), g2o::OptimizableGraph::Vertex::setHessianIndex(), and g2o::OptimizationAlgorithm::updateStructure().

Referenced by main(), and g2o::SparseOptimizerOnline::updateInitialization().

◆ verbose()

bool g2o::SparseOptimizer::verbose ( ) const
inline

verbose information during optimization

Definition at line 172 of file sparse_optimizer.h.

172{ return _verbose; }

Referenced by computeInitialGuess(), main(), optimize(), g2o::SparseOptimizerIncremental::optimize(), g2o::SparseOptimizerOnline::optimize(), and setVerbose().

Friends And Related Symbol Documentation

◆ ActivePathCostFunction

friend class ActivePathCostFunction
friend

Definition at line 49 of file sparse_optimizer.h.

Member Data Documentation

◆ _activeEdges

EdgeContainer g2o::SparseOptimizer::_activeEdges
protected

◆ _activeVertices

VertexContainer g2o::SparseOptimizer::_activeVertices
protected

◆ _algorithm

OptimizationAlgorithm* g2o::SparseOptimizer::_algorithm
protected

◆ _batchStatistics

BatchStatisticsContainer g2o::SparseOptimizer::_batchStatistics
protected

global statistics of the optimizer, e.g., timing, num-non-zeros

Definition at line 307 of file sparse_optimizer.h.

Referenced by optimize(), and setComputeBatchStatistics().

◆ _computeBatchStatistics

bool g2o::SparseOptimizer::_computeBatchStatistics
protected

Definition at line 309 of file sparse_optimizer.h.

Referenced by optimize(), and setComputeBatchStatistics().

◆ _forceStopFlag

bool* g2o::SparseOptimizer::_forceStopFlag
protected

Definition at line 288 of file sparse_optimizer.h.

Referenced by setForceStopFlag().

◆ _ivMap

VertexContainer g2o::SparseOptimizer::_ivMap
protected

◆ _verbose

bool g2o::SparseOptimizer::_verbose
protected

Definition at line 289 of file sparse_optimizer.h.

Referenced by setVerbose().


The documentation for this class was generated from the following files: