Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
vpGaussRand Class Reference

#include <visp3/core/vpGaussRand.h>

+ Inheritance diagram for vpGaussRand:

Public Member Functions

 vpGaussRand ()
 
 vpGaussRand (const double sigma_val, const double mean_val, const long noise_seed=0)
 
void setSigmaMean (const double sigma_val, const double mean_val)
 
void seed (const long seed_val)
 
double operator() ()
 

Protected Member Functions

double draw1 ()
 

Protected Attributes

long x
 

Detailed Description

Class for generating random number with normal probability density.

The algorithms and notations used are described in [14].

The code below shows how to use the random generator to get values that have their mean equal to 10 with a standart deviation equal to 0.5.

#include <iostream>
#include <visp3/core/vpGaussRand.h>
int main()
{
vpGaussRand noise(0.5, 10);
for(int i=0; i< 10; i++) {
std::cout << "noise " << i << ": " << noise() << std::endl;
}
return 0;
}

The previous example produces the following printings:

noise 0: 9.43873
noise 1: 10.1977
noise 2: 10.8145
noise 3: 9.13729
noise 4: 8.86476
noise 5: 9.83382
noise 6: 9.43609
noise 7: 9.34311
noise 8: 9.62742
noise 9: 9.37701

Note that the previous example produces always the same "random" results. To produce real random values, you need to initialize the random generator with different values using seed(). For example, this could be done using the current time. The code becomes:

#include <iostream>
#include <visp3/core/vpGaussRand.h>
#include <visp3/core/vpTime.h>
int main()
{
vpGaussRand noise(0.5, 10);
long seed = (long)vpTime::measureTimeMs();
noise.seed(seed);
for(int i=0; i< 10; i++) {
std::cout << "noise " << i << ": " << noise() << std::endl;
}
return 0;
}

Now if you run the previous example you will always get different values:

noise 0: 10.5982
noise 1: 9.19111
noise 2: 9.82498
noise 3: 9.07857
noise 4: 9.9285
noise 5: 10.3688
noise 6: 9.75621
noise 7: 10.3259
noise 8: 10.4238
noise 9: 10.2391
Examples:
testColVector.cpp, testPoseRansac2.cpp, and testTukeyEstimator.cpp.

Definition at line 120 of file vpGaussRand.h.

Constructor & Destructor Documentation

vpGaussRand::vpGaussRand ( )
inline

Default noise generator constructor.

Definition at line 131 of file vpGaussRand.h.

vpGaussRand::vpGaussRand ( const double  sigma_val,
const double  mean_val,
const long  noise_seed = 0 
)
inline

Gaussian noise random generator constructor.

Parameters
sigma_val: Standard deviation.
mean_val: Mean value.
noise_seed: Seed of the noise

Definition at line 140 of file vpGaussRand.h.

Member Function Documentation

double vpUniRand::draw1 ( )
protectedinherited

Bays-Durham Shuffling of Park-Miller generator.

Minimal random number generator of Park and Miller with Bays-Durham shuffle. Returns a uniform random deviate between 0.0 and 1.0 (exclusive of the endpoint values).

Definition at line 62 of file vpUniRand.cpp.

References vpUniRand::x.

double vpGaussRand::operator() ( )
inline

Return a random value from the Gaussian noise generator.

Definition at line 167 of file vpGaussRand.h.

void vpGaussRand::seed ( const long  seed_val)
inline

Set the seed of the noise.

Parameters
seed_val: New seed.
Examples:
testTukeyEstimator.cpp.

Definition at line 162 of file vpGaussRand.h.

void vpGaussRand::setSigmaMean ( const double  sigma_val,
const double  mean_val 
)
inline

Set the standard deviation and mean for gaussian noise.

Parameters
sigma_val: New standard deviation sigma.
mean_val: New mean value.

Definition at line 151 of file vpGaussRand.h.

Member Data Documentation

long vpUniRand::x
protectedinherited

Definition at line 78 of file vpUniRand.h.

Referenced by vpUniRand::draw1().