Main MRPT website > C++ reference
MRPT logo
rba_problem_common.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-2015, 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 
10 #pragma once
11 
12 #include <mrpt/utils/CConfigFileBase.h> // MRPT_LOAD_CONFIG_VAR
13 #include <mrpt/math/ops_containers.h> // meanAndStd()
14 
15 namespace mrpt { namespace srba {
16 
17 /** Default constructor */
18 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
20  rba_state(),
21  m_profiler(true)
22 {
23  clear();
24 }
25 
26 /** Reset the entire problem to an empty state (automatically called at construction) */
27 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
29 {
30  this->rba_state.clear();
31 }
32 
33 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
35  // -------------------------------
36  edge_creation_policy ( ecpICRA2013 ),
37  max_tree_depth ( 4 ),
38  max_optimize_depth ( 4 ),
39  submap_size ( 15 ),
40  min_obs_to_loop_closure ( 6 ),
41  // -------------------------------
42  optimize_new_edges_alone (true),
43  use_robust_kernel ( false ),
44  use_robust_kernel_stage1 ( false ),
45  kernel_param ( 3. ),
46  max_iters ( 20 ),
47  max_error_per_obs_to_stop ( 1e-6 ),
48  max_rho ( 10.0 ),
49  max_lambda ( 1e20 ),
50  min_error_reduction_ratio_to_relinearize ( 0.01 ),
51  numeric_jacobians ( false ),
52  feedback_user_iteration(NULL),
53  compute_condition_number(false),
54  cov_recovery ( crpLandmarksApprox )
55 {
56 }
57 
58 /** See docs of mrpt::utils::CLoadableOptions */
59 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
61 {
62  edge_creation_policy = source.read_enum(section, "edge_creation_policy", edge_creation_policy);
63  MRPT_LOAD_CONFIG_VAR(max_tree_depth,uint64_t,source,section)
64  MRPT_LOAD_CONFIG_VAR(max_optimize_depth,uint64_t,source,section)
65  MRPT_LOAD_CONFIG_VAR(submap_size,uint64_t,source,section)
66  MRPT_LOAD_CONFIG_VAR(min_obs_to_loop_closure,uint64_t,source,section)
67 
68  MRPT_LOAD_CONFIG_VAR(optimize_new_edges_alone,bool,source,section)
69  MRPT_LOAD_CONFIG_VAR(use_robust_kernel,bool,source,section)
70  MRPT_LOAD_CONFIG_VAR(use_robust_kernel_stage1,bool,source,section)
71  MRPT_LOAD_CONFIG_VAR(max_rho,double,source,section)
72  MRPT_LOAD_CONFIG_VAR(max_lambda,double,source,section)
73  MRPT_LOAD_CONFIG_VAR(kernel_param,double,source,section)
74  MRPT_LOAD_CONFIG_VAR(max_iters,uint64_t,source,section)
75  MRPT_LOAD_CONFIG_VAR(max_error_per_obs_to_stop,double,source,section)
76 
77  cov_recovery = source.read_enum(section, "cov_recovery", cov_recovery);
78 }
79 
80 /** See docs of mrpt::utils::CLoadableOptions */
81 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
83 {
84  out.write(section,"edge_creation_policy", mrpt::utils::TEnumType<TEdgeCreationPolicy>::value2name(edge_creation_policy) , /* text width */ 30, 30, "Arc creation policy");
85 
86  out.write(section,"max_tree_depth",max_tree_depth, /* text width */ 30, 30, "Maximum depth of all spanning trees");
87  out.write(section,"max_optimize_depth",max_optimize_depth, /* text width */ 30, 30, "Max. local optimization distance");
88  out.write(section,"submap_size",static_cast<uint64_t>(submap_size), /* text width */ 30, 30, "Max. local optimization distance");
89  out.write(section,"min_obs_to_loop_closure",static_cast<uint64_t>(min_obs_to_loop_closure), /* text width */ 30, 30, "Min. num. of covisible observations to add a loop closure edge");
90 
91 
92  out.write(section,"optimize_new_edges_alone",optimize_new_edges_alone, /* text width */ 30, 30, "Optimize new edges alone before optimizing the entire local area?");
93  out.write(section,"use_robust_kernel",use_robust_kernel, /* text width */ 30, 30, "Use pseudo-Huber kernel?");
94  out.write(section,"use_robust_kernel_stage1",use_robust_kernel_stage1, /* text width */ 30, 30, "Use pseudo-Huber kernel at stage1?");
95  out.write(section,"kernel_param",kernel_param, /* text width */ 30, 30, "robust kernel parameter");
96  out.write(section,"max_rho",max_rho, /* text width */ 30, 30, "Lev-Marq optimization: maximum rho value to stop");
97  out.write(section,"max_lambda",max_lambda, /* text width */ 30, 30, "Lev-Marq optimization: maximum lambda to stop");
98  out.write(section,"max_iters",static_cast<uint64_t>(max_iters), /* text width */ 30, 30, "Max. iterations for optimization");
99  out.write(section,"max_error_per_obs_to_stop",max_error_per_obs_to_stop, /* text width */ 30, 30, "Another criterion for stopping optimization");
100  out.write(section,"cov_recovery", mrpt::utils::TEnumType<TCovarianceRecoveryPolicy>::value2name(cov_recovery) , /* text width */ 30, 30, "Covariance recovery policy");
101 }
102 
103 
104 /** Computes stats on the degree (# of adjacent nodes) of all the nodes in the graph. Runs in O(N) with N=# of keyframes */
105 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
107  double &out_mean_degree,
108  double &out_std_degree,
109  double &out_max_degree) const
110 {
111  out_mean_degree = 0;
112  out_std_degree = 0;
113  out_max_degree = 0;
114 
115  const size_t nKFs = keyframes.size();
116 
117  std::vector<size_t> degs;
118  degs.reserve(nKFs);
119 
120  for(size_t i=0;i<nKFs;i++)
121  degs.push_back( keyframes[i].adjacent_k2k_edges.size() );
122 
123  mrpt::math::meanAndStd(degs,out_mean_degree,out_std_degree);
124  out_max_degree = mrpt::math::maximum(degs);
125 
126 }
127 
128 /** Returns true if the pair of KFs are connected thru a kf2kf edge, no matter the direction of the edge.
129  * Runs in worst-case O(D) with D the degree of the KF graph (that is, the maximum number of edges adjacent to one KF) */
130 template <class KF2KF_POSE_TYPE,class LM_TYPE,class OBS_TYPE,class RBA_OPTIONS>
132 {
133  ASSERT_BELOW_(id1, keyframes.size())
134  ASSERT_BELOW_(id2, keyframes.size())
135 
136  const std::deque<k2k_edge_t*> & id1_adj = keyframes[id1].adjacent_k2k_edges;
137 
138  for (size_t i=0;i<id1_adj.size();i++)
139  if ( id2== getTheOtherFromPair2(id1, *id1_adj[i]) )
140  return true;
141 
142  return false;
143 }
144 
145 } } // end NS
virtual void edge_creation_policy(const TKeyFrameID new_kf_id, const typename traits_t::new_kf_observations_t &obs, std::vector< TNewEdgeInfo > &new_k2k_edge_ids)
Implements the edge-creation policy, by default depending on "parameters.edge_creation_policy" if the...
ENUMTYPE read_enum(const std::string &section, const std::string &name, const ENUMTYPE &defaultValue, bool failIfNotFound=false) const
Reads an "enum" value, where the value in the config file can be either a numerical value or the symb...
#define ASSERT_BELOW_(__A, __B)
This file implements several operations that operate element-wise on individual or pairs of container...
The sub-map method introduced in the ICRA2013 paper.
Definition: srba_types.h:166
This class allows loading and storing values and vectors of different types from a configuration text...
A helper class that can convert an enum value into its textual representation, and viceversa...
CONTAINER::Scalar maximum(const CONTAINER &v)
RbaEngine()
Default constructor.
void compute_all_node_degrees(double &out_mean_degree, double &out_std_degree, double &out_max_degree) const
Computes stats on the degree (# of adjacent nodes) of all the nodes in the graph. ...
virtual void saveToConfigFile(mrpt::utils::CConfigFileBase &out, const std::string &section) const
See docs of mrpt::utils::CLoadableOptions.
#define MRPT_LOAD_CONFIG_VAR(variableName, variableType, configFileObject, sectionNameStr)
An useful macro for loading variables stored in a INI-like file under a key with the same name that t...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void meanAndStd(const VECTORLIKE &v, double &out_mean, double &out_std, bool unbiased=true)
Computes the standard deviation of a vector.
virtual void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string &section)
See docs of mrpt::utils::CLoadableOptions.
bool are_keyframes_connected(const TKeyFrameID id1, const TKeyFrameID id2) const
Returns true if the pair of KFs are connected thru a kf2kf edge, no matter the direction of the edge...
void write(const std::string &section, const std::string &name, double value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
Approximate covariances of landmarks as the inverse of the hessian diagonal blocks.
Definition: srba_types.h:180
void clear()
Reset the entire problem to an empty state (automatically called at construction) ...
V getTheOtherFromPair2(const V one, const K2K_EDGE &p)
For usage with K2K_EDGE = typename kf2kf_pose_traits::k2k_edge_t.
Definition: srba_types.h:191
uint64_t TKeyFrameID
Numeric IDs for key-frames (KFs)
Definition: srba_types.h:31



Page generated by Doxygen 1.8.9.1 for MRPT 1.3.0 SVN: at Sun Sep 13 03:55:12 UTC 2015