relife.distribution.Weibull

relife.distribution.Weibull

class relife.distribution.Weibull(c: Optional[float] = None, rate: Optional[float] = None)[source]

Bases: relife.distribution.ParametricLifetimeDistribution

Weibull parametric lifetime distribution.

The Weibull distribution is a 2-parameter distribution with \((c,\lambda)\). The probability density function is:

\[f(t) = c \lambda^c t^{c-1} e^{-(\lambda t)^c}\]

where:

  • \(c > 0\), the shape parameter,

  • \(\lambda > 0\), the rate parameter,

  • \(t\geq 0\), the operating time, age, cycles, etc.

Methods

cdf

Cumulative distribution function.

chf

Cumulative hazard function.

fit

Fit the parametric lifetime distribution to lifetime data.

hf

Hazard function (or hazard rate).

ichf

Inverse cumulative hazard 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.

plot

Plot functions of the distribution model.

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.

Attributes

c

shape parameter

n_params

Number of parameters.

params

Parameters of the hazard functions.

rate

rate parameter (inverse of scale)

c: float = None

shape parameter

rate: float = None

rate parameter (inverse of scale)

property params: numpy.ndarray

Parameters of the hazard functions.

mean() 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,)
mrl(t: 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.

var() 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,)
cdf(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray

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),)
chf(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray

Cumulative hazard function.

The cumulative hazard function is the integral of the hazard function.

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

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

Returns

Cumulative hazard function at 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),)
fit(time: numpy.ndarray, event: Optional[numpy.ndarray] = None, entry: Optional[numpy.ndarray] = None, args: numpy.ndarray = (), params0: Optional[numpy.ndarray] = None, method: Optional[str] = None, **kwargs) relife.distribution.ParametricLifetimeDistribution

Fit the parametric lifetime distribution to lifetime data.

Parameters
  • time (1D array) – Array of time-to-event or durations.

  • event (1D array, optional) –

    Array of event types coded as follows:

    • 0 if observation ends before the event has occurred (right censoring)

    • 1 if the event has occured

    • 2 if observation starts after the event has occurred (left censoring)

    by default the event has occured for each asset.

  • entry (1D array, optional) – Array of delayed entry times (left truncation), by default None.

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

  • params0 (1D array, optional) – Initial guess, by default None.

  • method (str, optional) – Type of solver (see scipy.optimize.minimize documentation), by default None.

  • **kwargs (dict, optional) – Extra arguments to pass to the minimize method.

Returns

Return the fitted distribution as the current object.

Return type

self

hf(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray

Hazard function (or hazard rate).

The hazard function is the derivative of the cumulative hazard function.

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

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

Returns

Hazard rate at t.

Return type

float or 1D array

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),)
ichf(v: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray

Inverse cumulative hazard function.

Parameters
  • v (float or 1D array) – Cumulative hazard rate

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

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),)
isf(p: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray

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),)
ls_integrate(func: Callable, a: numpy.ndarray, b: numpy.ndarray, *args: numpy.ndarray, ndim: int = 0, deg: int = 100, q0: float = 0.0001) numpy.ndarray

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.

median(*args: numpy.ndarray) numpy.ndarray

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

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,)
property n_params: int

Number of parameters.

pdf(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray

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),)
plot(timeline: Optional[numpy.ndarray] = None, args: Tuple[numpy.ndarray] = (), alpha_ci: float = 0.05, fname: str = 'sf', **kwargs) None

Plot functions of the distribution model.

Parameters
  • timeline (1D array, optional) – Timeline of the plot (x-axis), by default guessed by the millile.

  • args (Tuple[ndarray], optional) – Extra arguments required by the parametric lifetime model, by default ().

  • alpha_ci (float, optional) – \(\alpha\)-value to define the \(100(1-\alpha)\%\) confidence interval, by default 0.05 corresponding to the 95% confidence interval. If set to None or if the model has not been fitted, no confidence interval is plotted.

  • fname (str, optional) –

    Name of the function to be plotted, by default ‘sf’. Should be one of:

    • ’sf’: survival function,

    • ’cdf’: cumulative distribution function,

    • ’chf’: cumulative hazard function,

    • ’hf’: hazard function,

    • ’pdf’: probability density function.

  • **kwargs (dict, optional) – Extra arguments to specify the plot properties (see matplotlib.pyplot.plot documentation).

Raises

ValueError – If fname value is not among ‘sf’, ‘cdf’, ‘chf’, ‘hf’ or ‘pdf’.

ppf(p: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray

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),)
rvs(*args: numpy.ndarray, size: int = 1, random_state: Optional[int] = None) numpy.ndarray

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,)
sf(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray

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),)
support_upper_bound(*args: numpy.ndarray) float

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