Distribution functions

The escape.core.distribution module provides functors for several commonly used distribution functions:

  • Gamma

  • Schulz-Zimm

  • LogNorm

  • Normal (Gaussian)

  • Uniform

  • Triangular

Usage notes

The distribution functions normal, uniform and triangular use the full width at half maximum (FWHM) as the width parameter instead of \(\sigma\).

The input arguments x and mean can be functors or parameters, but must be of the same type. The sigma or fwhm argument can be a functor or a parameter, the same type as x and mean is optional. Variables and numeric constants as input arguments are converted to identity functions and parameters with a constant value, respectively.

Several examples:

  • >>> x = esc.var("x")
    >>> x0 = esc.var("x0")
    >>> s = esc.var("s")
    >>> d = esc.gamma("Gamma", x, x0, s)
    >>> type(d) 
      <class 'escape.core.objects.functor_obj'>
    >>> d.variables()
      [variable(name='x'), variable(name='x0'), variable(name='s')]
    >>> d(1, 1, 2) 
      0.15189039329751247
    
  • >>> x = esc.par("x", 1)
    >>> x0 = esc.par("x0", 1)
    >>> s = esc.var("s")
    >>> d = esc.gamma("Gamma", x, x0, s)
    >>> type(d)
      <class 'escape.core.objects.functor_obj'>
    >>> d.variables()
      [variable(name='s')]
    >>> d(2) 
      0.15189039329751247
    
  • >>> x = esc.par("x", 1)
    >>> x0 = esc.par("x0", 1)
    >>> s = esc.par("s", 2)
    >>> d = esc.gamma("Gamma", x, x0, s)
    >>> type(d)
      <class 'escape.core.objects.parameter_obj'>
    >>> d.value
      0.15189039329751247
    
  • >>> d = esc.gamma("Gamma", 1, esc.var("x0"), s = esc.par("s", 2))
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "escape\core\distribution.pyx", line 138, in escape.core.distribution.gamma
      TypeError:  Wrong type of `x` and `mean` argument, expected for both `parameter_obj`, `variable_obj` or `functor_obj` got <class 'int'>, <class 'escape.core.objects.variable_obj'>
    
escape.core.distribution.gamma(name, x, mean, sigma)

Gamma distribution functor of the following form: \(1/\theta\exp((k-1)\log(t)-x/\theta-\log(\Gamma(k)))\), where \(\theta=\sigma^2x_0\), \(k=x_0/\theta\), \(t=x/\theta\).

Parameters:
name: string

Name of the functor. Ignored if returned object is a parameter

x: variable_obj, functor_obj, parameter_obj or numeric

Coordinate

mean: variable_obj, functor_obj, parameter_obj or numeric

Mean value

sigma: functor_obj, parameter_obj or numeric

Sigma defines width of the distribution function

Returns:

object of type functor_obj or parameter_obj, depending on the types of function arguments

escape.core.distribution.schulz(name, x, mean, sigma)

Schulz-Zimm distribution functor of the following form: \(t/x\exp((k-1)\log(t)-t-\log(\Gamma(k)))\), where \(k=1/\sigma^2\), \(t=kx/x_0\).

Parameters:
name: string

Name of the functor. Ignored if returned object is a parameter

x: variable_obj

Variable object

mean: variable_obj, parameter_obj or numeric

Mean value

sigma: functor_obj, parameter_obj or numeric

Sigma defines width of the distribution function

Returns:

object of type functor_obj

escape.core.distribution.lognorm(name, x, mean, sigma)

Lognorm distribution functor of the following form: \(\exp(\log^2(x/x_0)/(2\sigma^2))/(\sqrt(2\pi)\sigma x)\),

Parameters:
name: string

Name of the functor. Ignored if returned object is a parameter

x: variable_obj

Variable object

mean: variable_obj, parameter_obj or numeric

Mean value

sigma: functor_obj, parameter_obj or numeric

Sigma defines width of the distribution function

Returns:

object of type functor_obj

escape.core.distribution.normal(name, x, mean, fwhm)

Normal distribution functor of the following form: \(1/(\sqrt(2\pi)\sigma)\exp(-(x-x_0)^2/(2\sigma^2))\), where \(\sigma = FWHM/2.355\)

Parameters:
name: string

Name of the functor. Ignored if returned object is a parameter

x: variable_obj

Variable object

mean: variable_obj, parameter_obj or numeric

Mean value

fwhm: functor_obj, parameter_obj or numeric

Full width at half maximum

Returns:

object of type functor_obj

escape.core.distribution.uniform(name, x, mean, fwhm)

Uniform distribution functor. \(G(x; x_0, FWHM) = 1.0 / w\), for \(x_0-w/2<=x<=x_0+w/2\) and :\(w==FWHM\)

Parameters:
name: string

Name of the functor. Ignored if returned object is a parameter

x: variable_obj

Variable object

mean: variable_obj, parameter_obj or numeric

Mean value

fwhm: functor_obj, parameter_obj or numeric

Full width at half maximum

Returns:

object of type functor_obj

escape.core.distribution.triangular(name, x, mean, fwhm)

Triangular distribution functor. \(G(x; x_0, w) = 2 (x - a) / (b - a) / (x_0 - a)\), for \(a<=x<=x_0\) \(G(x; x_0, w) = 2 (b - x) / (b - a) / (b - x_0)\), for \(x_0<=x<=b\), where \(a=x_0-w\) and \(b=x_0+w\) and \(w==FWHM\)

Parameters:
name: string

Name of the functor. Ignored if returned object is a parameter

x: variable_obj

Variable object

mean: variable_obj, parameter_obj or numeric

Mean value

fwhm: functor_obj, parameter_obj or numeric

Full width at half maximum

Returns:

object of type functor_obj