GestureRecognitionToolkit
Version: 0.2.5
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
|
This file contains the Random class, a useful wrapper for generating cross platform random functions. This includes functions for uniform distributions (both integer and Float) and Gaussian distributions. More...
#include <Random.h>
Public Member Functions | |
Random (unsigned long long seed=0) | |
~Random () | |
bool | setSeed (const unsigned long long seed=0) |
int | getRandomNumberInt (int minRange, int maxRange) |
int | getRandomNumberWeighted (const Vector< int > &values, const VectorFloat &weights) |
int | getRandomNumberWeighted (Vector< IndexedDouble > weightedValues) |
int | getRandomNumberWeighted (Vector< IndexedDouble > &weightedValues, VectorFloat &x) |
Float | getRandomNumberUniform (Float minRange=0.0, Float maxRange=1.0) |
Float | getUniform (const Float &minRange=0.0, const Float &maxRange=1.0) |
Float | getRandomNumberGauss (Float mu=0.0, Float sigma=1.0) |
Float | getGauss (const Float &mu=0.0, const Float &sigma=1.0) |
VectorFloat | getRandomVectorUniform (UINT numDimensions, Float minRange=0.0, Float maxRange=1.0) |
VectorFloat | getRandomVectorGauss (UINT numDimensions, Float mu=0.0, Float sigma=1.0) |
Vector< unsigned int > | getRandomSubset (const unsigned int startRange, const unsigned int endRange, const unsigned int subsetSize) |
This file contains the Random class, a useful wrapper for generating cross platform random functions. This includes functions for uniform distributions (both integer and Float) and Gaussian distributions.
GRT_BEGIN_NAMESPACE Random::Random | ( | unsigned long long | seed = 0 | ) |
Default constructor. Sets the random seed. If no seed is supplied then the seed will be set using the current system time.
seed | sets the current seed, If no seed is supplied then the seed will be set using the current system time |
Definition at line 29 of file Random.cpp.
Random::~Random | ( | ) |
Default destructor.
Definition at line 38 of file Random.cpp.
Float Random::getGauss | ( | const Float & | mu = 0.0 , |
const Float & | sigma = 1.0 |
||
) |
Gets a random Float, using a Gaussian distribution with mu 0 and sigma 1.0
mu | the mu parameter for the Gaussian distribution |
sigma | the sigma parameter for the Gaussian distribution |
Definition at line 146 of file Random.cpp.
Float Random::getRandomNumberGauss | ( | Float | mu = 0.0 , |
Float | sigma = 1.0 |
||
) |
Gets a random Float, using a Gaussian distribution with mu 0 and sigma 1.0
mu | the mu parameter for the Gaussian distribution |
sigma | the sigma parameter for the Gaussian distribution |
Definition at line 142 of file Random.cpp.
int Random::getRandomNumberInt | ( | int | minRange, |
int | maxRange | ||
) |
Gets a random integer in the range [minRange maxRange-1], using a uniform distribution
minRange | the minimum value in the range (inclusive) |
maxRange | the maximum value in the range (not inclusive) |
Definition at line 59 of file Random.cpp.
Float Random::getRandomNumberUniform | ( | Float | minRange = 0.0 , |
Float | maxRange = 1.0 |
||
) |
Gets a random Float in the range [minRange maxRange], using a uniform distribution
minRange | the minimum value in the range (inclusive) |
maxRange | the maximum value in the range (inclusive) |
Definition at line 129 of file Random.cpp.
int Random::getRandomNumberWeighted | ( | const Vector< int > & | values, |
const VectorFloat & | weights | ||
) |
Gets a random integer from the Vector values. The probability of choosing a specific integer from the values Vector is given by the corresponding weight in the weights Vector. The size of the values Vector must match the size of the weights Vector. The weights do not need to sum to 1.
For example, if the input values are: [1 2 3] and weights are: [0.7 0.2 0.1], then the 1 value would be randomly returned 70% of the time, the 2 value returned 20% of the time and the 3 value returned 10% of the time.
values | a Vector containing the N possible values the function can return |
weights | the corresponding weights for the values Vector (must be the same size as the values Vector) |
Definition at line 68 of file Random.cpp.
int Random::getRandomNumberWeighted | ( | Vector< IndexedDouble > | weightedValues | ) |
Gets a random integer from the input Vector. The probability of choosing a specific integer is given by the corresponding weight of that value. The weights do not need to sum to 1.
For example, if the input values are: [{1 0.7},{2 0.2}, {3 0.1}], then the 1 value would be randomly returned 70% of the time, the 2 value returned 20% of the time and the 3 value returned 10% of the time.
weightedValues | a Vector of IndexedDouble values, the (int) indexs represent the value that will be returned while the (Float) values represent the weight of choosing that specific index |
Definition at line 82 of file Random.cpp.
int Random::getRandomNumberWeighted | ( | Vector< IndexedDouble > & | weightedValues, |
VectorFloat & | x | ||
) |
This function is similar to the getRandomNumberWeighted(Vector< IndexedDouble > weightedValues), with the exception that the user needs to sort the weightedValues Vector and create the accumulated lookup table (x). This is useful if you need to call the same function multiple times on the same weightedValues, allowing you to only sort and build the loopup table once.
Gets a random integer from the input Vector. The probability of choosing a specific integer is given by the corresponding weight of that value. The weights do not need to sum to 1.
For example, if the input values are: [{1 0.7},{2 0.2}, {3 0.1}], then the 1 value would be randomly returned 70% of the time, the 2 value returned 20% of the time and the 3 value returned 10% of the time.
weightedValues | a sorted Vector of IndexedDouble values, the (int) indexs represent the value that will be returned while the (Float) values represent the weight of choosing that specific index |
x | a Vector containing the accumulated lookup table |
Definition at line 111 of file Random.cpp.
Vector< unsigned int > Random::getRandomSubset | ( | const unsigned int | startRange, |
const unsigned int | endRange, | ||
const unsigned int | subsetSize | ||
) |
Gets an N-dimensional Vector of random unsigned ints drawn from the range controlled by the start and end range parameters.
startRange | indicates the start of the range the random subset will selected from (e.g. 0) |
endRange | indicates the end of the range the random subset will selected from (e.g. 100) |
subsetSize | controls the size of the Vector returned by the function (e.g. 50 |
Definition at line 185 of file Random.cpp.
VectorFloat Random::getRandomVectorGauss | ( | UINT | numDimensions, |
Float | mu = 0.0 , |
||
Float | sigma = 1.0 |
||
) |
Gets an N-dimensional Vector of random Floats drawn from the Gaussian distribution controlled by mu and sigma.
numDimensions | the size of the Vector you require |
mu | the mu parameter for the Gaussian distribution |
sigma | the sigma parameter for the Gaussian distribution |
Definition at line 177 of file Random.cpp.
VectorFloat Random::getRandomVectorUniform | ( | UINT | numDimensions, |
Float | minRange = 0.0 , |
||
Float | maxRange = 1.0 |
||
) |
Gets an N-dimensional Vector of random Floats drawn from the uniform distribution set by the minRange and maxRange.
numDimensions | the size of the Vector you require |
minRange | the minimum value in the range (inclusive) |
maxRange | the maximum value in the range (inclusive) |
Definition at line 169 of file Random.cpp.
Float Random::getUniform | ( | const Float & | minRange = 0.0 , |
const Float & | maxRange = 1.0 |
||
) |
Gets a random Float in the range [minRange maxRange], using a uniform distribution
minRange | the minimum value in the range (inclusive) |
maxRange | the maximum value in the range (inclusive) |
Definition at line 133 of file Random.cpp.
bool Random::setSeed | ( | const unsigned long long | seed = 0 | ) |
Sets the current seed used to compute the random distrubutions.
seed | sets the current seed, If no seed is supplied then the seed will be set using the current system time |
Definition at line 40 of file Random.cpp.