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

Base for solvers operating on the approximated Hessian, e.g., Gauss-Newton, Levenberg. More...

#include <optimization_algorithm_with_hessian.h>

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

Public Member Functions

 OptimizationAlgorithmWithHessian (Solver &solver)
 
virtual ~OptimizationAlgorithmWithHessian ()
 
virtual bool init (bool online=false)
 
virtual bool computeMarginals (SparseBlockMatrix< MatrixX > &spinv, const std::vector< std::pair< int, int > > &blockIndices)
 
virtual bool buildLinearStructure ()
 
virtual void updateLinearSystem ()
 
virtual bool updateStructure (const std::vector< HyperGraph::Vertex * > &vset, const HyperGraph::EdgeSet &edges)
 
Solversolver ()
 return the underlying solver used to solve the linear system
 
virtual void setWriteDebug (bool writeDebug)
 
virtual bool writeDebug () const
 
- Public Member Functions inherited from g2o::OptimizationAlgorithm
 OptimizationAlgorithm ()
 
virtual ~OptimizationAlgorithm ()
 
virtual SolverResult solve (int iteration, bool online=false)=0
 
virtual void printVerbose (std::ostream &os) const
 
const SparseOptimizeroptimizer () const
 return the optimizer operating on
 
SparseOptimizeroptimizer ()
 
void setOptimizer (SparseOptimizer *optimizer)
 
const PropertyMapproperties () const
 return the properties of the solver
 
bool updatePropertiesFromString (const std::string &propString)
 
void printProperties (std::ostream &os) const
 

Protected Attributes

Solver_solver
 
Property< bool > * _writeDebug
 
- Protected Attributes inherited from g2o::OptimizationAlgorithm
SparseOptimizer_optimizer
 the optimizer the solver is working on
 
PropertyMap _properties
 

Detailed Description

Base for solvers operating on the approximated Hessian, e.g., Gauss-Newton, Levenberg.

Definition at line 41 of file optimization_algorithm_with_hessian.h.

Constructor & Destructor Documentation

◆ OptimizationAlgorithmWithHessian()

g2o::OptimizationAlgorithmWithHessian::OptimizationAlgorithmWithHessian ( Solver solver)
explicit

Definition at line 39 of file optimization_algorithm_with_hessian.cpp.

42 _writeDebug = _properties.makeProperty<Property<bool> >("writeDebug", true);
43}
Solver & solver()
return the underlying solver used to solve the linear system
P * makeProperty(const std::string &name_, const typename P::ValueType &v)
Definition property.h:116

References g2o::OptimizationAlgorithm::_properties, _writeDebug, and g2o::PropertyMap::makeProperty().

◆ ~OptimizationAlgorithmWithHessian()

g2o::OptimizationAlgorithmWithHessian::~OptimizationAlgorithmWithHessian ( )
virtual

Definition at line 45 of file optimization_algorithm_with_hessian.cpp.

45{}

Member Function Documentation

◆ buildLinearStructure()

bool g2o::OptimizationAlgorithmWithHessian::buildLinearStructure ( )
virtual

Definition at line 76 of file optimization_algorithm_with_hessian.cpp.

76 {
77 return _solver.buildStructure();
78}
virtual bool buildStructure(bool zeroBlocks=false)=0

References _solver, and g2o::Solver::buildStructure().

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

◆ computeMarginals()

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

computes the block diagonal elements of the pattern specified in the input and stores them in given SparseBlockMatrix. If your solver does not support computing the marginals, return false.

Implements g2o::OptimizationAlgorithm.

Definition at line 70 of file optimization_algorithm_with_hessian.cpp.

72 {
73 return _solver.computeMarginals(spinv, blockIndices);
74}
virtual bool computeMarginals(SparseBlockMatrix< MatrixX > &spinv, const std::vector< std::pair< int, int > > &blockIndices)=0

References _solver, and g2o::Solver::computeMarginals().

◆ init()

bool g2o::OptimizationAlgorithmWithHessian::init ( bool  online = false)
virtual

initialize the solver, called once before the first call to solve()

Implements g2o::OptimizationAlgorithm.

Definition at line 47 of file optimization_algorithm_with_hessian.cpp.

47 {
48 assert(_optimizer && "_optimizer not set");
50 bool useSchur = false;
51 for (OptimizableGraph::VertexContainer::const_iterator it =
52 _optimizer->activeVertices().begin();
53 it != _optimizer->activeVertices().end(); ++it) {
54 OptimizableGraph::Vertex* v = *it;
55 if (v->marginalized()) {
56 useSchur = true;
57 break;
58 }
59 }
60 if (useSchur) {
62 } else {
64 }
65
66 bool initState = _solver.init(_optimizer, online);
67 return initState;
68}
SparseOptimizer * _optimizer
the optimizer the solver is working on
const T & value() const
Definition property.h:59
virtual void setSchur(bool s)=0
virtual bool supportsSchur()
Definition solver.h:120
virtual bool init(SparseOptimizer *optimizer, bool online=false)=0
virtual void setWriteDebug(bool)=0
const VertexContainer & activeVertices() const
the vertices active in the current optimization

References g2o::OptimizationAlgorithm::_optimizer, _solver, _writeDebug, g2o::SparseOptimizer::activeVertices(), g2o::Solver::init(), g2o::OptimizableGraph::Vertex::marginalized(), g2o::Solver::setSchur(), g2o::Solver::setWriteDebug(), g2o::Solver::supportsSchur(), and g2o::Property< T >::value().

◆ setWriteDebug()

void g2o::OptimizationAlgorithmWithHessian::setWriteDebug ( bool  writeDebug)
virtual

write debug output of the Hessian if system is not positive definite

Definition at line 90 of file optimization_algorithm_with_hessian.cpp.

References _writeDebug, g2o::Property< T >::setValue(), and writeDebug().

◆ solver()

Solver & g2o::OptimizationAlgorithmWithHessian::solver ( )
inline

return the underlying solver used to solve the linear system

Definition at line 61 of file optimization_algorithm_with_hessian.h.

61{ return _solver; }

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

◆ updateLinearSystem()

void g2o::OptimizationAlgorithmWithHessian::updateLinearSystem ( )
virtual

Definition at line 80 of file optimization_algorithm_with_hessian.cpp.

80 {
82}
virtual bool buildSystem()=0

References _solver, and g2o::Solver::buildSystem().

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

◆ updateStructure()

bool g2o::OptimizationAlgorithmWithHessian::updateStructure ( const std::vector< HyperGraph::Vertex * > &  vset,
const HyperGraph::EdgeSet edges 
)
virtual

update the structures for online processing

Implements g2o::OptimizationAlgorithm.

Definition at line 84 of file optimization_algorithm_with_hessian.cpp.

86 {
87 return _solver.updateStructure(vset, edges);
88}
virtual bool updateStructure(const std::vector< HyperGraph::Vertex * > &vset, const HyperGraph::EdgeSet &edges)=0

References _solver, and g2o::Solver::updateStructure().

◆ writeDebug()

virtual bool g2o::OptimizationAlgorithmWithHessian::writeDebug ( ) const
inlinevirtual

Definition at line 67 of file optimization_algorithm_with_hessian.h.

67{ return _writeDebug->value(); }

Referenced by setWriteDebug().

Member Data Documentation

◆ _solver

Solver& g2o::OptimizationAlgorithmWithHessian::_solver
protected

◆ _writeDebug

Property<bool>* g2o::OptimizationAlgorithmWithHessian::_writeDebug
protected

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