Main MRPT website > C++ reference for MRPT 1.9.9
Classes | Functions
mrpt::random Namespace Reference

Detailed Description

A namespace of pseudo-random numbers generators of diferent distributions.

The central class in this namespace is mrpt::random::CRandomGenerator

Classes

class  CRandomGenerator
 A thred-safe pseudo random number generator, based on an internal MT19937 randomness generator. More...
 

Functions

template<class RandomIt , class URBG >
void shuffle (RandomIt first, RandomIt last, URBG &&g)
 Uniform shuffle a sequence. More...
 
template<class RandomIt >
void shuffle (RandomIt first, RandomIt last)
 Uniform shuffle a sequence. More...
 
CRandomGeneratorgetRandomGenerator ()
 A static instance of a CRandomGenerator class, for use in single-thread applications. More...
 
ptrdiff_t random_generator_for_STL (ptrdiff_t i)
 A random number generator for usage in STL algorithms expecting a function like this (eg, random_shuffle): More...
 
template<class MAT >
void matrixRandomUni (MAT &matrix, const double unif_min=0, const double unif_max=1)
 Fills the given matrix with independent, uniformly distributed samples. More...
 
template<class T >
void vectorRandomUni (std::vector< T > &v_out, const T &unif_min=0, const T &unif_max=1)
 Fills the given matrix with independent, uniformly distributed samples. More...
 
template<class MAT >
void matrixRandomNormal (MAT &matrix, const double mean=0, const double std=1)
 Fills the given matrix with independent, normally distributed samples. More...
 
template<class T >
void vectorRandomNormal (std::vector< T > &v_out, const T &mean=0, const T &std=1)
 Generates a random vector with independent, normally distributed samples. More...
 
void Randomize (const uint32_t seed)
 Randomize the generators. More...
 
void Randomize ()
 
template<class T >
void randomPermutation (const std::vector< T > &in_vector, std::vector< T > &out_result)
 Returns a random permutation of a vector: all the elements of the input vector are in the output but at random positions. More...
 
template<typename T , typename MATRIX >
void randomNormalMultiDimensionalMany (const MATRIX &cov, size_t desiredSamples, std::vector< std::vector< T >> &ret, std::vector< T > *samplesLikelihoods=nullptr)
 Generate a given number of multidimensional random samples according to a given covariance matrix. More...
 
template<typename T , typename MATRIXLIKE >
void randomNormalMultiDimensionalMany (const MATRIXLIKE &cov, size_t desiredSamples, std::vector< std::vector< T >> &ret)
 Generate multidimensional random samples according to a given covariance matrix. More...
 
template<typename T , typename MATRIX >
void randomNormalMultiDimensional (const MATRIX &cov, std::vector< T > &out_result)
 Generate multidimensional random samples according to a given covariance matrix. More...
 

Function Documentation

◆ getRandomGenerator()

CRandomGenerator & mrpt::random::getRandomGenerator ( )

A static instance of a CRandomGenerator class, for use in single-thread applications.

Definition at line 19 of file RandomGenerator.cpp.

References randomGenerator.

Referenced by mrpt::slam::CGridMapAligner::AlignPDF_robustMatch(), atan2_lut_test(), mrpt::hmtslam::CHierarchicalMapMHPartition::computeCoordinatesTransformationBetweenNodes(), mrpt::obs::CActionRobotMovement3D::computeFromOdometry_model6DOF(), mrpt::obs::CActionRobotMovement2D::computeFromOdometry_modelThrun(), mrpt::bayes::CParticleFilterCapable::computeResampling(), mrpt::poses::CPosePDFParticles::copyFrom(), GraphSlamLevMarqTest< my_graph_t >::create_ring_path(), mrpt::opengl::CPolyhedron::CreateRandomPolyhedron(), mrpt::poses::CPoseRandomSampler::do_sample_2D(), mrpt::poses::CPoseRandomSampler::do_sample_3D(), do_test_init_random(), mrpt::poses::CPose3DQuatPDFGaussianInf::drawManySamples(), mrpt::poses::CPose3DQuatPDFGaussian::drawManySamples(), mrpt::poses::CPose3DPDFGaussianInf::drawManySamples(), mrpt::poses::CPosePDFGaussian::drawManySamples(), mrpt::poses::CPose3DPDFGaussian::drawManySamples(), mrpt::poses::CPosePDFGaussianInf::drawManySamples(), mrpt::poses::CPoint2DPDFGaussian::drawSingleSample(), mrpt::poses::CPose3DQuatPDFGaussianInf::drawSingleSample(), mrpt::poses::CPose3DQuatPDFGaussian::drawSingleSample(), mrpt::poses::CPose3DPDFGaussianInf::drawSingleSample(), mrpt::poses::CPosePDFGaussian::drawSingleSample(), mrpt::poses::CPosePDFParticles::drawSingleSample(), mrpt::poses::CPointPDFGaussian::drawSingleSample(), mrpt::poses::CPose3DPDFGaussian::drawSingleSample(), mrpt::poses::CPosePDFGaussianInf::drawSingleSample(), mrpt::poses::CPointPDFSOG::drawSingleSample(), mrpt::obs::CActionRobotMovement2D::drawSingleSample_modelThrun(), mrpt::math::RANSAC_Template< NUMTYPE >::execute(), mrpt::bayes::CParticleFilterCapable::fastDrawSample(), mrpt::obs::CActionRobotMovement2D::fastDrawSingleSample_modelGaussian(), PosePDFGaussTests::generateRandomPose2DPDF(), Pose3DPDFGaussTests::generateRandomPose3DPDF(), Pose3DQuatPDFGaussTests::generateRandomPose3DPDF(), generateRandomSparseMatrix(), mrpt::maps::CBeaconMap::internal_insertObservation(), matrixRandomNormal(), matrixRandomUni(), mrpt::slam::PF_implementation< mrpt::math::TPose3D, CMonteCarloLocalization3D, mrpt::bayes::particle_storage_mode::VALUE >::PF_SLAM_aux_perform_one_rejection_sampling_step(), mrpt::slam::PF_implementation< mrpt::math::TPose3D, CMonteCarloLocalization3D, mrpt::bayes::particle_storage_mode::VALUE >::PF_SLAM_implementation_pfAuxiliaryPFStandardAndOptimal(), mrpt::hmtslam::CLSLAM_RBPF_2DLASER::prediction_and_update_pfAuxiliaryPFOptimal(), mrpt::maps::CMultiMetricMapPDF::prediction_and_update_pfOptimalProposal(), random_generator_for_STL(), Randomize(), randomNormalMultiDimensional(), randomNormalMultiDimensionalMany(), randomPermutation(), ransac_data_assoc_run(), mrpt::bayes::CRejectionSamplingCapable< CPose2D >::rejectionSampling(), mrpt::poses::CPosePDFParticles::resetAroundSetOfPoses(), mrpt::poses::CPosePDFParticles::resetUniform(), mrpt::slam::CMonteCarloLocalization2D::resetUniformFreeSpace(), mrpt::slam::CRejectionSamplingRangeOnlyLocalization::RS_drawFromProposal(), run_test_pf_localization(), mrpt::maps::COccupancyGridMap2D::saveAsBitmapTwoMapsWithCorrespondences(), mrpt::tfest::se2_l2_robust(), mrpt::tfest::se3_l2_robust(), mrpt::maps::CBeaconMap::simulateBeaconReadings(), mrpt::maps::CLandmarksMap::simulateBeaconReadings(), mrpt::kinematics::CVehicleSimulVirtualBase::simulateOneTimeStep(), mrpt::maps::CLandmarksMap::simulateRangeBearingReadings(), mrpt::maps::COccupancyGridMap2D::simulateScanRay(), mrpt::nav::PlannerRRT_SE2_TPS::solve(), TEST(), TEST_F(), mrpt::hmtslam::CHMTSLAM::thread_LSLAM(), mrpt::hmtslam::CHMTSLAM::thread_TBI(), mrpt::math::transform_gaussian_montecarlo(), vectorRandomNormal(), and vectorRandomUni().

◆ matrixRandomNormal()

template<class MAT >
void mrpt::random::matrixRandomNormal ( MAT &  matrix,
const double  mean = 0,
const double  std = 1 
)

Fills the given matrix with independent, normally distributed samples.

Matrix classes can be mrpt::math::CMatrixTemplateNumeric or mrpt::math::CMatrixFixedNumeric

See also
matrixRandomUni

Definition at line 421 of file RandomGenerators.h.

References mrpt::random::CRandomGenerator::drawGaussian1D_normalized(), getRandomGenerator(), and mean().

◆ matrixRandomUni()

template<class MAT >
void mrpt::random::matrixRandomUni ( MAT &  matrix,
const double  unif_min = 0,
const double  unif_max = 1 
)

Fills the given matrix with independent, uniformly distributed samples.

Matrix classes can be mrpt::math::CMatrixTemplateNumeric or mrpt::math::CMatrixFixedNumeric

See also
matrixRandomNormal

Definition at line 394 of file RandomGenerators.h.

References mrpt::random::CRandomGenerator::drawUniform(), and getRandomGenerator().

◆ random_generator_for_STL()

ptrdiff_t mrpt::random::random_generator_for_STL ( ptrdiff_t  i)
inline

A random number generator for usage in STL algorithms expecting a function like this (eg, random_shuffle):

Definition at line 383 of file RandomGenerators.h.

References mrpt::random::CRandomGenerator::drawUniform32bit(), and getRandomGenerator().

◆ Randomize() [1/2]

void mrpt::random::Randomize ( )
inline

◆ Randomize() [2/2]

void mrpt::random::Randomize ( const uint32_t  seed)
inline

Randomize the generators.

A seed can be providen, or a current-time based seed can be used (default)

Definition at line 446 of file RandomGenerators.h.

References getRandomGenerator(), and mrpt::random::CRandomGenerator::randomize().

◆ randomNormalMultiDimensional()

template<typename T , typename MATRIX >
void mrpt::random::randomNormalMultiDimensional ( const MATRIX &  cov,
std::vector< T > &  out_result 
)

Generate multidimensional random samples according to a given covariance matrix.

Exceptions
std::exceptionOn invalid covariance matrix
See also
randomNormalMultiDimensionalMany

Definition at line 503 of file RandomGenerators.h.

References mrpt::math::cov(), mrpt::random::CRandomGenerator::drawGaussianMultivariate(), and getRandomGenerator().

◆ randomNormalMultiDimensionalMany() [1/2]

template<typename T , typename MATRIX >
void mrpt::random::randomNormalMultiDimensionalMany ( const MATRIX &  cov,
size_t  desiredSamples,
std::vector< std::vector< T >> &  ret,
std::vector< T > *  samplesLikelihoods = nullptr 
)

Generate a given number of multidimensional random samples according to a given covariance matrix.

Parameters
covThe covariance matrix where to draw the samples from.
desiredSamplesThe number of samples to generate.
samplesLikelihoodsIf desired, set to a valid pointer to a vector, where it will be stored the likelihoods of having obtained each sample: the product of the gaussian-pdf for each independent variable.
retThe output list of samples
Exceptions
std::exceptionOn invalid covariance matrix
See also
randomNormalMultiDimensional

Definition at line 475 of file RandomGenerators.h.

References mrpt::math::cov(), mrpt::random::CRandomGenerator::drawGaussianMultivariateMany(), and getRandomGenerator().

◆ randomNormalMultiDimensionalMany() [2/2]

template<typename T , typename MATRIXLIKE >
void mrpt::random::randomNormalMultiDimensionalMany ( const MATRIXLIKE &  cov,
size_t  desiredSamples,
std::vector< std::vector< T >> &  ret 
)

Generate multidimensional random samples according to a given covariance matrix.

Exceptions
std::exceptionOn invalid covariance matrix
See also
randomNormalMultiDimensional

Definition at line 490 of file RandomGenerators.h.

References mrpt::math::cov(), mrpt::random::CRandomGenerator::drawGaussianMultivariateMany(), and getRandomGenerator().

◆ randomPermutation()

template<class T >
void mrpt::random::randomPermutation ( const std::vector< T > &  in_vector,
std::vector< T > &  out_result 
)

Returns a random permutation of a vector: all the elements of the input vector are in the output but at random positions.

Definition at line 455 of file RandomGenerators.h.

References getRandomGenerator(), and mrpt::random::CRandomGenerator::permuteVector().

◆ vectorRandomNormal()

template<class T >
void mrpt::random::vectorRandomNormal ( std::vector< T > &  v_out,
const T &  mean = 0,
const T &  std = 1 
)

Generates a random vector with independent, normally distributed samples.

See also
matrixRandomUni

Definition at line 434 of file RandomGenerators.h.

References mrpt::random::CRandomGenerator::drawGaussian1D_normalized(), getRandomGenerator(), and mean().

◆ vectorRandomUni()

template<class T >
void mrpt::random::vectorRandomUni ( std::vector< T > &  v_out,
const T &  unif_min = 0,
const T &  unif_max = 1 
)

Fills the given matrix with independent, uniformly distributed samples.

See also
vectorRandomNormal

Definition at line 407 of file RandomGenerators.h.

References mrpt::random::CRandomGenerator::drawUniform(), and getRandomGenerator().




Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST