relife.model.LifetimeModel

relife.model.LifetimeModel

class relife.model.LifetimeModel[source]

Bases: abc.ABC

Generic lifetime model.

Abstract class for lifetime models, with basic functions pertaining to statiscal distributions.

Methods

cdf

Cumulative distribution function.

isf

Inverse survival function.

ls_integrate

Lebesgue-Stieltjes integration.

mean

Mean of the distribution.

median

Median of the distribution.

moment

N-th order moment of the distribution.

mrl

Mean residual life.

pdf

Probability density function.

ppf

Percent point function.

rvs

Random variable sampling.

sf

Survival (or reliability) function of the lifetime model.

support_upper_bound

Support upper bound of the lifetime model.

var

Variance of the distribution.

abstract support_upper_bound(*args: numpy.ndarray) numpy.ndarray[source]

Support upper bound of the lifetime model.

Parameters

*args (float or 2D array, optional) – Extra arguments required by the lifetime model.

Returns

The support upper bound of the lifetime model with respect to the extra arguments.

Return type

float or ndarray

abstract sf(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray[source]

Survival (or reliability) function of the lifetime model.

Parameters
  • t (float or 1D array) – Elapsed time.

  • *args (float or 2D array, optional) – Extra arguments required by the lifetime model.

Returns

The survival function evaluated at t with extra arguments args.

Return type

float or ndarray

Notes

If args are of type ndarray, the arrays should be broadcastable with shape[-1]=1.

The shape of the result will be:

np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (np.size(t),)
abstract pdf(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray[source]

Probability density function.

Parameters
  • t (float or 1D array) – Elapsed time.

  • *args (float or 2D array, optional) – Extra arguments required by the lifetime model.

Returns

The probability density function evaluated at t with extra arguments args.

Return type

float or ndarray

Notes

If args are of type ndarray, the arrays should be broadcastable with shape[-1]=1.

The shape of the result will be:

np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (np.size(t),)
abstract isf(p: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray[source]

Inverse survival function.

Parameters
  • p (float or 1D array) – Probability.

  • *args (float or 2D array, optional) – Extra arguments required by the lifetime model.

Returns

Complement quantile corresponding to p.

Return type

float or ndarray

Notes

If args are of type ndarray, the arrays should be broadcastable with shape[-1]=1.

The shape of the result will be:

np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (np.size(p),)
abstract ls_integrate(func: Callable, a: numpy.ndarray, b: numpy.ndarray, *args: numpy.ndarray, **kwargs) numpy.ndarray[source]

Lebesgue-Stieltjes integration.

The Lebesgue-Stieljes intregration of a function with respect to the lifetime model taking into account the probability density function and jumps.

Parameters
  • func (Callable) – Function or method to integrate on interval [a,b] integrated with respect to the lifetime model.

  • a (float or 1D array) – Lower bound of integration.

  • b (float or 1D array) – Upper bound of integration (use numpy.inf for +infinity).

  • *args (float or 2D array, optional) – Extra arguments required by the lifetime model.

  • **kwargs (int or float) – Extra keyword arguments required for the Lebesgue-Stieljes integration.

Returns

Lebesgue-Stieltjes integral of func with respect to cdf from a to b.

Return type

float or ndarray

Notes

The Lebesgue-Stieltjes integral is:

\[\int_a^b g(x) \mathrm{d}F(x) = \int_a^b g(x) f(x)\mathrm{d}x + \sum_i g(a_i) w_i\]

where:

  • \(F\) is the cumulative distribution function,

  • \(f\) the probability density function of the lifetime model,

  • \(a_i\) and \(w_i\) are the points and weights of the jumps.

1

Resnick, S. I. (1992). Adventures in stochastic processes. Springer Science & Business Media. p176.

cdf(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray[source]

Cumulative distribution function.

Parameters
  • t (float or 1D array) – Elapsed time.

  • *args (float or 2D array, optional) – Extra arguments required by the lifetime model.

Returns

Cumulative distribution function at t with extra args .

Return type

float or ndarray

Notes

If args are of type ndarray, the arrays should be broadcastable with shape[-1]=1.

The shape of the result will be:

np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (np.size(t),)
rvs(*args: numpy.ndarray, size: int = 1, random_state: Optional[int] = None) numpy.ndarray[source]

Random variable sampling.

Parameters
  • *args (float or 2D array, optional) – Extra arguments required by the lifetime model.

  • size (int, optional) – Size of sample, by default 1.

  • random_state (int, optional) – Random seed, by default None.

Returns

Sample of random variates with shape[-1]=size.

Return type

float or ndarray

Notes

If args are of type ndarray, the arrays should be broadcastable with shape[-1]=1.

The shape of the result will be:

np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (size,)
ppf(p: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray[source]

Percent point function.

The ppf is the inverse of cdf.

Parameters
  • p (float or 1D array) – Probability.

  • *args (float or 2D array, optional) – Extra arguments required by the lifetime model.

Returns

Quantile corresponding to p.

Return type

float or ndarray

Notes

If args are of type ndarray, the arrays should be broadcastable with shape[-1]=1.

The shape of the result will be:

np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (np.size(p),)
median(*args: numpy.ndarray) numpy.ndarray[source]

Median of the distribution.

The median is the ppf evaluated at 0.5.

Parameters

*args (float or 2D array, optional) – Extra arguments required by the lifetime model.

Returns

The median of the distribution.

Return type

float or ndarray

Notes

If args are of type ndarray, the arrays should be broadcastable with shape[-1]=1.

The shape of the result will be:

np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (1,)
moment(n: int, *args: numpy.ndarray) numpy.ndarray[source]

N-th order moment of the distribution.

The n-th order moment is the Lebegue-Stieljes integral of x**n with respect to the cdf.

Parameters
  • n (int, n >=1) – Order of moment.

  • *args (float or 2D array, optional) – Extra arguments required by the lifetime model.

Returns

N-th order moment of the distribution.

Return type

float or ndarray

Notes

If args are of type ndarray, the arrays should be broadcastable with shape[-1]=1.

The shape of the result will be:

np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (1,)
mean(*args: numpy.ndarray) numpy.ndarray[source]

Mean of the distribution.

The mean of a distribution is the moment of the first order.

Parameters

*args (float or 2D array, optional) – Extra arguments required by the lifetime model.

Returns

Mean of the distribution.

Return type

float or ndarray

Notes

If args are of type ndarray, the arrays should be broadcastable with shape[-1]=1.

The shape of the result will be:

np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (1,)
var(*args: numpy.ndarray) numpy.ndarray[source]

Variance of the distribution.

Parameters

*args (float or 2D array, optional) – Extra arguments required by the lifetime model.

Returns

Variance of the distribution.

Return type

float or ndarray

Notes

If args are of type ndarray, the arrays should be broadcastable with shape[-1]=1.

The shape of the result will be:

np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (1,)
mrl(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray[source]

Mean residual life.

The mean residual life for an asset aged t is the mean of the lifetime distribution truncated at t on the interval [t,ub).

Parameters
  • t (float or 1D array) – Age of the asset

  • *args (float or 2D array, optional) – Extra arguments required by the lifetime model.

Returns

The mean residual life of assets at age t.

Return type

float or ndarray

Notes

If args are of type ndarray, the arrays should be broadcastable with shape[-1]=1.

The shape of the result will be:

np.broadcast_shapes(*(np.shape(arg) for arg in args))[:-1] + (np.size(t),).

The mean residual life is:

\[\mu(t) = \dfrac{\int_t^{\infty} (x - t) \mathrm{d}F(x)}{S(t)}\]

where \(F\) is the cumulative distribution function and \(S\) is the survival function.