Randomly Sample Distributions

Functions

sampling.discrete_powerlaw_ccdf(val, xmin, alpha)

Calculate the complementary cumulative distribution function of a discrete power law distribution such that P(x) = Pr(X >= x)

Parameters:
  • x (float) – value at which to evaluate CDF
  • xmin (float) – lower bound of power law PDF
  • alpha (float) – exponent of power law
  • upper_limit (int) – number of terms used to calculate Hurwitz zeta function

:return CDF of power law PDF evaluated at x :rtype float

sampling.exact_discrete_power_law_sample(alpha, xmin, size=1)

Exact method for generating random draws from a discrete power law distribution of form t**-alpha

See Appendix D of https://epubs.siam.org/doi/abs/10.1137/070710111.

This method is slow and the approximation might be more useful

Parameters:
  • alpha – power law exponent
  • xmin (float) – lower limit of distribution.
  • size (int) – number of random draws to perform
Type:

alpha: float

Returns:

array of random power law draws

sampling.approximate_discrete_powerlaw(alpha, xmin, size=1)

Approximate random draws from a discrete power law distribution of form t**-alpha. Much faster than discrete_powerlaw()

See Appendix D of https://epubs.siam.org/doi/abs/10.1137/070710111

Parameters:
  • alpha – power law exponent
  • xmin (float) – lower limit of distribution.
  • size (int) – number of random draws to perform
Type:

alpha: float

Returns:

array of random power law draws

sampling.random_power_law_dwell(alpha, ll=0.1, size=1, limit=None, discrete=False, exact=False)

Randomly draw from a power law distribution of form t**-alpha See Appendix D of https://epubs.siam.org/doi/abs/10.1137/070710111

Parameters:
  • alpha – anomalous exponent + 1
  • ll – lower limit of distribution.
  • size – number of random draws to perform
  • limit – upper limit on dwell time length (As implemented, this is not mathematically sound, so it’s only

for demonstration purposes) :param discrete: pull from discrete power law distribution (uses approximation :param exact: use exact method for generating random draws from discrete power law distribution

Type:alpha: float
Returns:array of random power law draws
sampling.random_exponential_dwell(lam, size=1)

Randomly draw from an exponential distribution See Appendix D of https://epubs.siam.org/doi/abs/10.1137/070710111

Parameters:
  • lam (float) – rate of decay
  • size (int) – number of random draws to perform
Returns:

array of random draws