generatorsrandom.py

class IGenRandom[source]

Bases: ABC

Interface (abstract base class) for wrapping numpy random number generation to allow probability distribution parameters to be specified in the initialiser whereas the generation of random numbers has a common method that just takes the require shape to return. Allows for easy subsitution of different probability distributions.

abstractmethod generate(shape)[source]

Abstract method. Generates an array of random numbers with the shape specified by the input.

Parameters:

shape (tuple[int,...]) – Shape of the array of random numbers to be returned.

Returns:

np.ndarray – Array of random numbers with shape specified by the input shape.

class GenNormal(std=1.0, mean=0.0, seed=None)[source]

Bases: IGenRandom

Class wrapping the numpy normal random number generator. Implements the IGeneratorRandom interface to allow for interchangeability with other random number generators.

__init__(std=1.0, mean=0.0, seed=None)[source]
Parameters:
  • std (float, optional) – Standard deviation of the normal distribution to sample, by default 1.0

  • mean (float, optional) – Mean of the normal distribution to sample, by default 0.0

  • seed (int | None, optional) – Optional seed for the random generator to allow for reproducibility and testing, by default None

generate(shape)[source]

Generates an array of random numbers with the shape specified by the input.

Parameters:

shape (tuple[int,...]) – Shape of the array to return.

Returns:

np.ndarray – Array of random numbers with the specified shape.

class GenLogNormal(std=1.0, mean=0.0, seed=None)[source]

Bases: IGenRandom

Class wrapping the numpy lognormal random generator. Implements the IGeneratorRandom interface to allow for interchangeability with other random number generators.

__init__(std=1.0, mean=0.0, seed=None)[source]
Parameters:
  • std (float, optional) – Standard deviation of the normal distribution to sample, by default 1.0

  • mean (float, optional) – Mean of the normal distribution to sample, by default 0.0

  • seed (int | None, optional) – Optional seed for the random generator to allow for reproducibility and testing, by default None

generate(shape)[source]

Generates an array of random numbers with the shape specified by the input.

Parameters:

shape (tuple[int,...]) – Shape of the array to return.

Returns:

np.ndarray – Array of random numbers with the specified shape.

class GenUniform(low=-1.0, high=1.0, seed=None)[source]

Bases: IGenRandom

Class wrapping the numpy uniform random number generator. Implements the IGeneratorRandom interface to allow for interchangeability with other random number generators.

__init__(low=-1.0, high=1.0, seed=None)[source]
Parameters:
  • low (float, optional) – Lower bound of the uniform dsitribution., by default -1.0

  • high (float, optional) – Upper bound of the uniform distribution, by default 1.0

  • seed (int | None, optional) – Optional seed for the random generator to allow for reproducibility and testing, by default None

generate(shape)[source]

Generates an array of random numbers with the shape specified by the input.

Parameters:

shape (tuple[int,...]) – Shape of the array to return.

Returns:

np.ndarray – Array of random numbers with the specified shape.

class GenExponential(scale=1.0, seed=None)[source]

Bases: IGenRandom

Class wrapping the numpy exponential random generator. Implements the IGeneratorRandom interface to allow for interchangeability with other random number generators.

__init__(scale=1.0, seed=None)[source]
Parameters:
  • scale (float, optional) – Scale parameter of the distribution which must be positive, by default 1.0

  • seed (int | None, optional) – Optional seed for the random generator to allow for reproducibility and testing, by default None

generate(shape)[source]

Generates an array of random numbers with the shape specified by the input.

Parameters:

shape (tuple[int,...]) – Shape of the array to return.

Returns:

np.ndarray – Array of random numbers with the specified shape.

class GenChiSquare(dofs, seed=None)[source]

Bases: IGenRandom

Class wrapping the numpy chi square random generator. Implements the IGeneratorRandom interface to allow for interchangeability with other random number generators.

__init__(dofs, seed=None)[source]
Parameters:
  • dofs (float) – Number of degrees of freedom of the distribution must be greater than zero.

  • seed (int | None, optional) – Optional seed for the random generator to allow for reproducibility and testing, by default None

generate(shape)[source]

Generates an array of random numbers with the shape specified by the input.

Parameters:

shape (tuple[int,...]) – Shape of the array to return.

Returns:

np.ndarray – Array of random numbers with the specified shape.

class GenDirichlet(alpha, seed=None)[source]

Bases: IGenRandom

Class wrapping the numpy dirichlet random generator. Implements the IGeneratorRandom interface to allow for interchangeability with other random number generators.

__init__(alpha, seed=None)[source]
Parameters:
  • alpha (float) – Alpha parameter of the distribution

  • seed (int | None, optional) – Optional seed for the random generator to allow for reproducibility and testing, by default None

generate(shape)[source]

Generates an array of random numbers with the shape specified by the input.

Parameters:

shape (tuple[int,...]) – Shape of the array to return.

Returns:

np.ndarray – Array of random numbers with the specified shape.

class GenF(dofs, seed=None)[source]

Bases: IGenRandom

Class wrapping the numpy F distribution random generator. Implements the IGeneratorRandom interface to allow for interchangeability with other random number generators.

__init__(dofs, seed=None)[source]
Parameters:
  • dofs (float) – Number of degrees of freedom of the distribution must be greater than zero

  • seed (int | None, optional) – Optional seed for the random generator to allow for reproducibility and testing, by default None

generate(shape)[source]

Generates an array of random numbers with the shape specified by the input.

Parameters:

shape (tuple[int,...]) – Shape of the array to return.

Returns:

np.ndarray – Array of random numbers with the specified shape.

class GenGamma(shape, scale=1.0, seed=None)[source]

Bases: IGenRandom

Class wrapping the numpy gamma random generator. Implements the IGeneratorRandom interface to allow for interchangeability with other random number generators.

__init__(shape, scale=1.0, seed=None)[source]
Parameters:
  • shape (float) – Shape parameter of the gamma distribution, must be greater than zero

  • scale (float, optional) – Scale parameter of the gamma distribution which must be greater than zero, by default 1.0

  • seed (int | None, optional) – Optional seed for the random generator to allow for reproducibility and testing, by default None

generate(shape)[source]

Generates an array of random numbers with the shape specified by the input.

Parameters:

shape (tuple[int,...]) – Shape of the array to return.

Returns:

np.ndarray – Array of random numbers with the specified shape.

class GenStandardT(dofs, seed=None)[source]

Bases: IGenRandom

Class wrapping the numpy t distribution random generator. Implements the IGeneratorRandom interface to allow for interchangeability with other random number generators.

__init__(dofs, seed=None)[source]
Parameters:
  • dofs (float) – Number of degrees of freedom of the distribution must be greater than zero.

  • seed (int | None, optional) – Optional seed for the random generator to allow for reproducibility and testing, by default None

generate(shape)[source]

Generates an array of random numbers with the shape specified by the input.

Parameters:

shape (tuple[int,...]) – Shape of the array to return.

Returns:

np.ndarray – Array of random numbers with the specified shape.

class GenBeta(a, b, seed=None)[source]

Bases: IGenRandom

Class wrapping the numpy beta distribution random generator. Implements the IGeneratorRandom interface to allow for interchangeability with other random number generators.

__init__(a, b, seed=None)[source]
Parameters:
  • a (float) – Alpha parameter of the distribution which must be greater than zero

  • b (float) – Beta parameter of the distribution which must be greater than zero

  • seed (int | None, optional) – Optional seed for the random generator to allow for reproducibility and testing, by default None

generate(shape)[source]

Generates an array of random numbers with the shape specified by the input.

Parameters:

shape (tuple[int,...]) – Shape of the array to return.

Returns:

np.ndarray – Array of random numbers with the specified shape.

class GenTriangular(left=-1.0, mode=0.0, right=1.0, seed=None)[source]

Bases: IGenRandom

Class wrapping the numpy triangular random generator. Implements the IGeneratorRandom interface to allow for interchangeability with other random number generators.

__init__(left=-1.0, mode=0.0, right=1.0, seed=None)[source]
Parameters:
  • left (float, optional) – Left (min) corner of the triangular distribution, by default -1.0

  • mode (float, optional) – Central peak of the triangular distribution, by default 0.0

  • right (float, optional) – Right (max) corner of the triangular distribution , by default 1.0

  • seed (int | None, optional) – Optional seed for the random generator to allow for reproducibility and testing, by default None

generate(shape)[source]

Generates an array of random numbers with the shape specified by the input.

Parameters:

shape (tuple[int,...]) – Shape of the array to return.

Returns:

np.ndarray – Array of random numbers with the specified shape.