gstools.random¶
GStools subpackage for random number generation.
Random Number Generator¶
RNG ([seed]) |
A random number generator for different distributions and multiple streams. |
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
orNone
, optional) – The seed of the master RNG, ifNone
, a random seed is used. Default:None
Attributes: 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
- size (
int
orNone
, 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: Notes
At least pdf or cdf needs to be given.
- pdf (
-
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 argument - size (
int
orNone
, 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
- ln_pdf (
-
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:
-
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
-
-
class
gstools.random.
MasterRNG
(seed)[source]¶ Master random number generator for generating seeds.
Parameters: seed (
int
orNone
, optional) – The seed of the master RNG, ifNone
, a random seed is used. Default:None
Attributes: Methods
__call__
()Return a random seed.
-
gstools.random.
dist_gen
(pdf_in=None, cdf_in=None, ppf_in=None, **kwargs)[source]¶ Distribution Factory.
Parameters: - pdf_in (
callable
orNone
, optional) – Proprobability distribution function of the given distribution, that takes a single argument Default:None
- cdf_in (
callable
orNone
, optional) – Cumulative distribution function of the given distribution, that takes a single argument Default:None
- ppf_in (
callable
orNone
, 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: Notes
At least pdf or cdf needs to be given.
- pdf_in (