random_util

Short description

@author: Moritz F P Becker

class pyrid.math.random_util.Interpolate(*args, **kwargs)[source]

Interpolation

Source: https://stackoverflow.com/questions/7343697/how-to-implement-linear-interpolation

Methods

call

class_type

pyrid.math.random_util.bisect_right(a, x)[source]

Return the index where to insert item x in list a, assuming a is sorted.

The return value i is such that all e in a[:i] have e <= x, and all e in a[i:] have e > x. So if x already appears in the list, a.insert(i, x) will insert just after the rightmost x already there.

Optional args lo (default 0) and hi (default len(a)) bound the slice of a to be searched.

Reduced copy from Cpython library: https://github.com/python/cpython/blob/3.10/Lib/bisect.py

Parameters
aarray_like

Array which to bisect

xfloat64

Value which to insert in the sorted list

Returns
int64

Index where to isnert x

pyrid.math.random_util.dx_cum_prob(x)[source]

Cumulative probability distribution for the distance away from a plane of a diffusing particle after it crossing the plane [10].

Parameters
xfloat64

Normalized distance

Returns
float64

Probability of a diffusing particle being x (normalized by the diffusion length coefficient) away from a plane after it crossing the plane.

Raises
NotImplementedError (just an example)

Brief explanation of why/when this exception is raised

pyrid.math.random_util.erfc(x)[source]

Calculates the complementary error function of all elements in the 1D Array x using the erfc fucntion from the math library, which, hwoever, only works on scalars.

Parameters
xfloat64[:]

Array of whose elements to calculate erfc.

Returns
float64[:]

Complementary error function of array x.

pyrid.math.random_util.random_choice(population=None, weights=None, cum_weights=None)[source]

Returns a weighted random element from a given list if population is passed, othewise returns the respective index.

Parameters
populationarray_like

population from which to pick an element.

weightsfloat64[:]

Weights

cum_weightsfloat64[:]

Cumulative weights

Returns
int64

Random element from the population or its index.

Raises
TypeError(“random_choice() missing required argument ‘weight’ or ‘cum_weight’”)

Error raised if neither a weight nor a cumulative weight is passed.