gstools.random

GStools subpackage for random number generation.

Random Number Generator

RNG([seed]) A random number generator for different distributions and multiple streams.

Seed Generator

MasterRNG(seed) Master random number generator for generating seeds.

Distribution factory

dist_gen([pdf_in, cdf_in, ppf_in]) Distribution Factory.

class gstools.random.RNG(seed=None)[source]

A random number generator for different distributions and multiple streams.

Parameters:

seed (int or None, optional) – The seed of the master RNG, if None, a random seed is used. Default: None

Attributes:
random

numpy.random.mtrand.RandomState: Randomstate.

seed

int: Seed of the master RNG.

Methods

sample_dist(self[, pdf, cdf, ppf, size]) Sample from a distribution given by pdf, cdf and/or ppf.
sample_ln_pdf(self, ln_pdf[, size, …]) Sample from a distribution given by ln(pdf).
sample_sphere(self, dim[, size]) Uniform sampling on a d-dimensional sphere.
sample_dist(self, pdf=None, cdf=None, ppf=None, size=None, **kwargs)[source]

Sample from a distribution given by pdf, cdf and/or ppf.

Parameters:
  • pdf (callable or None, optional) – Probability density function of the given distribution, that takes a single argument Default: None
  • cdf (callable or None, optional) – Cumulative distribution function of the given distribution, that takes a single argument Default: None
  • ppf (callable or None, optional) – Percent point function of the given distribution, that takes a single argument Default: None
  • size (int or None, optional) – sample size. Default: None
  • **kwargs – Keyword-arguments that are forwarded to scipy.stats.rv_continuous.
Returns:

samples – the samples from the given distribution

Return type:

float or numpy.ndarray

Notes

At least pdf or cdf needs to be given.

sample_ln_pdf(self, ln_pdf, size=None, sample_around=1.0, nwalkers=50, burn_in=20, oversampling_factor=10)[source]

Sample from a distribution given by ln(pdf).

This algorithm uses the emcee.EnsembleSampler

Parameters:
  • ln_pdf (callable) – The logarithm of the Probability density function of the given distribution, that takes a single argument
  • size (int or None, optional) – sample size. Default: None
  • sample_around (float, optional) – Starting point for initial guess Default: 1.
  • nwalkers (int, optional) – The number of walkers in the mcmc sampler. Used for the emcee.EnsembleSampler class. Default: 100
  • burn_in (int, optional) – Number of burn-in runs in the mcmc algorithm. Default: 100
  • oversampling_factor (int, optional) –

    To guess the sample number needed for proper results, we use a factor for oversampling. The intern used sample-size is calculated by

    sample_size = max(burn_in, (size/nwalkers)*oversampling_factor)

    So at least, as much as the burn-in runs. Default: 10

sample_sphere(self, dim, size=None)[source]

Uniform sampling on a d-dimensional sphere.

Parameters:
  • dim (int) – Dimension of the sphere. Just 1, 2, and 3 supported.
  • size (int, optional) – sample size
Returns:

coord – x[, y[, z]] coordinates on the sphere with shape (dim, size)

Return type:

numpy.ndarray

random

Randomstate.

Get a stream to the numpy Random number generator. You can use this, to call any provided distribution from numpy.random.mtrand.RandomState.

Type:numpy.random.mtrand.RandomState
seed

Seed of the master RNG.

The setter property not only saves the new seed, but also creates a new master RNG function with the new seed.

Type:int
class gstools.random.MasterRNG(seed)[source]

Master random number generator for generating seeds.

Parameters:

seed (int or None, optional) – The seed of the master RNG, if None, a random seed is used. Default: None

Attributes:
seed

int: Seed of the master RNG.

Methods

__call__(self) Return a random seed.
__call__(self)[source]

Return a random seed.

seed

Seed of the master RNG.

The setter property not only saves the new seed, but also creates a new master RNG function with the new seed.

Type:int
gstools.random.dist_gen(pdf_in=None, cdf_in=None, ppf_in=None, **kwargs)[source]

Distribution Factory.

Parameters:
  • pdf_in (callable or None, optional) – Proprobability distribution function of the given distribution, that takes a single argument Default: None
  • cdf_in (callable or None, optional) – Cumulative distribution function of the given distribution, that takes a single argument Default: None
  • ppf_in (callable or None, optional) – Percent point function of the given distribution, that takes a single argument Default: None
  • **kwargs – Keyword-arguments forwarded to scipy.stats.rv_continuous.
Returns:

dist – The constructed distribution.

Return type:

scipy.stats.rv_continuous

Notes

At least pdf or cdf needs to be given.