MRPT  1.9.9
mrpt::math::ModelSearch Class Reference

Detailed Description

Model search implementations: RANSAC and genetic algorithm.

The type TModelFit is a user-supplied struct/class that implements this interface:

  • Types:
    • Real : The numeric type to use (typ: double, float)
    • Model : The type of the model to be fitted (for example: A matrix, a TLine2D, a TPlane3D, ...)
  • Methods:
    • size_t getSampleCount() const : return the number of samples. This should not change during a model search.
    • bool fitModel( const std::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.
    • 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.

There are two methods provided in this class to fit a model:

  • ransacSingleModel (RANSAC): Just like mrpt::math::RANSAC_Template
  • geneticSingleModel (Genetic): Provides a mixture of a genetic and the ransac algorithm. Instead of selecting a set of data in each iteration, it takes more (ex. 10) and order these model using some fitness function: the average error of the inliers scaled by the number of outliers (This fitness might require some fine tuning). Than the (ex 10) new kernel for the next iteration is created as follows:
    • Take the best kernels (as for the original ransac)
    • 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)
    • Generate some new random samples.

For an example of usage, see "samples/model_search_test/"

See also
mrpt::math::RANSAC_Template, another RANSAC implementation where models can be matrices only.
Author
Zoltar Gaal

Definition at line 64 of file model_search.h.

#include <mrpt/math/model_search.h>

Classes

struct  TSpecies
 

Public Member Functions

template<typename TModelFit >
bool ransacSingleModel (const TModelFit &p_state, size_t p_kernelSize, const typename TModelFit::Real &p_fitnessThreshold, typename TModelFit::Model &p_bestModel, std::vector< size_t > &p_inliers)
 Run the ransac algorithm searching for a single model. More...
 
template<typename TModelFit >
bool geneticSingleModel (const TModelFit &p_state, size_t p_kernelSize, const typename TModelFit::Real &p_fitnessThreshold, size_t p_populationSize, size_t p_maxIteration, typename TModelFit::Model &p_bestModel, std::vector< size_t > &p_inliers)
 Run a generic programming version of ransac searching for a single model. More...
 

Private Member Functions

void pickRandomIndex (size_t p_size, size_t p_pick, std::vector< size_t > &p_ind)
 Select random (unique) indices from the 0..p_size sequence. More...
 
void pickRandomIndex (std::set< size_t > p_set, size_t p_pick, std::vector< size_t > &p_ind)
 Select random (unique) indices from the set. More...
 

Member Function Documentation

◆ geneticSingleModel()

template<typename TModelFit >
bool mrpt::math::ModelSearch::geneticSingleModel ( const TModelFit &  p_state,
size_t  p_kernelSize,
const typename TModelFit::Real &  p_fitnessThreshold,
size_t  p_populationSize,
size_t  p_maxIteration,
typename TModelFit::Model &  p_bestModel,
std::vector< size_t > &  p_inliers 
)

Run a generic programming version of ransac searching for a single model.

Definition at line 95 of file model_search_impl.h.

References ASSERT_, and pickRandomIndex().

◆ pickRandomIndex() [1/2]

void ModelSearch::pickRandomIndex ( size_t  p_size,
size_t  p_pick,
std::vector< size_t > &  p_ind 
)
private

Select random (unique) indices from the 0..p_size sequence.

Definition at line 21 of file model_search.cpp.

References ASSERT_, and mrpt::random::shuffle().

Referenced by geneticSingleModel(), and ransacSingleModel().

◆ pickRandomIndex() [2/2]

void ModelSearch::pickRandomIndex ( std::set< size_t >  p_set,
size_t  p_pick,
std::vector< size_t > &  p_ind 
)
private

Select random (unique) indices from the set.

The set is destroyed during pick

Definition at line 37 of file model_search.cpp.

References mrpt::random::shuffle().

◆ ransacSingleModel()

template<typename TModelFit >
bool mrpt::math::ModelSearch::ransacSingleModel ( const TModelFit &  p_state,
size_t  p_kernelSize,
const typename TModelFit::Real &  p_fitnessThreshold,
typename TModelFit::Model &  p_bestModel,
std::vector< size_t > &  p_inliers 
)

Run the ransac algorithm searching for a single model.

Definition at line 24 of file model_search_impl.h.

References ASSERT_, eps, min, and pickRandomIndex().




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