Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
BIAS::Random Class Reference

class for producing random numbers from different distributions More...

#include <Base/Math/Random.hh>

+ Inheritance diagram for BIAS::Random:
+ Collaboration diagram for BIAS::Random:

Public Member Functions

void AddDebugLevel (const long int lv)
 
void AddDebugLevel (const std::string &name)
 
bool DebugLevelIsSet (const long int lv) const
 
bool DebugLevelIsSet (const std::string &name) const
 
int GetDebugLevel () const
 
std::ostream & GetDebugStream () const
 
void GetDebugStream (std::ostream &os) const
 
void GetMeanAndCovariance (const std::vector< double > &samples, double &mean, double &covariance) const
 check-function to compute mean and cov from samples More...
 
void GetMeanAndCovariance (const std::vector< BIAS::Vector< double > > &samples, BIAS::Vector< double > &mean, BIAS::Matrix< double > &covariance) const
 check-function to compute mean and cov from samples More...
 
double GetNormalDistributed (const double mean, const double sigma)
 on succesive calls return normal distributed random variable with mean and standard deviation sigma More...
 
void GetNormalDistributed (const double mean, const double sigma, const int num, std::vector< double > &res)
 calculates num normal ditributed random variables and stores them in res More...
 
int GetNormalDistributed (const Vector2< double > &mean, const Matrix2x2< double > &cov, Vector2< double > &ran)
 See GetNormalDistributed(). More...
 
int GetNormalDistributed (const Vector2< double > &mean, const Matrix2x2< double > &cov, const int num, std::vector< Vector2< double > > &ran)
 Generates a vector of length num containing 2D (dependent) normal distributed random variables. More...
 
void GetNormalDistributed (const double mean, const double sigma, const int num, double *res)
 old deprectade interfaces More...
 
double GetNormalDistributedGSL (const double mean, const double sigma)
 interface to GSL for comparison purposes More...
 
int GetQuasiNormalDistributed (const int dim, Vector< double > &res)
 On subsequent calls returns a Sobol' sequence of quasi random numbers 'normal distributed' with mean 0 and Covariance matrix identity Input: dim - dimension of requested sequqnce, in range [1,6] Output: res - quasi random vector See GetQuasiUniformDistributed() and sobseq_() for details. More...
 
int GetQuasiNormalDistributed (const int dim, const unsigned num, std::vector< Vector< double > > &res)
 returns a quasi random seuqence of 'normal dsitributed' numbres. More...
 
int GetQuasiUniformDistributed (const int dim, const Vector< double > &min, const Vector< double > &max, Vector< double > &res)
 On subsequent calls returns a Sobol' sequence of quasi random numbers 'uniformly distributed' in a N-dimensional cube between min and max. More...
 
int GetQuasiUniformDistributed (const int dim, const Vector< double > &min, const Vector< double > &max, const unsigned num, std::vector< Vector< double > > &res)
 Returns a Sobol' sequence of num quasi random numbers 'uniformly distributed' in the N-dimensional cube between min and max. More...
 
double GetUniformDistributed (const double min, const double max)
 on succesive calls return uniform distributed random variable between min and max More...
 
void GetUniformDistributed (const double min, const double max, const int num, std::vector< double > &res)
 calculates num uniform ditributed random variables and stores them in res More...
 
void GetUniformDistributed (const double min, const double max, const int num, double *res)
 
int GetUniformDistributedInt (const int min, const int max)
 get uniform distributed random variable including min/max More...
 
unsigned GetUniformDistributedInt (const unsigned min, const unsigned max)
 get uniform distributed random variable including min/max More...
 
long int Name2DebugLevel (const std::string &name) const
 looks up a debuglevel in the internal map, returns 0 if not found More...
 
long int NewDebugLevel (const std::string &name)
 creates a new debuglevel More...
 
void PrintDebugLevel (std::ostream &os=std::cout) const
 
 Random ()
 initializes vars/seed with deterministic values, NOT calling reset More...
 
 Random (const long int seed)
 calls Reset(seed) and therefore srand() More...
 
void RemoveDebugLevel (const long int lv)
 
void RemoveDebugLevel (const std::string &name)
 
void Reset ()
 calls srand() with a seed generated from system call time, also initializes some other variables More...
 
void Reset (const long int seed)
 calls srand with seed, also initializes some other variables More...
 
void SetDebugLevel (const long int lv)
 
void SetDebugLevel (const std::string &name)
 
void SetDebugStream (const std::ostream &os)
 
void ShowDebugLevel (std::ostream &os=std::cout) const
 prints all internally known debuglevels More...
 
 ~Random ()
 

Static Public Member Functions

static long int GetGlobalDebugLevel ()
 
static void SetGlobalDebugLevel (long int lev)
 

Protected Member Functions

long ConsumeNextFreeDebuglevel_ ()
 returns the next available debuglevel More...
 
double gasdev3_ (int *idum)
 
double gasdev_ (int *idum)
 produces normal distributed random variable with unit variance and zero mean More...
 
double gasdevf_ (long *idum)
 
double ran1_ (int *idum)
 produces uniform random variable between 0 and 1 exclusive More...
 
double ran1c_ (int *idum)
 
double ran2_ (long *idum)
 
void sobseq_ (int *n, double x[])
 Generates a sobol sequence of n dimensional 'quasi' random vectors on succesive calls. More...
 
int Uniform2Normal_ (const double src, double &dst) const
 transfroms a uniform disributed random variable into a normal distributed random variable More...
 
int Uniform2Normal_ (const double src1, const double src2, double &dst1, double &dst2) const
 Box-Muller transform generating 2 normal distributed random variables from two uniform distributed random variables. More...
 

Protected Attributes

long int _liDebugLevel
 
long int _liNextDebugLevel
 new concept, debuglevel are managed here in the debug class More...
 
std::map< std::string, long int > _String2Debuglevel
 
int Idum_
 
long LongIdum_
 
unsigned int Seed_
 

Static Protected Attributes

static std::ostream _zDebugStream
 
static long int GlobalDebugLevel = 0
 

Detailed Description

class for producing random numbers from different distributions

IMPORTANT: Problems arise when multiple of these instances are used since every call to Reset() results in a call to srand() (from stdlib) with a specific seed. Calling srand() is a global action that will affect all other instances as well

Author
woelk 2002
Examples:
EvaluateAlignment.cpp, ExampleAbsoluteOrientation.cpp, ExampleAlignment.cpp, ExampleAutoCalib.cpp, ExampleCamPoseCalib.cpp, ExampleCondensImg.cpp, ExampleEParametrization.cpp, ExampleEstimateFisheyePolynomial.cpp, ExampleExtendedKalman.cpp, ExampleFFT.cpp, ExampleFMatrix.cpp, ExampleGSL.cpp, ExampleHistogram.cpp, ExampleHomographyMapping.cpp, ExampleIEKF.cpp, ExampleKalman.cpp, ExampleLapack.cpp, ExampleLDA.cpp, ExampleLeastSquares.cpp, ExampleLineMatcher.cpp, ExamplePMatrix.cpp, ExamplePolynomialSolve.cpp, ExamplePowell.cpp, ExampleProjectionParametersPerspective2.cpp, ExampleRandom.cpp, ExampleRandom2.cpp, ExampleRandom2D.cpp, ExampleRANSAC_double.cpp, ExampleRANSACPlane.cpp, ExampleSparseMatrix2.cpp, ExampleSVD.cpp, ExampleTracker.cpp, ExampleTriangleMeshQuad.cpp, ExampleTriangulateOptimal.cpp, ExampleUncertaintyTransform.cpp, ExampleVRMLOutProjection.cpp, FMatrixTest.cpp, HMatrixTest.cpp, InvestigateEpipoleEstimation.cpp, InvestigatePRelations.cpp, PMatrixTest.cpp, and PMatrixTest2.cpp.

Definition at line 51 of file Random.hh.

Constructor & Destructor Documentation

Random::Random ( )

initializes vars/seed with deterministic values, NOT calling reset

Definition at line 69 of file Random.cpp.

References Reset().

Random::Random ( const long int  seed)

calls Reset(seed) and therefore srand()

Definition at line 82 of file Random.cpp.

References Reset().

Random::~Random ( )

Definition at line 64 of file Random.cpp.

Member Function Documentation

void BIAS::Debug::AddDebugLevel ( const long int  lv)
inlineinherited
void BIAS::Debug::AddDebugLevel ( const std::string &  name)
inlineinherited

Definition at line 362 of file Debug.hh.

long BIAS::Debug::ConsumeNextFreeDebuglevel_ ( )
inlineprotectedinherited

returns the next available debuglevel

Author
woelk 09/2006

Definition at line 521 of file Debug.hh.

bool BIAS::Debug::DebugLevelIsSet ( const long int  lv) const
inlineinherited
bool BIAS::Debug::DebugLevelIsSet ( const std::string &  name) const
inlineinherited

Definition at line 350 of file Debug.hh.

double Random::gasdev3_ ( int *  idum)
protected

Definition at line 684 of file Random.cpp.

References ran1_().

double Random::gasdev_ ( int *  idum)
protected

produces normal distributed random variable with unit variance and zero mean

Definition at line 637 of file Random.cpp.

References ran1_().

double Random::gasdevf_ ( long *  idum)
protected

Definition at line 660 of file Random.cpp.

References ran2_().

Referenced by GetNormalDistributed().

int BIAS::Debug::GetDebugLevel ( ) const
inlineinherited
std::ostream& BIAS::Debug::GetDebugStream ( ) const
inlineinherited

Definition at line 405 of file Debug.hh.

void BIAS::Debug::GetDebugStream ( std::ostream &  os) const
inlineinherited

Definition at line 414 of file Debug.hh.

static long int BIAS::Debug::GetGlobalDebugLevel ( )
inlinestaticinherited

Definition at line 431 of file Debug.hh.

void Random::GetMeanAndCovariance ( const std::vector< double > &  samples,
double &  mean,
double &  covariance 
) const

check-function to compute mean and cov from samples

Definition at line 706 of file Random.cpp.

Referenced by BIAS::MonteCarloTransform::GetSamples_().

void Random::GetMeanAndCovariance ( const std::vector< BIAS::Vector< double > > &  samples,
BIAS::Vector< double > &  mean,
BIAS::Matrix< double > &  covariance 
) const

check-function to compute mean and cov from samples

Definition at line 722 of file Random.cpp.

References TNT::Vector< T >::newsize(), TNT::Matrix< T >::newsize(), BIAS::Matrix< T >::SetZero(), TNT::Matrix< T >::size(), and TNT::Vector< T >::size().

double BIAS::Random::GetNormalDistributed ( const double  mean,
const double  sigma 
)
inline
void Random::GetNormalDistributed ( const double  mean,
const double  sigma,
const int  num,
std::vector< double > &  res 
)

calculates num normal ditributed random variables and stores them in res

Definition at line 213 of file Random.cpp.

References gasdevf_(), and LongIdum_.

int Random::GetNormalDistributed ( const Vector2< double > &  mean,
const Matrix2x2< double > &  cov,
Vector2< double > &  ran 
)

See GetNormalDistributed().

Author
woelk 07/2005

Definition at line 224 of file Random.cpp.

References GetNormalDistributed().

int Random::GetNormalDistributed ( const Vector2< double > &  mean,
const Matrix2x2< double > &  cov,
const int  num,
std::vector< Vector2< double > > &  ran 
)

Generates a vector of length num containing 2D (dependent) normal distributed random variables.

The 2D distribution is described by the covariance matrix cov.

Returns
0 on success , negative on error
Author
woelk 07/2005

Definition at line 238 of file Random.cpp.

References BIAS::Matrix2x2< T >::EigenvalueDecomposition(), and GetNormalDistributed().

void BIAS::Random::GetNormalDistributed ( const double  mean,
const double  sigma,
const int  num,
double *  res 
)
inline

old deprectade interfaces

Definition at line 157 of file Random.hh.

double Random::GetNormalDistributedGSL ( const double  mean,
const double  sigma 
)

interface to GSL for comparison purposes

Definition at line 184 of file Random.cpp.

References GetNormalDistributed().

int Random::GetQuasiNormalDistributed ( const int  dim,
Vector< double > &  res 
)

On subsequent calls returns a Sobol' sequence of quasi random numbers 'normal distributed' with mean 0 and Covariance matrix identity Input: dim - dimension of requested sequqnce, in range [1,6] Output: res - quasi random vector See GetQuasiUniformDistributed() and sobseq_() for details.

Author
woelk 11/2006

Definition at line 396 of file Random.cpp.

References GetQuasiUniformDistributed(), BIAS::Vector< T >::Size(), and Uniform2Normal_().

Referenced by BIAS::MonteCarloTransform::GetSamples_().

int Random::GetQuasiNormalDistributed ( const int  dim,
const unsigned  num,
std::vector< Vector< double > > &  res 
)

returns a quasi random seuqence of 'normal dsitributed' numbres.

Input: dim - dimension of requested sequqnce, in range [1,6] num - length of requested sequence Output: res - quasi random vector sequence See GetQuasiUniformDistributed() and sobseq_() for details.

Author
woelk 11/2006

Definition at line 425 of file Random.cpp.

References GetQuasiUniformDistributed(), and Uniform2Normal_().

int Random::GetQuasiUniformDistributed ( const int  dim,
const Vector< double > &  min,
const Vector< double > &  max,
Vector< double > &  res 
)

On subsequent calls returns a Sobol' sequence of quasi random numbers 'uniformly distributed' in a N-dimensional cube between min and max.

The dimension of the space must not exceed 6. min[i] >= max[i] must hold for all i

Author
woelk 11/2006

Definition at line 300 of file Random.cpp.

References TNT::Vector< T >::newsize(), BIAS::Vector< T >::Size(), and sobseq_().

Referenced by GetQuasiNormalDistributed(), and BIAS::MonteCarloTransform::GetSamples_().

int Random::GetQuasiUniformDistributed ( const int  dim,
const Vector< double > &  min,
const Vector< double > &  max,
const unsigned  num,
std::vector< Vector< double > > &  res 
)

Returns a Sobol' sequence of num quasi random numbers 'uniformly distributed' in the N-dimensional cube between min and max.

min[i] >= max[i] must hold for all i

Author
woelk 11/2006

Definition at line 348 of file Random.cpp.

References BIAS::Vector< T >::Size(), and sobseq_().

double BIAS::Random::GetUniformDistributed ( const double  min,
const double  max 
)
inline

on succesive calls return uniform distributed random variable between min and max

Examples:
ExampleAbsoluteOrientation.cpp, ExampleAlignment.cpp, ExampleAutoCalib.cpp, ExampleCamPoseCalib.cpp, ExampleEParametrization.cpp, ExampleEstimateFisheyePolynomial.cpp, ExampleFFT.cpp, ExampleFMatrix.cpp, ExampleGSL.cpp, ExampleHistogram.cpp, ExampleKalman.cpp, ExampleLapack.cpp, ExampleLDA.cpp, ExampleLeastSquares.cpp, ExampleLineMatcher.cpp, ExamplePMatrix.cpp, ExamplePolynomialSolve.cpp, ExamplePowell.cpp, ExampleProjectionParametersPerspective2.cpp, ExampleRandom.cpp, ExampleRandom2D.cpp, ExampleRANSAC_double.cpp, ExampleRANSACPlane.cpp, ExampleSparseMatrix2.cpp, ExampleSVD.cpp, ExampleTracker.cpp, ExampleTriangleMeshQuad.cpp, ExampleTriangulateOptimal.cpp, ExampleUncertaintyTransform.cpp, FMatrixTest.cpp, InvestigateEpipoleEstimation.cpp, InvestigatePRelations.cpp, PMatrixTest.cpp, and PMatrixTest2.cpp.

Definition at line 84 of file Random.hh.

Referenced by BIAS::GenSynthMatches::_AddUniformDistributedOutliers(), BIAS::GenSynthMatches::_CreateCamMovement(), BIAS::GenSynthMatches::_CreateMoving3DPoints(), BIAS::GenSynthMatches::_CreateStatic3DPoints(), BIAS::TrackerSynth< StorageType, CalculationType >::AddOutlier_(), BIAS::GenGroundTruth::CreateIdealMatches(), BIAS::GenGroundTruth::CreateMatches(), BIAS::GenGroundTruth::CreateMatchesOutlier(), BIAS::GenSynthMatches::CreateMoving3DPoint(), BIAS::GenSynthMatches::CreateStatic3DPoint(), BIAS::GenGroundTruth::GenerateRandomCube(), BIAS::GenerateRandomData(), BIAS::LDA::GenerateRandomTestData(), BIAS::MonteCarloTransform::GetSamples_(), GetUniformDistributedInt(), BIAS::Condensation::PickImportanceSample_(), BIAS::Condensation::PickOneSample_(), BIAS::NurbsSurface::SetCTRLPointsToRandom(), and BIAS::BackwardMapping< InputStorageType, OutputStorageType >::UpdatePyramidSize().

void Random::GetUniformDistributed ( const double  min,
const double  max,
const int  num,
std::vector< double > &  res 
)

calculates num uniform ditributed random variables and stores them in res

Definition at line 174 of file Random.cpp.

References LongIdum_, and ran2_().

void BIAS::Random::GetUniformDistributed ( const double  min,
const double  max,
const int  num,
double *  res 
)
inline

Definition at line 166 of file Random.hh.

int Random::GetUniformDistributedInt ( const int  min,
const int  max 
)
unsigned int Random::GetUniformDistributedInt ( const unsigned  min,
const unsigned  max 
)

get uniform distributed random variable including min/max

Definition at line 157 of file Random.cpp.

References GetUniformDistributed().

long int BIAS::Debug::Name2DebugLevel ( const std::string &  name) const
inlineinherited

looks up a debuglevel in the internal map, returns 0 if not found

Author
woelk 09/2006

Definition at line 454 of file Debug.hh.

long int BIAS::Debug::NewDebugLevel ( const std::string &  name)
inlineinherited
void BIAS::Debug::PrintDebugLevel ( std::ostream &  os = std::cout) const
inlineinherited

Definition at line 383 of file Debug.hh.

double Random::ran1_ ( int *  idum)
protected

produces uniform random variable between 0 and 1 exclusive

Definition at line 503 of file Random.cpp.

Referenced by gasdev3_(), and gasdev_().

double Random::ran1c_ ( int *  idum)
protected

Definition at line 554 of file Random.cpp.

double Random::ran2_ ( long *  idum)
protected

Definition at line 603 of file Random.cpp.

Referenced by gasdevf_(), and GetUniformDistributed().

void BIAS::Debug::RemoveDebugLevel ( const long int  lv)
inlineinherited

Definition at line 369 of file Debug.hh.

void BIAS::Debug::RemoveDebugLevel ( const std::string &  name)
inlineinherited

Definition at line 376 of file Debug.hh.

void Random::Reset ( )

calls srand() with a seed generated from system call time, also initializes some other variables

Examples:
ExampleAbsoluteOrientation.cpp, ExampleExtendedKalman.cpp, and ExampleRandom2D.cpp.

Definition at line 113 of file Random.cpp.

References Idum_, LongIdum_, and Seed_.

Referenced by BIAS::AbsoluteOrientationRANSAC::AbsoluteOrientationRANSAC(), BIAS::LDA::GenerateRandomTestData(), Random(), BIAS::GenSynthMatches::Reset(), and BIAS::NurbsSurface::SetCTRLPointsToRandom().

void Random::Reset ( const long int  seed)

calls srand with seed, also initializes some other variables

Definition at line 92 of file Random.cpp.

References Idum_, LongIdum_, and Seed_.

void BIAS::Debug::SetDebugLevel ( const long int  lv)
inlineinherited
void BIAS::Debug::SetDebugLevel ( const std::string &  name)
inlineinherited

Definition at line 325 of file Debug.hh.

void BIAS::Debug::SetDebugStream ( const std::ostream &  os)
inlineinherited

Definition at line 398 of file Debug.hh.

static void BIAS::Debug::SetGlobalDebugLevel ( long int  lev)
inlinestaticinherited

Definition at line 424 of file Debug.hh.

void BIAS::Debug::ShowDebugLevel ( std::ostream &  os = std::cout) const
inlineinherited

prints all internally known debuglevels

Author
woelk 09/2006

Definition at line 496 of file Debug.hh.

void Random::sobseq_ ( int *  n,
double  x[] 
)
protected

Generates a sobol sequence of n dimensional 'quasi' random vectors on succesive calls.

When n is negative, internally intializes a set of MAXBIT=6 direction numbers for each MAXDIM different Sobol' sequences. When n is positive (but <=MAXDIM), returns as thevector x[0..n-1] the next values from n of theses sequneces. (n must not be changed between initializations. ) See Press, "Numerical Recipes in C", Chapter 7.7, p. 312 http://www.nrbook.com/a/bookcpdf.html

Author
woelk 11/2006

Definition at line 747 of file Random.cpp.

Referenced by GetQuasiUniformDistributed().

int Random::Uniform2Normal_ ( const double  src,
double &  dst 
) const
protected

transfroms a uniform disributed random variable into a normal distributed random variable

The algiorithm is based on the inversion Principle, see L. Devroye "Non-Uniform Random Variate Generation", 1986, Springer, chapter II.2 for details

Input: src - uniform deviat in range [-1.0, +1.0] Output: dst - normal distributed deviate

returns 0 on success -1 when src is out of bounds

Author
woelk 11/2006

Definition at line 456 of file Random.cpp.

Referenced by GetQuasiNormalDistributed().

int Random::Uniform2Normal_ ( const double  src1,
const double  src2,
double &  dst1,
double &  dst2 
) const
protected

Box-Muller transform generating 2 normal distributed random variables from two uniform distributed random variables.

Input: src1, src2 - uniform deviate in range [-1, +1] with src1*src1+src2*src2<1.0 and src1*src1+src2*src2!=0.0 Output: dst1, dst2 - normal deviates with sigma 1

returns 0 on success, -2 when src1 or src2 out of bounds -1 either src1*src1+src2*src2>=1.0 or rc1*src1+src2*src2 == 0.0

See Press, "Numerical Recipes in C", Chapter 7, p. 289 http://www.nrbook.com/a/bookcpdf.html for details.

Author
woelk 11/2006

Definition at line 477 of file Random.cpp.

Member Data Documentation

long int BIAS::Debug::_liDebugLevel
protectedinherited

Definition at line 510 of file Debug.hh.

Referenced by BIAS::Debug::operator=(), and BIAS::ImageBase::operator=().

long int BIAS::Debug::_liNextDebugLevel
protectedinherited

new concept, debuglevel are managed here in the debug class

Definition at line 516 of file Debug.hh.

Referenced by BIAS::Debug::operator=().

std::map<std::string, long int> BIAS::Debug::_String2Debuglevel
protectedinherited

Definition at line 517 of file Debug.hh.

Referenced by BIAS::Debug::operator=().

std::ostream BIAS::Debug::_zDebugStream
staticprotectedinherited

Definition at line 511 of file Debug.hh.

Referenced by BIAS::Debug::operator=().

long int BIAS::Debug::GlobalDebugLevel = 0
staticprotectedinherited

Definition at line 513 of file Debug.hh.

int BIAS::Random::Idum_
protected

Definition at line 187 of file Random.hh.

Referenced by Reset().

long BIAS::Random::LongIdum_
protected

Definition at line 188 of file Random.hh.

Referenced by GetNormalDistributed(), GetUniformDistributed(), and Reset().

unsigned int BIAS::Random::Seed_
protected

Definition at line 186 of file Random.hh.

Referenced by Reset().


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