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-2018, 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/math/types_math.h>
14 #include <deque>
15 
16 namespace mrpt::graphs
17 {
18 /** Sparse solver for GMRF (Gaussian Markov Random Fields) graphical models.
19  * The design of this class is optimized for large problems (e.g. >1e3 nodes,
20  * >1e4 constrainst)
21  * by leaving to the user/caller the responsibility of allocating all "nodes"
22  * and constraints.
23  * This class can be seen as an intermediary solution between current methods
24  * in mrpt::graphslam and the well-known G2O library:
25  *
26  * Assumptions/limitations:
27  * - Linear error functions (for now).
28  * - Scalar (1-dim) error functions.
29  * - Gaussian factors.
30  * - Solver: Eigen SparseQR.
31  *
32  * Usage:
33  * - Call initialize() to set the number of nodes.
34  * - Call addConstraints() to insert constraints. This may be called more than
35  * once.
36  * - Call updateEstimation() to run one step of the linear SparseQR solver.
37  *
38  * \ingroup mrpt_graph_grp
39  * \note [New in MRPT 1.5.0] Requires Eigen>=3.1
40  */
42 {
43  public:
45 
46  struct FactorBase
47  {
48  virtual ~FactorBase();
49  /** Return the residual/error of this observation. */
50  virtual double evaluateResidual() const = 0;
51  /** Return the inverse of the variance of this constraint */
52  virtual double getInformation() const = 0;
53  };
54 
55  /** Simple, scalar (1-dim) constraint (edge) for a GMRF */
57  {
58  size_t node_id;
59  /** Returns the derivative of the residual wrt the node value */
60  virtual void evalJacobian(double& dr_dx) const = 0;
61  };
62 
63  /** Simple, scalar (1-dim) constraint (edge) for a GMRF */
65  {
67  /** Returns the derivative of the residual wrt the node values */
68  virtual void evalJacobian(double& dr_dxi, double& dr_dxj) const = 0;
69  };
70 
71  /** Reset state: remove all constraints and nodes. */
72  void clear();
73 
74  /** Initialize the GMRF internal state and copy the prior factors. */
75  void initialize(
76  /** Number of unknown nodes in the MRF graph */
77  const size_t nodeCount);
78 
79  /** Insert constraints into the GMRF problem.
80  * \param listOfConstraints List of user-implemented constraints.
81  * **A pointer to the passed object is kept**, but memory ownship *REMAINS*
82  * being responsability of the caller. This is
83  * done such that arrays/vectors of constraints can be more efficiently
84  * allocated if their type is known at build time.
85  */
86  void addConstraint(const UnaryFactorVirtualBase& listOfConstraints);
87  void addConstraint(const BinaryFactorVirtualBase& listOfConstraints);
88 
89  /** Removes a constraint. Return true if found and deleted correctly. */
90  bool eraseConstraint(const FactorBase& c);
91 
94  void updateEstimation(
95  /** Output increment of the current estimate. Caller must add this
96  vector to current state vector to obtain the optimal estimation. */
97  Eigen::VectorXd& solved_x_inc,
98  /** If !=nullptr, the variances of each estimate will be stored here. */
99  Eigen::VectorXd* solved_variances = nullptr);
100 
101  bool isProfilerEnabled() const { return m_enable_profiler; }
102  void enableProfiler(bool enable = true) { m_enable_profiler = enable; }
103  private:
104  /** number of nodes in the graph */
105  size_t m_numNodes;
106 
107  std::deque<const UnaryFactorVirtualBase*> m_factors_unary;
108  std::deque<const BinaryFactorVirtualBase*> m_factors_binary;
109 
112 
113 }; // End of class def.
114 
115 }
116 
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.
Abstract graph and tree data structures, plus generic graph algorithms.
std::deque< const BinaryFactorVirtualBase * > m_factors_binary
void enableProfiler(bool enable=true)
mrpt::system::CTimeLogger m_timelogger
std::deque< const UnaryFactorVirtualBase * > m_factors_unary
const GLubyte * c
Definition: glext.h:6313
Versatile class for consistent logging and management of output messages.
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
A versatile "profiler" that logs the time spent within each pair of calls to enter(X)-leave(X), among other stats.
virtual void evalJacobian(double &dr_dx) const =0
Returns the derivative of the residual wrt the node value.
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: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020