gstools.random.RNG
- class gstools.random.RNG(seed=None)[source]
Bases:
object
A random number generator for different distributions and multiple streams.
- Parameters
seed (
int
orNone
, optional) – The seed of the master RNG, ifNone
, a random seed is used. Default:None
- Attributes
random
numpy.random.RandomState
: Randomstate.seed
int
: Seed of the master RNG.
Methods
sample_dist
([pdf, cdf, ppf, size])Sample from a distribution given by pdf, cdf and/or ppf.
sample_ln_pdf
(ln_pdf[, size, sample_around, ...])Sample from a distribution given by ln(pdf).
sample_sphere
(dim[, size])Uniform sampling on a d-dimensional sphere.
- sample_dist(pdf=None, cdf=None, ppf=None, size=None, **kwargs)[source]
Sample from a distribution given by pdf, cdf and/or ppf.
- Parameters
pdf (
callable
orNone
, optional) – Probability density function of the given distribution, that takes a single argument Default:None
cdf (
callable
orNone
, optional) – Cumulative distribution function of the given distribution, that takes a single argument Default:None
ppf (
callable
orNone
, optional) – Percent point function of the given distribution, that takes a single argument Default:None
**kwargs – Keyword-arguments that are forwarded to
scipy.stats.rv_continuous
.
- Returns
samples – the samples from the given distribution
- Return type
Notes
At least pdf or cdf needs to be given.
- sample_ln_pdf(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 argumentsample_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: 50burn_in (
int
, optional) – Number of burn-in runs in the mcmc algorithm. Default: 20oversampling_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 bysample_size = max(burn_in, (size/nwalkers)*oversampling_factor)
So at least, as much as the burn-in runs. Default: 10
- sample_sphere(dim, size=None)[source]
Uniform sampling on a d-dimensional sphere.
- Parameters
- Returns
coord – x[, y[, z]] coordinates on the sphere with shape (dim, size)
- Return type
- property random
Randomstate.
Get a stream to the numpy Random number generator. You can use this, to call any provided distribution from
numpy.random.RandomState
.