src/core/random-variable.h
changeset 360 7bffd987426c
parent 346 4a76f247e7dc
child 364 9df87117d468
equal deleted inserted replaced
359:91b7ad7fa784 360:7bffd987426c
    86    * \brief Constructor for a random number generator with a random seed.
    86    * \brief Constructor for a random number generator with a random seed.
    87    */
    87    */
    88   RandomVariable();
    88   RandomVariable();
    89   
    89   
    90   /**
    90   /**
       
    91    * \brief Copy constructor
       
    92    */  
       
    93   RandomVariable(const RandomVariable&);
       
    94   
       
    95   /**
    91    * \brief Destructor for a random number generator with a random seed.
    96    * \brief Destructor for a random number generator with a random seed.
    92    */
    97    */
    93   virtual ~RandomVariable();
    98   virtual ~RandomVariable();
    94   
    99   
    95   /**
   100   /**
   143    */
   148    */
   144   static  void UseDevRandom(bool udr = true);
   149   static  void UseDevRandom(bool udr = true);
   145 
   150 
   146    /**
   151    /**
   147    * \brief Use the global seed to force precisely reproducible results.
   152    * \brief Use the global seed to force precisely reproducible results.
       
   153    *
   148    * It is often desirable to create a simulation that uses random
   154    * It is often desirable to create a simulation that uses random
   149    * numbers, while at the same time is completely reproducible.
   155    * numbers, while at the same time is completely reproducible.
   150    * Specifying this set of six random seeds initializes the
   156    * Specifying this set of six random seeds initializes the
   151    * random number generator with the specified seed.
   157    * random number generator with the specified seed.
   152    * Once this is set, all generators will produce fixed output
   158    * Once this is set, all generators will produce fixed output
   208   double m_max;
   214   double m_max;
   209 };
   215 };
   210 
   216 
   211 /**
   217 /**
   212  * \brief A random variable that returns a constant
   218  * \brief A random variable that returns a constant
       
   219  *
   213  * Class ConstantVariable defines a random number generator that
   220  * Class ConstantVariable defines a random number generator that
   214  * returns the same value every sample.
   221  * returns the same value every sample.
   215  */
   222  */
   216 class ConstantVariable : public RandomVariable { 
   223 class ConstantVariable : public RandomVariable { 
   217 
   224 
   218 public:
   225 public:
   219   /**
   226   /**
   220    * \brief Construct a ConstantVariable RNG that returns zero every sample
   227    * Construct a ConstantVariable RNG that returns zero every sample
   221    */
   228    */
   222   ConstantVariable();
   229   ConstantVariable();
   223   
   230   
   224   /**
   231   /**
   225    * Construct a ConstantVariable RNG that returns the specified value
   232    * Construct a ConstantVariable RNG that returns the specified value
   247   double m_const;
   254   double m_const;
   248 };
   255 };
   249 
   256 
   250 /**
   257 /**
   251  * \brief Return a sequential list of values
   258  * \brief Return a sequential list of values
       
   259  *
   252  * Class SequentialVariable defines a random number generator that
   260  * Class SequentialVariable defines a random number generator that
   253  * returns a sequential sequence.  The sequence monotonically
   261  * returns a sequential sequence.  The sequence monotonically
   254  * increases for a period, then wraps around to the low value 
   262  * increases for a period, then wraps around to the low value 
   255  * and begins monotonicaly increasing again.
   263  * and begins monotonicaly increasing again.
   256  */
   264  */
   257 class SequentialVariable : public RandomVariable {
   265 class SequentialVariable : public RandomVariable {
   258 
   266 
   259 public:
   267 public:
   260   /**
   268   /**
   261    * \brief Constructor for the SequentialVariable RNG.
   269    * \brief Constructor for the SequentialVariable RNG.
       
   270    *
   262    * The four parameters define the sequence.  For example
   271    * The four parameters define the sequence.  For example
   263    * SequentialVariable(0,5,1,2) creates a RNG that has the sequence
   272    * SequentialVariable(0,5,1,2) creates a RNG that has the sequence
   264    * 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, 0 ...
   273    * 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, 0 ...
   265    * \param f First value of the sequence.
   274    * \param f First value of the sequence.
   266    * \param l One more than the last value of the sequence.
   275    * \param l One more than the last value of the sequence.
   269    */
   278    */
   270   SequentialVariable(double f, double l, double i = 1, uint32_t c = 1);
   279   SequentialVariable(double f, double l, double i = 1, uint32_t c = 1);
   271 
   280 
   272   /**
   281   /**
   273    * \brief Constructor for the SequentialVariable RNG.
   282    * \brief Constructor for the SequentialVariable RNG.
       
   283    *
   274    * Differs from the first only in that the increment parameter is a
   284    * Differs from the first only in that the increment parameter is a
   275    * random variable
   285    * random variable
   276    * \param f First value of the sequence.
   286    * \param f First value of the sequence.
   277    * \param l One more than the last value of the sequence.
   287    * \param l One more than the last value of the sequence.
   278    * \param i Reference to a Random variable for the sequence increment
   288    * \param i Reference to a RandomVariable for the sequence increment
   279    * \param c Number of times each member of the sequence is repeated
   289    * \param c Number of times each member of the sequence is repeated
   280    */
   290    */
   281   SequentialVariable(double f, double l, const RandomVariable& i, uint32_t c = 1);
   291   SequentialVariable(double f, double l, const RandomVariable& i, uint32_t c = 1);
   282 
   292 
   283   SequentialVariable(const SequentialVariable& c);
   293   SequentialVariable(const SequentialVariable& c);
       
   294   
       
   295   ~SequentialVariable();
   284   /**
   296   /**
   285    * \return The next value in the Sequence
   297    * \return The next value in the Sequence
   286    */
   298    */
   287   virtual double GetValue();
   299   virtual double GetValue();
   288   virtual RandomVariable*  Copy() const;
   300   virtual RandomVariable*  Copy() const;
   295   uint32_t  m_currentConsecutive;
   307   uint32_t  m_currentConsecutive;
   296 };
   308 };
   297 
   309 
   298 /**
   310 /**
   299  * \brief Exponentially Distributed random var
   311  * \brief Exponentially Distributed random var
       
   312  *
   300  * ExponentialVariable defines a random variable with an exponential distribution
   313  * ExponentialVariable defines a random variable with an exponential distribution
   301  */
   314  */
   302 class ExponentialVariable : public RandomVariable { 
   315 class ExponentialVariable : public RandomVariable { 
   303 public:
   316 public:
   304   /**
   317   /**
   314   explicit ExponentialVariable(double m);
   327   explicit ExponentialVariable(double m);
   315 
   328 
   316   /**
   329   /**
   317    * \brief Constructs an exponential random variable with spefified
   330    * \brief Constructs an exponential random variable with spefified
   318    * \brief mean and upper limit.
   331    * \brief mean and upper limit.
       
   332    *
   319    * Since exponential distributions can theoretically return unbounded values,
   333    * Since exponential distributions can theoretically return unbounded values,
   320    * it is sometimes useful to specify a fixed upper limit.  Note however when
   334    * it is sometimes useful to specify a fixed upper limit.  Note however when
   321    * the upper limit is specified, the true mean of the distribution is 
   335    * the upper limit is specified, the true mean of the distribution is 
   322    * slightly smaller than the mean value specified.
   336    * slightly smaller than the mean value specified.
   323    * \param m Mean value of the random variable
   337    * \param m Mean value of the random variable
   490   double    cdf;
   504   double    cdf;
   491 };
   505 };
   492 
   506 
   493 /**
   507 /**
   494  * \brief EmpiricalVariable distribution random var
   508  * \brief EmpiricalVariable distribution random var
       
   509  *
   495  * Defines a random variable  that has a specified, empirical 
   510  * Defines a random variable  that has a specified, empirical 
   496  * distribution.  The distribution is specified by a
   511  * distribution.  The distribution is specified by a
   497  * series of calls the the CDF member function, specifying a
   512  * series of calls the the CDF member function, specifying a
   498  * value and the probability that the function value is less than
   513  * value and the probability that the function value is less than
   499  * the specified value.  When values are requested,
   514  * the specified value.  When values are requested,
   529   std::vector<ValueCDF> emp;       // Empicical CDF
   544   std::vector<ValueCDF> emp;       // Empicical CDF
   530 };
   545 };
   531 
   546 
   532 /**
   547 /**
   533  * Defines an empirical distribution where all values are integers.
   548  * Defines an empirical distribution where all values are integers.
   534  * Indentical to {\tt EmpiricalVariable}, but with slightly different
   549  * Indentical to EmpiricalVariable, but with slightly different
   535  * interpolation between points.
   550  * interpolation between points.
   536  */
   551  */
   537 class IntEmpiricalVariable : public EmpiricalVariable {
   552 class IntEmpiricalVariable : public EmpiricalVariable {
   538 public:
   553 public:
   539 
   554 
   540   IntEmpiricalVariable();
   555   IntEmpiricalVariable();
   541 
   556   
   542   virtual RandomVariable* Copy() const;
   557   virtual RandomVariable* Copy() const;
   543   /**
   558   /**
   544    * \return An integer value from this empirical distribution
   559    * \return An integer value from this empirical distribution
   545    */
   560    */
   546   virtual uint32_t GetIntValue();
   561   virtual uint32_t GetIntValue();
   556 class DeterministicVariable : public RandomVariable {
   571 class DeterministicVariable : public RandomVariable {
   557 
   572 
   558 public:
   573 public:
   559   /**
   574   /**
   560    * \brief Constructor
   575    * \brief Constructor
       
   576    *
   561    * Creates a generator that returns successive elements of the d array
   577    * Creates a generator that returns successive elements of the d array
   562    * on successive calls to ::Value().  Note that the d pointer is copied
   578    * on successive calls to ::Value().  Note that the d pointer is copied
   563    * for use by the generator (shallow-copy), not its contents, so the 
   579    * for use by the generator (shallow-copy), not its contents, so the 
   564    * contents of the array d points to have to remain unchanged for the use 
   580    * contents of the array d points to have to remain unchanged for the use 
   565    * of DeterministicVariable to be meaningful.
   581    * of DeterministicVariable to be meaningful.