g2o
Static Public Member Functions | List of all members
g2o::Sampler Class Reference

#include <sampler.h>

Static Public Member Functions

static double gaussRand (double mean, double sigma)
 
static double uniformRand (double lowerBndr, double upperBndr)
 
static void seedRand ()
 
static void seedRand (unsigned int seed)
 

Detailed Description

Definition at line 79 of file sampler.h.

Member Function Documentation

static double g2o::Sampler::gaussRand ( double  mean,
double  sigma 
)
inlinestatic

Gaussian random with a mean and standard deviation. Uses the Polar method of Marsaglia.

Definition at line 86 of file sampler.h.

Referenced by main().

87  {
88  double x, y, r2;
89  do {
90  x = -1.0 + 2.0 * uniformRand(0.0, 1.0);
91  y = -1.0 + 2.0 * uniformRand(0.0, 1.0);
92  r2 = x * x + y * y;
93  } while (r2 > 1.0 || r2 == 0.0);
94  return mean + sigma * y * std::sqrt(-2.0 * log(r2) / r2);
95  }
static double uniformRand(double lowerBndr, double upperBndr)
Definition: sampler.h:100
static void g2o::Sampler::seedRand ( )
inlinestatic

default seed function using the current time in seconds

Definition at line 107 of file sampler.h.

Referenced by main().

108  {
109  seedRand(static_cast<unsigned int>(std::time(NULL)));
110  }
static void seedRand()
Definition: sampler.h:107
static void g2o::Sampler::seedRand ( unsigned int  seed)
inlinestatic

seed the random number generator

Definition at line 113 of file sampler.h.

114  {
115  std::srand(seed);
116  }
static double g2o::Sampler::uniformRand ( double  lowerBndr,
double  upperBndr 
)
inlinestatic

sample a number from a uniform distribution

Definition at line 100 of file sampler.h.

Referenced by main().

101  {
102  return lowerBndr + ((double) std::rand() / (RAND_MAX + 1.0)) * (upperBndr - lowerBndr);
103  }

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