Probability mass function

Module openquake.hazardlib.pmf implements PMF.

class openquake.hazardlib.pmf.PMF(data, epsilon=1e-15)[source]

Probability mass function is a function that gives the probability that a discrete random variable is exactly equal to some value.

Parameters:
  • data

    The PMF data in a form of list of tuples. Each tuple must contain two items with the first item being the probability of the implied random variable to take value of the second item.

    There must be at least one tuple in the list. All probabilities must sum up to 1 within the given precision.

    The type of values (second items in tuples) is not strictly defined, those can be objects of any (mixed or homogeneous) type.

  • epsilon – the tolerance for the sum of the probabilities (default 1E-15)
Raises:

ValueError – If probabilities do not sum up to 1 or there is zero or negative probability.

NB: in the engine the sum is checked to be exactly one by using Decimal numbers.

sample(number_samples)[source]

Produces a list of samples from the probability mass function.

Parameters:data (int) – Number of samples
Returns:Samples from PMF as a list
sample_pairs(number_samples)[source]

Produces a list of samples from the probability mass function.

Parameters:data (int) – Number of samples
Returns:Samples from PMF as a list of pairs