Dist_walker

class stats.Dist_walker(probabilities, values=None)

Bases: stats.Dist_qilum

Fast generator for discrete values using the Walker algorithm

Parameters
  • probabilities (array_like) – an array of probability

  • values (array_like or None) – values corresponding to the probabilities. if ‘None’ values=arange(probabilities.size)

Examples

>>> import qilum.stats as qs
>>> values = np.array([0, 10, 2])
>>> probabilities = np.array([0.2, 0.5, 0.3])
>>> walker = qs.Dist_walker(probabilities, values)
../_images/Dist_walker.jpg

Methods Summary

F_tot()

Cumulative of the function f() on the whole valid range x

cdf(x)

Cumulative distribution function.

f(x)

function f(x)

name()

Name of the class: ‘Dist_walker’

pdf(x)

Same as pmf()

pmf(x)

Probability mass function

ppf(q)

Percent point function (inverse of cdf) at q

rvs([size])

random numbers in ndarray of lenght size

Methods Documentation

F_tot()

Cumulative of the function f() on the whole valid range x

Returns

probabilities.sum()

Return type

int

Examples

>>> import qilum.stats as qs
>>> walker = qs.Dist_walker([0.2, 0.5, 0.3], [0, 10, 2])
>>> print(walker.F_tot())
1.0
cdf(x)

Cumulative distribution function.

Parameters

x (array_like of type(values)) –

Returns

Cumulative distribution function evaluated at x

Return type

ndarray

Examples

>>> import qilum.stats as qs
>>> walker = qs.Dist_walker([0.2, 0.5, 0.3], [0, 10, 2])
>>> x = [0,1,2,3,4,5,6,7,8,9,10]
>>> print('cdf(x)=',walker.cdf(x))
cdf(x)= [0.2 0.2 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 1. ]
f(x)

function f(x)

Parameters

x (array_like of type(values)) –

Returns

f(x)

Return type

ndarray

Examples

>>> import qilum.stats as qs
>>> walker = qs.Dist_walker([0.2, 0.5, 0.3], [0, 10, 2])
>>> x = [0,1,2,3,4,5,6,7,8,9,10]
>>> print('f(x)=',walker.f(x))
f(x)= [0.2 0.  0.3 0.  0.  0.  0.  0.  0.  0.  0.5]
name()

Name of the class: ‘Dist_walker’

pdf(x)

Same as pmf()

pmf(x)

Probability mass function

Parameters

x (array_like of type(values)) –

Returns

f(x)/probabilities.sum()

Return type

ndarray

Examples

>>> import qilum.stats as qs
>>> walker = qs.Dist_walker([0.2, 0.5, 0.3], [0, 10, 2])
>>> x = [0,1,2,3,4,5,6,7,8,9,10]
>>> print('pmf(x)=',walker.pmf(x))
pmf(x)= [0.2 0.  0.3 0.  0.  0.  0.  0.  0.  0.  0.5]
ppf(q)

Percent point function (inverse of cdf) at q

Parameters

q (array_like of double) – lower tail probability

Returns

quantile corresponding to the lower tail probability q

Return type

ndarray

Examples

>>> import qilum.stats as qs
>>> walker = qs.Dist_walker([0.2, 0.5, 0.3], [0, 10, 2])
>>> q = [0,0.3,0.5,0.7,1]
>>> print('ppf(q)=',walker.ppf(q))
ppf(q)= [ 0.  2.  2. 10. 10.]
rvs(size=1)

random numbers in ndarray of lenght size

Parameters

size (int) – number of random number

Returns

random numbers

Return type

ndarray

Examples

>>> import qilum.stats as qs
>>> walker = qs.Dist_walker([0.2, 0.5, 0.3], [0, 10, 2])
>>> print('rans=',walker.rvs(10))
rans= [ 0  0  0 10  0 10  2  2 10  0]