DOrandomnumbers.h

Classes

randomnumbers -- The C++ side of the glish randomnumbers tool. (full description)

class randomnumbers: public ApplicationObject

Types

enum methods

BINOMIAL
DISCRETEUNIFORM
ERLANG
GEOMETRIC
HYPERGEOMETRIC
NORMAL
LOGNORMAL
NEGATIVEEXPONENTIAL
POISSON
UNIFORM
WEIBULL
RESEED
NUM_METHODS

Interface

Public Members
randomnumbers()
randomnumbers(const randomnumbers& other)
randomnumbers& operator=(const randomnumbers& other)
~randomnumbers()
Array<Int> binomial(Int number, Double prob, const Vector<Int>& shape)
Array<Int> discreteuniform(Int low, Int high, const Vector<Int>& shape)
Array<Double> erlang(Double mean, Double variance, const Vector<Int>& shape)
Array<Int> geometric(Double probability, const Vector<Int>& shape)
Array<Double> hypergeometric(Double mean, Double variance, const Vector<Int>& shape)
Array<Double> normal(Double mean, Double variance, const Vector<Int>& shape)
Array<Double> lognormal(Double mean, Double variance, const Vector<Int>& shape)
Array<Double> negativeexponential(Double mean, const Vector<Int>& shape)
Array<Int> poisson(Double mean, const Vector<Int>& shape)
Array<Double> uniform(Double low, Double high, const Vector<Int>& shape)
Array<Double> weibull(Double alpha, Double beta, const Vector<Int>& shape)
void reseed(Int seed)
virtual String className() const
virtual Vector<String> methods() const
virtual Vector<String> noTraceMethods() const
virtual MethodResult runMethod(uInt which, ParameterSet& inputRecord, Bool runMethod)
Private Members
Vector<Double> getSamples(Random& distn, uInt nSamples)
void checkShape(const Vector<Int>& shape, const String& function)

Description

Review Status

Date Reviewed:
yyyy/mm/dd

Prerequisite

Etymology

The name MUST have the 'DO' prefix as this class is derived from ApplicationObject, and hence is classified as a distributed object. For the same reason the rest of its name must be in lower case. This class generates randomnumbers.

Synopsis

This class generates random numbers. The random numbers can be from a wide variety of distributions.

All the functions return the samples in an Array of user specified shape. The vector specifying the shape must contain only positive values, otherwise and an AipsError exception will be thrown.

Example

Motivation

Thrown Exceptions

To Do

Member Description

randomnumbers()

Construct a class that generates random numbers

randomnumbers(const randomnumbers& other)

The copy constructor uses copy semantics

randomnumbers& operator=(const randomnumbers& other)

The assignment operator uses copy semantics

~randomnumbers()

The destructor deletes all data allocated within this class

Array<Int> binomial(Int number, Double prob, const Vector<Int>& shape)

Generates a random number from the binomial distribution. This models drawing items from a pool. The 'number' parameter indicates how many items are in the pool, and the 'prob' parameter indicates the probability of drawing an item. The returned samples are the number of items actually drawn. The number parameter must be a non-negative integer, and the probablity must be between zero and one; otherwise an AipsError exception is thrown. The returned samples will be a non-negative integers that cannot be greater than the number of items in the pool.

Array<Int> discreteuniform(Int low, Int high, const Vector<Int>& shape)

Generates a random number from the discrete uniform distribution. If the low value is higher than the high value an AipsError exception is thrown.

Array<Double> erlang(Double mean, Double variance, const Vector<Int>& shape)

Generates a random number from the Erlang distribution. The mean cannot be zero and the variance must be positive; otherwise and AipsError exception will be thrown.

Array<Int> geometric(Double probability, const Vector<Int>& shape)

Generates a random number from the geometric distribution. The probability must be a non-negative value less than one; otherwise and AipsError exception will be thrown.

Array<Double> hypergeometric(Double mean, Double variance, const Vector<Int>& shape)

Generates a random number from the hyper-geometric distribution. The variance must be positive and the mean must be non-zero and cannot be bigger than the square-root of the variance; otherwise and AipsError exception will be thrown.

Array<Double> normal(Double mean, Double variance, const Vector<Int>& shape)

Generates a random number from the normal or Gaussian distribution. The mean and variance can be any values.

Array<Double> lognormal(Double mean, Double variance, const Vector<Int>& shape)

Generates a random number from the log-normal distribution. The mean must be non-zero and variance must be positive; otherwise and AipsError exception will be thrown.

Array<Double> negativeexponential(Double mean, const Vector<Int>& shape)

Generates a random number from the negative exponential distribution. The mean can be any value.

Array<Int> poisson(Double mean, const Vector<Int>& shape)

Generates a random number from the Poisson distribution. The mean must be non-negative; otherwise and AipsError exception will be thrown.

Array<Double> uniform(Double low, Double high, const Vector<Int>& shape)

Generates a random number from the uniform distribution. If the low value cannot be higher than the high value; otherwise and AipsError exception will be thrown. The low value may be returned unlike the high value.

Array<Double> weibull(Double alpha, Double beta, const Vector<Int>& shape)

Generates a random number from the Weibull distribution. The alpha parameter cannot be zero; otherwise and AipsError exception will be thrown.

void reseed(Int seed)

Specify a new seed to the random number generator. This allows you to get reproducable random numbers.

virtual String className() const

return the name of this object type the distributed object system. This function is required as part of the DO system

virtual Vector<String> methods() const

the returned vector contains the names of all the methods which may be used via the distributed object system. This function is required as part of the DO system

virtual Vector<String> noTraceMethods() const

the returned vector contains the names of all the methods which are to trivial to warrent automatic logging. This function is required as part of the DO system

virtual MethodResult runMethod(uInt which, ParameterSet& inputRecord, Bool runMethod)

Run the specified method. This is the function used by the distributed object system to invoke any of the specified member functions in thi s class.

Vector<Double> getSamples(Random& distn, uInt nSamples)

void checkShape(const Vector<Int>& shape, const String& function)

enum methods