parepy_toolbox.distributions module#

Probability distributions

convert_params_to_scipy(dist, parameters)[source]#

Convert user-provided distribution parameters to the format required by “scipy.stats”.

Parameters:
  • parameters (dict) – Original distribution parameters. (a) ‘uniform’: keys ‘min’ and ‘max’, (b) ‘normal’: keys ‘mean’ and ‘std’, (c) ‘lognormal’: keys ‘mean’ and ‘std’, (d) ‘gumbel max’: keys ‘mean’ and ‘std’, (e) ‘gumbel min’: keys ‘mean’ and ‘std’, (f) ‘triangular’: keys ‘min’, ‘mode’ and ‘max’, or (g) ‘gamma’: keys ‘mean’ and ‘std’.

  • dist (str)

Returns:

Distribution parameters according scipy.stats documentation.

Return type:

dict

normal_tail_approximation(dist, parameters_scipy, x)[source]#

Converts non-normal distributions to normal approximations while preserving their statistical properties in x point.

Parameters:
  • dist (str) – Type of distribution. Supported values: ‘uniform’, ‘normal’, ‘lognormal’, ‘gumbel max’, ‘gumbel min’, ‘triangular’, or ‘gamma’.

  • parameters_scipy (dict) – Distribution parameters according scipy.stats documentation.

  • x (float) – Project point.

Return type:

tuple[float, float]

return: output[0] = Mean of the normal approximation at point x, output[1] = Standard deviation of the normal approximation at point x.

random_sampling(dist, parameters, method, n_samples)[source]#

Generates random samples from a specified distribution.

Parameters:
  • dist (str) – Type of distribution. Supported values: ‘uniform’, ‘normal’, ‘lognormal’, ‘gumbel max’, ‘gumbel min’, ‘triangular’, or ‘gamma’.

  • parameters (dict) – Original distribution parameters. (a) ‘uniform’: keys ‘min’ and ‘max’, (b) ‘normal’: keys ‘mean’ and ‘std’, (c) ‘lognormal’: keys ‘mean’ and ‘std’, (d) ‘gumbel max’: keys ‘mean’ and ‘std’, (e) ‘gumbel min’: keys ‘mean’ and ‘std’, (f) ‘triangular’: keys ‘min’, ‘mode’ and ‘max’, or (g) ‘gamma’: keys ‘mean’ and ‘std’.

  • method (str) – Sampling method. Supported values: ‘lhs’ (Latin Hypercube Sampling), ‘mcs’ (Crude Monte Carlo Sampling) or ‘sobol’ (Sobol Sampling).

  • n_samples (int) – Number of samples. For Sobol sequences, this variable represents the exponent “m” (n = 2^m).

Returns:

Random samples.

Return type:

list

Example

>>> # pip install -U parepy-toolbox
>>> from parepy_toolbox import random_sampling
>>> parameters = {'mean': 10, 'std': 2}
>>> samples = random_sampling(dist='normal', parameters=parameters,method='lhs', n_samples=100)
>>> print(samples[:10])
random_sampling_statistcs(dist, parameters, values)[source]#
Parameters:
  • dist (str)

  • parameters (dict)

  • values (list)