Distributions

This are implemented distributions used for sampling. The logsim.distributions.Distribution() is an abstract class that defines the interface for all distributions and states the required methods. It is preferred that new distribution implementations inherit from this class and use the frozen distribution to store the distribution type from the scipy.stats module. These distributions are implemented manually in this module in order to provide additional functionality that enables the distributions to be stored in the database and to be used in the simulation.

class logsim.distributions.Random
class logsim.distributions.Distribution
abstract as_dict() dict

Return dictionary representation of distribution, needed for saving to files and the database. Without as_dict will throw an error when saving to database.

get_random_sailing_duration(distance: Quantity) float

Function that dynamically takes a distance and returns a random sailing duration.

Parameters:

distance – distance to be sailed

Returns:

random sailing duration in hours

random() float

Return one random draw as float from distribution

Returns:

random draw from distribution

random_array(size) array

Multiple random draws from the distribution according to given size, returns numpy array.

Parameters:

size – size of array

Returns:

numpy array of random draws

class logsim.distributions.Uniform(minimum, maximum, unit)
as_dict() dict

Return dictionary representation of distribution, needed for saving to files and the database. Without as_dict will throw an error when saving to database.

class logsim.distributions.PERT(minimum, maximum, mode, unit, lmb=4)

PERT distribution, based on the scipy.stats.beta distribution. In order to sample relies on the PertmGen which is a custom scipy implementation based on super class rv_continuous. The PertmGen class is a generator containing all the necessary functions to sample from the PERT distribution or plot the CDF/PDF etc. This PERT class is a wrapper around the PertmGen class and is used to create a PERT distribution and sample from it to use within the simulation.

Parameters:
  • minimum – minimum value of the distribution

  • maximum – maximum value of the distribution

  • mode – mode of the distribution

  • unit – unit of the distribution

  • lmb – lambda parameter of the distribution, default is 4

as_dict() dict

Return dictionary representation of distribution, needed for saving to files and the database.

Returns:

dictionary representation of distribution

class logsim.distributions.PertmGen(momtype=1, a=None, b=None, xtol=1e-14, badvalue=None, name=None, longname=None, shapes=None, extradoc=None, seed=None)

Modified beta_PERT distribution that is used to generate random PERT values. Based on rv_continuous class from scipy.stats and overwrites all required methods to enable sampling, plotting and calculations based on this continuous distribution. No type checking as signature of methods is not compatible with type checking. To use: First create an instance of the class, then call the instance with the parameters to freeze the distribution. Example: pertm = PertmGen(name=”pertm”) and then pertm(1, 2, 1, lmb=4). This will allow a frozen distribution to be used for sampling, plotting etc.

_cdf(x, minimum, mode, maximum, lmb)
_kurt(minimum, mode, maximum, lmb)
_mean(minimum, mode, maximum, lmb)
_ppf(p, minimum, mode, maximum, lmb)
_shape(minimum, mode, maximum, lmb)
_skew(minimum, mode, maximum, lmb)
_stats(minimum, mode, maximum, lmb)
_var(minimum, mode, maximum, lmb)