credible.utils

Basic typing used throughout this package.

Module Attributes

CIFunctor

A confidence-interval functor.

CIArrayFunctor

A confidence-interval functor that works with arrays.

Functions

as_int_arrays(input_)

Convert integer sequences into arrays, and checks for matching lenghts.

safe_divide(n, d)

Divide n by d.

credible.utils.CIFunctor

A confidence-interval functor.

Exchangeable functors follow this prototype:

def f(successes: int, failures: int) -> tuple[float, float, float]:
    '''Returns best estimate, lower, and upper bounds of metric.'''
    pass

Functors allow evaluation of bayesian credible regions or confidence intervals without coverage or \(\lambda\) parameterisation (implicit). It works as a partial function in which those parameters are predefined.

alias of Callable[[int, int], tuple[float, float, float]]

credible.utils.CIArrayFunctor

A confidence-interval functor that works with arrays.

Functors allow evaluation of bayesian credible regions or confidence intervals without coverage or \(\lambda\) parameterisation (implicit). It works as a partial function in which those parameters are predefined.

alias of Callable[[Iterable[int], Iterable[int]], tuple[ndarray[tuple[int, …], dtype[float64]], ndarray[tuple[int, …], dtype[float64]], ndarray[tuple[int, …], dtype[float64]]]]

credible.utils.as_int_arrays(input_)[source]

Convert integer sequences into arrays, and checks for matching lenghts.

Uses numpy.asarray(), which only converts arguments if they are not already integer arrays. We then use numpy.atleast_1d() to ensure all output arrays have at least 1 dimension.

Parameters:

input – Integer sequences to be converted into numpy arrays of integers.

Return type:

tuple[ndarray[tuple[int, ...], dtype[int64]], ...]

Returns:

A tuple with input arrays converted. All input arrays contain are at least one dimensional.

Raises:

TypeError – If the dimensions of the various arrays do not match.

credible.utils.safe_divide(n, d)[source]

Divide n by d. Returns 0.0 in case of a division by zero.

Parameters:
Return type:

float

Returns:

\(\frac{n}{d}`\) if \(d \ne 0\), else 0.