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



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020