Basic Image AlgorithmS Library
2.8.0
|
class for producing random numbers from different distributions More...
#include <Base/Math/Random.hh>
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 |
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
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.
|
inlineinherited |
Definition at line 355 of file Debug.hh.
Referenced by BIAS::GLProjectionParametersBase::AddDebugLevel(), BIAS::Triangulation::CorrectCorrespondences(), BIAS::FilterBase< InputStorageType, OutputStorageType >::FilterBase(), BIAS::ShowCamWxVideoSourceFactory::OpenDevice(), and BIAS::SceneOpenSceneGraph::SceneOpenSceneGraph().
|
inlineinherited |
|
inlineprotectedinherited |
|
inlineinherited |
Definition at line 341 of file Debug.hh.
Referenced by BIAS::GenSynthMatches::_AddUniformDistributedOutliers(), BIAS::GenSynthMatches::_CreateCamMovement(), BIAS::GenSynthMatches::_CreateStatic2DPoints(), BIAS::UnscentedTransform::ComputeSigmaPoints_(), BIAS::Triangulation::CorrectCorrespondences(), BIAS::GenSynthMatches::GetGTNormalizedF(), BIAS::MonteCarloTransform::GetSamples_(), and BIAS::MonteCarloTransform::Transform().
|
inlineinherited |
|
protected |
Definition at line 684 of file Random.cpp.
References ran1_().
|
protected |
produces normal distributed random variable with unit variance and zero mean
Definition at line 637 of file Random.cpp.
References ran1_().
|
protected |
Definition at line 660 of file Random.cpp.
References ran2_().
Referenced by GetNormalDistributed().
|
inlineinherited |
Definition at line 332 of file Debug.hh.
Referenced by BIAS::listenthread(), BIAS::Image< StorageType >::operator=(), and BIAS::ImageBase::operator=().
|
inlineinherited |
|
inlineinherited |
|
inlinestaticinherited |
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().
|
inline |
on succesive calls return normal distributed random variable with mean and standard deviation sigma
Definition at line 71 of file Random.hh.
Referenced by BIAS::GenSynthMatches::_AddUniformDistributedOutliers(), BIAS::GenSynthMatches::_CreateCamMovement(), BIAS::GenSynthMatches::_CreateMoving2DPoints(), BIAS::GenSynthMatches::_CreateStatic2DPoints(), BIAS::TrackerSynth< StorageType, CalculationType >::AddGaussianNoise_(), BIAS::PMDImageProc::AddNoiseToDepthImage(), BIAS::GenGroundTruth::CreateMatches(), BIAS::GenerateRandomData(), BIAS::LDA::GenerateRandomTestData(), BIAS::Triangulation::GetCovariance(), GetNormalDistributed(), GetNormalDistributedGSL(), and BIAS::MonteCarloTransform::GetSamples_().
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 | ||
) |
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.
Definition at line 238 of file Random.cpp.
References BIAS::Matrix2x2< T >::EigenvalueDecomposition(), and GetNormalDistributed().
|
inline |
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.
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.
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
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
Definition at line 348 of file Random.cpp.
References BIAS::Vector< T >::Size(), and sobseq_().
|
inline |
on succesive calls return uniform distributed random variable between min and max
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.
|
inline |
int Random::GetUniformDistributedInt | ( | const int | min, |
const int | max | ||
) |
get uniform distributed random variable including min/max
Definition at line 139 of file Random.cpp.
Referenced by BIAS::MSAC< SolutionType >::_GenerateSamplesRandom(), BIAS::TrackerSynth< StorageType, CalculationType >::AddOutlier_(), BIAS::JointHistogram< StorageType >::ComputeParzenWindow(), BIAS::GenerateRandomData(), BIAS::LDA::GenerateRandomTestData(), BIAS::RANSAC< SolutionType >::GenerateSamplesRandom(), and BIAS::RANSACEvaluatorInterface< SolutionType >::GenerateSamplesRandom_().
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().
|
inlineinherited |
|
inlineinherited |
creates a new debuglevel
Definition at line 474 of file Debug.hh.
Referenced by BIAS::COSAC< SolutionType >::COSAC(), BIAS::ProjectionParametersPerspectiveDepth::Init(), BIAS::MonteCarloTransform::MonteCarloTransform(), BIAS::PMatrixEstimation::PMatrixEstimation(), BIAS::PreemptiveRANSAC< SolutionType >::PreemptiveRANSAC(), BIAS::RANSACPreKnowledge< SolutionType >::RANSACPreKnowledge(), BIAS::ROI::ROI(), BIAS::RotationAveraging::RotationAveraging(), BIAS::SceneOpenSceneGraph::SceneOpenSceneGraph(), BIAS::ThreeDOutOpenSceneGraph::ThreeDOutOpenSceneGraph(), BIAS::Triangulation::Triangulation(), and BIAS::UnscentedTransform::UnscentedTransform().
|
inlineinherited |
|
protected |
produces uniform random variable between 0 and 1 exclusive
Definition at line 503 of file Random.cpp.
Referenced by gasdev3_(), and gasdev_().
|
protected |
Definition at line 554 of file Random.cpp.
|
protected |
Definition at line 603 of file Random.cpp.
Referenced by gasdevf_(), and GetUniformDistributed().
|
inlineinherited |
|
inlineinherited |
void Random::Reset | ( | ) |
calls srand() with a seed generated from system call time, also initializes some other variables
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.
|
inlineinherited |
Definition at line 318 of file Debug.hh.
Referenced by BIAS::ShowCamWxVideoSourceFactory::CreateBumbleBee(), BIAS::ShowCamWxVideoSourceFactory::CreateDCAM(), BIAS::VideoSource_MDcam::ScanBus(), BIAS::GLProjectionParametersBase::SetDebugLevel(), BIAS::VideoSource_Disk::VideoSource_Disk(), BIAS::VideoSource_DV2::VideoSource_DV2(), BIAS::VideoSource_DV::VideoSource_DV_Internal_Init_(), and BIAS::VideoSource_V4L::VideoSource_V4L().
|
inlineinherited |
|
inlineinherited |
|
inlinestaticinherited |
|
inlineinherited |
|
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
Definition at line 747 of file Random.cpp.
Referenced by GetQuasiUniformDistributed().
|
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
Definition at line 456 of file Random.cpp.
Referenced by GetQuasiNormalDistributed().
|
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.
Definition at line 477 of file Random.cpp.
|
protectedinherited |
Definition at line 510 of file Debug.hh.
Referenced by BIAS::Debug::operator=(), and BIAS::ImageBase::operator=().
|
protectedinherited |
new concept, debuglevel are managed here in the debug class
Definition at line 516 of file Debug.hh.
Referenced by BIAS::Debug::operator=().
|
protectedinherited |
Definition at line 517 of file Debug.hh.
Referenced by BIAS::Debug::operator=().
|
staticprotectedinherited |
Definition at line 511 of file Debug.hh.
Referenced by BIAS::Debug::operator=().
|
staticprotectedinherited |
|
protected |
Definition at line 188 of file Random.hh.
Referenced by GetNormalDistributed(), GetUniformDistributed(), and Reset().
|
protected |