Main MRPT website > C++ reference for MRPT 1.9.9
ScalarFactorGraph.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/utils/core_defs.h>
12 #include <mrpt/utils/types_math.h>
14 #include <mrpt/utils/CTimeLogger.h>
15 #include <deque>
16 
17 namespace mrpt
18 {
19 namespace graphs
20 {
21 /** Sparse solver for GMRF (Gaussian Markov Random Fields) graphical models.
22  * The design of this class is optimized for large problems (e.g. >1e3 nodes,
23  * >1e4 constrainst)
24  * by leaving to the user/caller the responsibility of allocating all "nodes"
25  * and constraints.
26  * This class can be seen as an intermediary solution between current methods
27  * in mrpt::graphslam and the well-known G2O library:
28  *
29  * Assumptions/limitations:
30  * - Linear error functions (for now).
31  * - Scalar (1-dim) error functions.
32  * - Gaussian factors.
33  * - Solver: Eigen SparseQR.
34  *
35  * Usage:
36  * - Call initialize() to set the number of nodes.
37  * - Call addConstraints() to insert constraints. This may be called more than
38  * once.
39  * - Call updateEstimation() to run one step of the linear SparseQR solver.
40  *
41  * \ingroup mrpt_graph_grp
42  * \note [New in MRPT 1.5.0] Requires Eigen>=3.1
43  */
44 class ScalarFactorGraph : public mrpt::utils::COutputLogger
45 {
46  public:
48 
49  struct FactorBase
50  {
51  virtual ~FactorBase();
52  /** Return the residual/error of this observation. */
53  virtual double evaluateResidual() const = 0;
54  /** Return the inverse of the variance of this constraint */
55  virtual double getInformation() const = 0;
56  };
57 
58  /** Simple, scalar (1-dim) constraint (edge) for a GMRF */
60  {
61  size_t node_id;
62  /** Returns the derivative of the residual wrt the node value */
63  virtual void evalJacobian(double& dr_dx) const = 0;
64  };
65 
66  /** Simple, scalar (1-dim) constraint (edge) for a GMRF */
68  {
70  /** Returns the derivative of the residual wrt the node values */
71  virtual void evalJacobian(double& dr_dxi, double& dr_dxj) const = 0;
72  };
73 
74  /** Reset state: remove all constraints and nodes. */
75  void clear();
76 
77  /** Initialize the GMRF internal state and copy the prior factors. */
78  void initialize(
79  /** Number of unknown nodes in the MRF graph */
80  const size_t nodeCount);
81 
82  /** Insert constraints into the GMRF problem.
83  * \param listOfConstraints List of user-implemented constraints.
84  * **A pointer to the passed object is kept**, but memory ownship *REMAINS*
85  * being responsability of the caller. This is
86  * done such that arrays/vectors of constraints can be more efficiently
87  * allocated if their type is known at build time.
88  */
89  void addConstraint(const UnaryFactorVirtualBase& listOfConstraints);
90  void addConstraint(const BinaryFactorVirtualBase& listOfConstraints);
91 
92  /** Removes a constraint. Return true if found and deleted correctly. */
93  bool eraseConstraint(const FactorBase& c);
94 
97  void updateEstimation(
98  /** Output increment of the current estimate. Caller must add this
99  vector to current state vector to obtain the optimal estimation. */
100  Eigen::VectorXd& solved_x_inc,
101  /** If !=nullptr, the variances of each estimate will be stored here. */
102  Eigen::VectorXd* solved_variances = nullptr);
103 
104  bool isProfilerEnabled() const { return m_enable_profiler; }
105  void enableProfiler(bool enable = true) { m_enable_profiler = enable; }
106  private:
107  /** number of nodes in the graph */
108  size_t m_numNodes;
109 
110  std::deque<const UnaryFactorVirtualBase*> m_factors_unary;
111  std::deque<const BinaryFactorVirtualBase*> m_factors_binary;
112 
115 
116 }; // End of class def.
117 
118 } // End of namespace
119 } // End of namespace
void initialize(const size_t nodeCount)
Initialize the GMRF internal state and copy the prior factors.
Simple, scalar (1-dim) constraint (edge) for a GMRF.
bool eraseConstraint(const FactorBase &c)
Removes a constraint.
std::deque< const BinaryFactorVirtualBase * > m_factors_binary
void enableProfiler(bool enable=true)
std::deque< const UnaryFactorVirtualBase * > m_factors_unary
const GLubyte * c
Definition: glext.h:6313
mrpt::utils::CTimeLogger m_timelogger
void addConstraint(const UnaryFactorVirtualBase &listOfConstraints)
Insert constraints into the GMRF problem.
virtual double evaluateResidual() const =0
Return the residual/error of this observation.
size_t m_numNodes
number of nodes in the graph
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
virtual void evalJacobian(double &dr_dx) const =0
Returns the derivative of the residual wrt the node value.
A versatile "profiler" that logs the time spent within each pair of calls to enter(X)-leave(X), among other stats.
Definition: CTimeLogger.h:45
void clear()
Reset state: remove all constraints and nodes.
Simple, scalar (1-dim) constraint (edge) for a GMRF.
virtual double getInformation() const =0
Return the inverse of the variance of this constraint.
virtual void evalJacobian(double &dr_dxi, double &dr_dxj) const =0
Returns the derivative of the residual wrt the node values.
void updateEstimation(Eigen::VectorXd &solved_x_inc, Eigen::VectorXd *solved_variances=nullptr)
Sparse solver for GMRF (Gaussian Markov Random Fields) graphical models.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019