Loading...
Searching...
No Matches
casacore::Random Class Referenceabstract
casa package (libcasa_casa) » BasicMath_module

Base class for random number distributions. More...

`#include <Random.h>`

## Public Types

enum | Types { BINOMIAL , DISCRETEUNIFORM , ERLANG , GEOMETRIC , HYPERGEOMETRIC , NORMAL , LOGNORMAL , NEGATIVEEXPONENTIAL , POISSON , UNIFORM , WEIBULL , UNKNOWN , NUMBER_TYPES }
| This enumerator lists all the predefined random number distributions. More...

## Public Member Functions

virtual | ~Random ()
| A virtual destructor is needed to ensure that the destructor of derived classes gets used.
virtual Double | operator() ()=0
| This function returns a random number from the appropriate distribution.
RNG * | generator ()
| Functions that allow you to access and change the class that generates the random bits.
void | generator (RNG *p)
virtual void | setParameters (const Vector< Double > &parms)=0
| These function allow you to manipulate the parameters (mean variance etc.) of random number distribution.
virtual Vector< Double > | parameters () const =0
virtual Bool | checkParameters (const Vector< Double > &parms) const =0

## Static Public Member Functions

static String | asString (Random::Types type)
| Convert the enumerator to a lower-case string.
static Random::Types | asType (const String &str)
| Convert the string to enumerator.
static Random * | construct (Random::Types type, RNG *gen)
| Convert the Random::Type enumerator to a specific object (derived from Random but upcast to a Random object).
static Vector< Double > | defaultParameters (Random::Types type)
| returns the default parameters for the specified distribution.

## Protected Member Functions

| Random (RNG *generator)

## Protected Attributes

RNG * | itsRNG

## Detailed Description

Base class for random number distributions.

### Intended use:

Public interface

### Review Status

Reviewed By:
  UNKNOWN
Date Reviewed:
  before2004/08/25

### Prerequisite

- A knowledge of C++, in particular inheritance
- College level mathematics

### Synopsis

A random number generator may be declared by first constructing a RNG object and then a Random. For example,

ACG gen(10, 20);
NegativeExpntl rnd (1.0, &gen);
casacore::ACG
Additive number generator.
Definition Random.h:222
casacore::NegativeExpntl
Negative exponential distribution.
Definition Random.h:1138

declares an additive congruential generator with seed 10 and table size 20, that is used to generate exponentially distributed values with mean of 1.0.

The virtual member Random::operator() is the common way of extracting a random number from a particular distribution. The base class, Random does not implement operator(). This is performed by each of the derived classes. Thus, given the above declaration of rnd, new random values may be obtained via, for example, Double nextExpRand = rnd();

Currently, the following subclasses are provided:

- Binomial
- Erlang
- Geometric
- HyperGeometric
- NegativeExpntl
- Normal
- LogNormal
- Poisson
- DiscreteUniform
- Uniform
- Weibull

### Example

### Thrown Exceptions

- No exceptions are thrown directly from this class.

### To Do

- Nothing I hope!

Definition at line 424 of file Random.h.

## Member Enumeration Documentation

## Types

enum casacore::Random::Types

This enumerator lists all the predefined random number distributions.

Enumerator
BINOMIAL | 2 parameters. The binomial distribution models successfully drawing items from a pool. Specify n and p. n is the number of items in the pool, and p, is the probability of each item being successfully drawn. It is required that n > 0 and 0 <= p <= 1
DISCRETEUNIFORM | 2 parameters. Model a uniform random variable over the closed interval. Specify the values low and high. The low parameter is the lowest possible return value and the high parameter is the highest. It is required that low < high.
ERLANG | 2 parameters, mean and variance. It is required that the mean is non-zero and the variance is positive.
GEOMETRIC | 1 parameters, the mean. It is required that 0 <= probability < 1
HYPERGEOMETRIC | 2 parameters, mean and variance. It is required that the variance is positive and that the mean is non-zero and not bigger than the square-root of the variance.
NORMAL | 2 parameters, the mean and variance. It is required that the variance is positive.
LOGNORMAL | 2 parameters, mean and variance. It is required that the supplied variance is positive and that the mean is non-zero
NEGATIVEEXPONENTIAL | 1 parameter, the mean.
POISSON | 1 parameter, the mean. It is required that the mean is non-negative
UNIFORM | 2 parameters, low and high. Model a uniform random variable over the closed interval. The low parameter is the lowest possible return value and the high parameter can never be returned. It is required that low < high.
WEIBULL | 2 parameters, alpha and beta. It is required that the alpha parameter is not zero.
UNKNOWN | An non-predefined random number distribution.
NUMBER_TYPES | Number of distributions.

Definition at line 428 of file Random.h.

## Constructor & Destructor Documentation

## ~Random()

virtual casacore::Random::~Random | ( |  | ) |

virtual

A virtual destructor is needed to ensure that the destructor of derived classes gets used.

Not that this destructor does NOT delete the pointer to the RNG object

## Random()

casacore::Random::Random | ( | RNG * | generator | ) |

inline protected

Definition at line 537 of file Random.h.

References itsRNG.

Referenced by construct(), casacore::Erlang::Erlang(), and casacore::HyperGeometric::HyperGeometric().

## Member Function Documentation

## asString()

String casacore::Random::asString | ( | Random::Types | type | ) |

static

Convert the enumerator to a lower-case string.

## asType()

Random::Types casacore::Random::asType | ( | const String & | str | ) |

static

Convert the string to enumerator.

The parsing of the string is case insensitive. Returns the Random::UNKNOWN value if the string does not cotrtrespond to any of the enumerators.

## checkParameters()

virtual Bool casacore::Random::checkParameters | ( | const Vector< Double > & | parms | ) | const

pure virtual

Implemented in casacore::Binomial, casacore::DiscreteUniform, casacore::Erlang, casacore::Geometric, casacore::HyperGeometric, casacore::LogNormal, casacore::NegativeExpntl, casacore::Normal, casacore::Poisson, casacore::Uniform, and casacore::Weibull.

## construct()

Random * casacore::Random::construct | ( | Random::Types | type,
|  | RNG * | gen )

static

Convert the Random::Type enumerator to a specific object (derived from Random but upcast to a Random object).

Returns a null pointer if the object could not be constructed. This will occur is the enumerator is UNKNOWN or NUMBER_TYPES or there is insufficient memory. The caller of this function is responsible for deleting the pointer.

References Random().

## defaultParameters()

Vector< Double > casacore::Random::defaultParameters | ( | Random::Types | type | ) |

static

returns the default parameters for the specified distribution.

Returns an empty Vector if a non-predifined distribution is used.

References generator().

## generator() [1/2]

RNG * casacore::Random::generator | ( |  | ) |

inline

Functions that allow you to access and change the class that generates the random bits.

Definition at line 542 of file Random.h.

References itsRNG.

Referenced by defaultParameters().

## generator() [2/2]

void casacore::Random::generator | ( | RNG * | p | ) |

inline

Definition at line 547 of file Random.h.

References itsRNG.

## operator()()

virtual Double casacore::Random::operator() | ( |  | ) |

pure virtual

This function returns a random number from the appropriate distribution.

Implemented in casacore::Binomial, casacore::DiscreteUniform, casacore::Erlang, casacore::Geometric, casacore::HyperGeometric, casacore::LogNormal, casacore::NegativeExpntl, casacore::Normal, casacore::Poisson, casacore::Uniform, and casacore::Weibull.

## parameters()

virtual Vector< Double > casacore::Random::parameters | ( |  | ) | const

pure virtual

Implemented in casacore::Binomial, casacore::DiscreteUniform, casacore::Erlang, casacore::Geometric, casacore::HyperGeometric, casacore::LogNormal, casacore::NegativeExpntl, casacore::Normal, casacore::Poisson, casacore::Uniform, and casacore::Weibull.

## setParameters()

virtual void casacore::Random::setParameters | ( | const Vector< Double > & | parms | ) |

pure virtual

These function allow you to manipulate the parameters (mean variance etc.) of random number distribution.

The parameters() function returns the current value, the setParameters function allows you to change the parameters and the checkParameters function will return False if the supplied parameters are not appropriate for the distribution.

Implemented in casacore::Binomial, casacore::DiscreteUniform, casacore::Erlang, casacore::Geometric, casacore::HyperGeometric, casacore::LogNormal, casacore::NegativeExpntl, casacore::Normal, casacore::Poisson, casacore::Uniform, and casacore::Weibull.

## Member Data Documentation

## itsRNG

RNG* casacore::Random::itsRNG

protected

Definition at line 534 of file Random.h.

Referenced by generator(), generator(), and Random().

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

- casa/BasicMath/Random.h