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.
Random Class Reference

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)
 

Detailed Description

Constructor & Destructor Documentation

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.

Parameters
seedsets 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.

Member Function Documentation

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

Parameters
muthe mu parameter for the Gaussian distribution
sigmathe sigma parameter for the Gaussian distribution
Returns
returns a Float from the Gaussian distribution controlled by mu and sigma

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

Parameters
muthe mu parameter for the Gaussian distribution
sigmathe sigma parameter for the Gaussian distribution
Returns
returns a Float from the Gaussian distribution controlled by mu and sigma
Examples:
ClusteringModulesExamples/GaussianMixtureModelsExample/GaussianMixtureModelsExample.cpp.

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

Parameters
minRangethe minimum value in the range (inclusive)
maxRangethe maximum value in the range (not inclusive)
Returns
returns an integer in the range [minRange maxRange-1]
Examples:
ClusteringModulesExamples/GaussianMixtureModelsExample/GaussianMixtureModelsExample.cpp.

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

Parameters
minRangethe minimum value in the range (inclusive)
maxRangethe maximum value in the range (inclusive)
Returns
returns a Float in the range [minRange maxRange]
Examples:
ClusteringModulesExamples/GaussianMixtureModelsExample/GaussianMixtureModelsExample.cpp, PreprocessingModulesExamples/DeadZoneExample/DeadZoneExample.cpp, PreprocessingModulesExamples/DoubleMovingAverageFilterExample/DoubleMovingAverageFilterExample.cpp, and PreprocessingModulesExamples/MovingAverageFilterExample/MovingAverageFilterExample.cpp.

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.

Parameters
valuesa Vector containing the N possible values the function can return
weightsthe corresponding weights for the values Vector (must be the same size as the values Vector)
Returns
returns a random integer from the values Vector, with a probability relative to the values weight

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.

Parameters
weightedValuesa 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
Returns
returns a random integer from the values Vector, with a probability relative to the values weight

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.

Parameters
weightedValuesa 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
xa Vector containing the accumulated lookup table
Returns
returns a random integer from the values Vector, with a probability relative to the values weight

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.

Parameters
startRangeindicates the start of the range the random subset will selected from (e.g. 0)
endRangeindicates the end of the range the random subset will selected from (e.g. 100)
subsetSizecontrols the size of the Vector returned by the function (e.g. 50
Returns
returns a Vector of unsigned ints selected from the

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.

Parameters
numDimensionsthe size of the Vector you require
muthe mu parameter for the Gaussian distribution
sigmathe sigma parameter for the Gaussian distribution
Returns
returns a Vector of Floats drawn from the Gaussian distribution controlled by mu and sigma

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.

Parameters
numDimensionsthe size of the Vector you require
minRangethe minimum value in the range (inclusive)
maxRangethe maximum value in the range (inclusive)
Returns
returns a Vector of Floats drawn from the uniform distribution set by the minRange and maxRange

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

Parameters
minRangethe minimum value in the range (inclusive)
maxRangethe maximum value in the range (inclusive)
Returns
returns a Float in the range [minRange maxRange]

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.

Parameters
seedsets the current seed, If no seed is supplied then the seed will be set using the current system time
Returns
returns true if the seed was set successfully, false otherwise

Definition at line 40 of file Random.cpp.


The documentation for this class was generated from the following files: