Main MRPT website > C++ reference for MRPT 1.5.9
model_search.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 
10 #ifndef math_modelsearch_h
11 #define math_modelsearch_h
12 
13 #include <mrpt/utils/utils_defs.h>
14 #include <set>
15 
16 namespace mrpt {
17  namespace math {
18 
19 
20  /** Model search implementations: RANSAC and genetic algorithm
21  *
22  * The type \a TModelFit is a user-supplied struct/class that implements this interface:
23  * - Types:
24  * - \a Real : The numeric type to use (typ: double, float)
25  * - \a Model : The type of the model to be fitted (for example: A matrix, a TLine2D, a TPlane3D, ...)
26  * - Methods:
27  * - size_t getSampleCount() const : return the number of samples. This should not change during a model search.
28  * - bool fitModel( const vector_size_t& useIndices, Model& model ) const : This function fits a model to the data selected by the indices. The return value indicates the success, hence false means a degenerate case, where no model was found.
29  * - Real testSample( size_t index, const Model& model ) const : return some value that indicates how well a sample fits to the model. This way the thresholding is moved to the searching procedure and the model just tells how good a sample is.
30  *
31  * There are two methods provided in this class to fit a model:
32  * - \a ransacSingleModel (RANSAC): Just like mrpt::math::RANSAC_Template
33  *
34  * - \a geneticSingleModel (Genetic): Provides a mixture of a genetic and the ransac algorithm.
35  * Instead of selecting a set of data in each iteration, it takes more (ex. 10) and order these model
36  * using some fitness function: the average error of the inliers scaled by the number of outliers (This
37  * fitness might require some fine tuning). Than the (ex 10) new kernel for the next iteration is created as follows:
38  * - Take the best kernels (as for the original ransac)
39  * - Select two kernels ( with a higher probability for the better models) and let the new kernel be a subset of the two original kernels ( additionally to leave the local minimums an additional random seed might appear - mutation)
40  * - Generate some new random samples.
41  *
42  * For an example of usage, see "samples/model_search_test/"
43  * \sa mrpt::math::RANSAC_Template, another RANSAC implementation where models can be matrices only.
44  *
45  * \author Zoltar Gaal
46  * \ingroup ransac_grp
47  */
49  private:
50  //! Select random (unique) indices from the 0..p_size sequence
51  void pickRandomIndex( size_t p_size, size_t p_pick, vector_size_t& p_ind );
52 
53  /** Select random (unique) indices from the set.
54  * The set is destroyed during pick */
55  void pickRandomIndex( std::set<size_t> p_set, size_t p_pick, vector_size_t& p_ind );
56 
57  public:
58  template<typename TModelFit>
59  bool ransacSingleModel( const TModelFit& p_state,
60  size_t p_kernelSize,
61  const typename TModelFit::Real& p_fitnessThreshold,
62  typename TModelFit::Model& p_bestModel,
63  vector_size_t& p_inliers );
64 
65  private:
66  template<typename TModelFit>
67  struct TSpecies {
68  typename TModelFit::Model model;
71  typename TModelFit::Real fitness;
72 
73  static bool compare( const TSpecies* p_a, const TSpecies* p_b )
74  {
75  return p_a->fitness < p_b->fitness;
76  }
77  };
78 
79  public:
80  template<typename TModelFit>
81  bool geneticSingleModel( const TModelFit& p_state,
82  size_t p_kernelSize,
83  const typename TModelFit::Real& p_fitnessThreshold,
84  size_t p_populationSize,
85  size_t p_maxIteration,
86  typename TModelFit::Model& p_bestModel,
87  vector_size_t& p_inliers );
88  }; // end of class
89 
90  } // namespace math
91 } // namespace mrpt
92 
93 // Template implementations:
94 #include "model_search_impl.h"
95 
96 #endif // math_modelsearch_h
Model search implementations: RANSAC and genetic algorithm.
Definition: model_search.h:48
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::vector< size_t > vector_size_t
Definition: types_simple.h:25
static bool compare(const TSpecies *p_a, const TSpecies *p_b)
Definition: model_search.h:73



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