|
Momentum
A library for solving nonlinear optimization problems related to human body kinematics
|
A consolidated random number generator providing convenient APIs wrapping the C++ standard library <random>. More...
#include <random.h>
Public Types | |
| using | Generator = Generator_ |
Public Member Functions | |
| Random (uint32_t seed=std::random_device{}()) | |
| Constructs a generator seeded with the given value. | |
| template<typename T> | |
| T | uniform (const T &min, const T &max) |
| Generates a random scalar/vector/matrix from the uniform distribution. | |
| template<typename FixedSizeT> | |
| FixedSizeT | uniform (typename FixedSizeT::Scalar min, typename FixedSizeT::Scalar max) |
| Generates a fixed-size vector/matrix from the uniform distribution with a single scalar range applied to every element. | |
| template<typename DynamicVector> | |
| DynamicVector | uniform (Eigen::Index size, typename DynamicVector::Scalar min, typename DynamicVector::Scalar max) |
| Generates a dynamic-size vector from the uniform distribution with a single scalar range applied to every element. | |
| template<typename DynamicMatrix> | |
| DynamicMatrix | uniform (Eigen::Index rows, Eigen::Index cols, typename DynamicMatrix::Scalar min, typename DynamicMatrix::Scalar max) |
| Generates a dynamic-size matrix from the uniform distribution with a single scalar range applied to every element. | |
| template<typename T> | |
| Quaternion< T > | uniformQuaternion () |
| Generates a random unit quaternion uniformly distributed on SO(3) (Haar measure). | |
| template<typename T> | |
| Matrix3< T > | uniformRotationMatrix () |
| Generates a random rotation matrix uniformly distributed on SO(3) (Haar measure). | |
| template<typename T> | |
| Isometry3< T > | uniformIsometry3 (const Vector3< T > &min=Vector3< T >::Zero(), const Vector3< T > &max=Vector3< T >::Ones()) |
| Generates a random isometry (rigid transformation) on SE(3) with rotation drawn uniformly from SO(3) and translation drawn uniformly from the box [min, max]. | |
| template<typename T> | |
| Affine3< T > | uniformAffine3 (T scaleMin=T(0.1), T scaleMax=T(10.0), const Vector3< T > &min=Vector3< T >::Zero(), const Vector3< T > &max=Vector3< T >::Ones()) |
| Generates a random affine transformation with rotation drawn uniformly from SO(3), uniform scale drawn from [scaleMin, scaleMax], and translation drawn uniformly from the box [min, max]. | |
| template<typename T> | |
| T | normal (const T &mean, const T &sigma) |
| Generates a value from a normal (Gaussian) distribution N(mean, sigma^2). | |
| template<typename FixedSizeT> | |
| FixedSizeT | normal (typename FixedSizeT::Scalar mean, typename FixedSizeT::Scalar sigma) |
| Generates a fixed-size vector/matrix with each element drawn independently from N(mean, sigma^2). | |
| template<typename DynamicVector> | |
| DynamicVector | normal (Eigen::Index size, typename DynamicVector::Scalar mean, typename DynamicVector::Scalar sigma) |
| Generates a dynamic-size vector with each element drawn independently from N(mean, sigma^2). | |
| template<typename DynamicMatrix> | |
| DynamicMatrix | normal (Eigen::Index rows, Eigen::Index cols, typename DynamicMatrix::Scalar mean, typename DynamicMatrix::Scalar sigma) |
| Generates a dynamic-size matrix with each element drawn independently from N(mean, sigma^2). | |
| uint32_t | getSeed () const |
| Returns the seed last used to initialize the engine. | |
| void | setSeed (uint32_t seed) |
| Re-seeds the internal engine, resetting its state to the deterministic sequence implied by seed. | |
Static Public Member Functions | |
| static Random & | GetSingleton () |
| Returns the process-wide singleton instance. | |
A consolidated random number generator providing convenient APIs wrapping the C++ standard library <random>.
The default engine is std::mt19937; any engine satisfying the C++ UniformRandomBitGenerator requirements can be substituted via the template parameter (see: https://en.cppreference.com/w/cpp/numeric/random).
| using momentum::Random< Generator_ >::Generator = Generator_ |
|
explicit |
Constructs a generator seeded with the given value.
| seed | Seed for the underlying engine. Defaults to a non-deterministic value drawn from std::random_device, which makes default-constructed instances non-reproducible. |
Definition at line 192 of file random-inl.h.
Referenced by GetSingleton().
|
nodiscard |
Returns the seed last used to initialize the engine.
Definition at line 311 of file random-inl.h.
|
staticnodiscard |
Returns the process-wide singleton instance.
Definition at line 186 of file random-inl.h.
References Random().
Referenced by momentum::normal(), momentum::normal(), momentum::normal(), momentum::normal(), momentum::uniform(), momentum::uniform(), momentum::uniform(), momentum::uniform(), momentum::uniformAffine3(), momentum::uniformIsometry3(), and momentum::uniformQuaternion().
|
nodiscard |
Generates a value from a normal (Gaussian) distribution N(mean, sigma^2).
Each element of a vector/matrix result is drawn independently.
Backed by std::normal_distribution, which requires a real (floating-point) scalar type.
| T | Scalar, fixed-size, or dynamic-size Eigen type with floating-point scalar. |
| [in] | mean | Distribution mean (mu). |
| [in] | sigma | Distribution standard deviation (sigma). |
Definition at line 274 of file random-inl.h.
References momentum::detail::generateNormal().
|
nodiscard |
Generates a dynamic-size matrix with each element drawn independently from N(mean, sigma^2).
| DynamicMatrix | Dynamic-size Eigen matrix type with floating-point scalar. |
| [in] | rows | Number of rows in the result. |
| [in] | cols | Number of columns in the result. |
| [in] | mean | Distribution mean applied to every element. |
| [in] | sigma | Distribution standard deviation applied to every element. |
Definition at line 299 of file random-inl.h.
References momentum::detail::generateMatrixNormal().
|
nodiscard |
Generates a dynamic-size vector with each element drawn independently from N(mean, sigma^2).
| DynamicVector | Dynamic-size Eigen vector type with floating-point scalar. |
| [in] | size | Number of elements in the result. |
| [in] | mean | Distribution mean applied to every element. |
| [in] | sigma | Distribution standard deviation applied to every element. |
Definition at line 289 of file random-inl.h.
References momentum::detail::generateMatrixNormal().
|
nodiscard |
Generates a fixed-size vector/matrix with each element drawn independently from N(mean, sigma^2).
| FixedSizeT | Fixed-size Eigen vector/matrix type with floating-point scalar. |
| [in] | mean | Distribution mean applied to every element. |
| [in] | sigma | Distribution standard deviation applied to every element. |
Definition at line 280 of file random-inl.h.
References momentum::detail::generateMatrixNormal().
| void momentum::Random< Generator >::setSeed | ( | uint32_t | seed | ) |
Re-seeds the internal engine, resetting its state to the deterministic sequence implied by seed.
Definition at line 316 of file random-inl.h.
|
nodiscard |
Generates a random scalar/vector/matrix from the uniform distribution.
Supported element types are integer types accepted by std::uniform_int_distribution<T> (see: https://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution) and any type for which std::is_floating_point<T>::value is true (see: https://en.cppreference.com/w/cpp/types/is_floating_point). T may be a scalar, a fixed-size Eigen vector/matrix, or a dynamic-size Eigen vector/matrix (in which case the result has the same dimensions as min).
The result lies in [min, max] for integer types and [min, max) for real types.
For vector/matrix types, supplying vector/matrix bounds applies a per-element range; use the scalar-bounds overload to apply the same range to every element.
| T | Scalar, fixed-size, or dynamic-size Eigen type. |
| [in] | min | Inclusive lower bound (element-wise). |
| [in] | max | Upper bound (inclusive for integer types, exclusive for real types). |
Definition at line 196 of file random-inl.h.
References momentum::detail::generateUniform().
Referenced by uniformAffine3(), and uniformIsometry3().
|
nodiscard |
Generates a dynamic-size matrix from the uniform distribution with a single scalar range applied to every element.
Same range semantics as uniform(const T&, const T&).
| DynamicMatrix | Dynamic-size Eigen matrix type. |
| [in] | rows | Number of rows in the result. |
| [in] | cols | Number of columns in the result. |
| [in] | min | Inclusive lower bound applied to every element. |
| [in] | max | Upper bound applied to every element (inclusive for integer scalars, exclusive for real scalars). |
Definition at line 221 of file random-inl.h.
References momentum::detail::generateMatrixUniform().
|
nodiscard |
Generates a dynamic-size vector from the uniform distribution with a single scalar range applied to every element.
Same range semantics as uniform(const T&, const T&).
| DynamicVector | Dynamic-size Eigen vector type. |
| [in] | size | Number of elements in the result. |
| [in] | min | Inclusive lower bound applied to every element. |
| [in] | max | Upper bound applied to every element (inclusive for integer scalars, exclusive for real scalars). |
Definition at line 211 of file random-inl.h.
References momentum::detail::generateMatrixUniform().
|
nodiscard |
Generates a fixed-size vector/matrix from the uniform distribution with a single scalar range applied to every element.
Same range semantics as uniform(const T&, const T&).
| FixedSizeT | Fixed-size Eigen vector/matrix type. |
| [in] | min | Inclusive lower bound applied to every element. |
| [in] | max | Upper bound applied to every element (inclusive for integer scalars, exclusive for real scalars). |
Definition at line 202 of file random-inl.h.
References momentum::detail::generateMatrixUniform().
|
nodiscard |
Generates a random affine transformation with rotation drawn uniformly from SO(3), uniform scale drawn from [scaleMin, scaleMax], and translation drawn uniformly from the box [min, max].
| T | Floating-point scalar type of the affine components (float or double). The defaults below are floating-point literals, so instantiation with an integer T is rejected by a static_assert in the implementation rather than silently truncating the defaults. |
| scaleMin | Inclusive lower bound on the uniform scale factor. |
| scaleMax | Inclusive upper bound on the uniform scale factor. |
| min | Inclusive lower bound on the translation component (per axis). |
| max | Inclusive upper bound on the translation component (per axis). |
Definition at line 255 of file random-inl.h.
References uniform(), momentum::uniform(), and momentum::uniformRotationMatrix().
|
nodiscard |
Generates a random isometry (rigid transformation) on SE(3) with rotation drawn uniformly from SO(3) and translation drawn uniformly from the box [min, max].
| T | Scalar type of the isometry components, typically float or double. |
| min | Inclusive lower bound on the translation component (per axis). |
| max | Inclusive upper bound on the translation component (per axis). |
Definition at line 246 of file random-inl.h.
References uniform(), and momentum::uniformRotationMatrix().
|
nodiscard |
Generates a random unit quaternion uniformly distributed on SO(3) (Haar measure).
Definition at line 234 of file random-inl.h.
|
nodiscard |
Generates a random rotation matrix uniformly distributed on SO(3) (Haar measure).
Definition at line 240 of file random-inl.h.
References momentum::uniformQuaternion().