relife package

Submodules

relife.data module

Dataclasses for survival analysis and renewal processes outputs.

class relife.data.LifetimeData(time: numpy.ndarray, event: Optional[numpy.ndarray] = None, entry: Optional[numpy.ndarray] = None, args: Tuple[numpy.ndarray] = ())[source]

Bases: object

Lifetime data.

Dataclass of lifetime data required by the maximum likelihood estimation.

time: numpy.ndarray

Age of the assets.

event: numpy.ndarray = None

Type of event, by default None.

entry: numpy.ndarray = None

Age of assets at the beginning of the observation period (left truncation), by default None.

args: Tuple[numpy.ndarray] = ()

Extra arguments required by the lifetime model.

class DataByEvent(D: numpy.ndarray, D_RC: numpy.ndarray, LC: numpy.ndarray, LT: numpy.ndarray)[source]

Bases: tuple

Group data by type of event.

Create new instance of DataByEvent(D, D_RC, LC, LT)

D: numpy.ndarray

observed event.

D_RC: numpy.ndarray

union of observed events and right-censored data.

LC: numpy.ndarray

left-censored data.

LT: numpy.ndarray

left-truncated data.

astuple() Tuple[numpy.ndarray, ...][source]

Converts the dataclass attributes as a tuple.

Returns

The attributes of the class as the tuple (time, event, entry, *args).

Return type

Tuple[ndarray]

class relife.data.CountData(T: float, n_indices: int, n_samples: int, indices: numpy.ndarray, samples: numpy.ndarray, times: numpy.ndarray)[source]

Bases: object

Counting process data.

T: float

Time at the end of the observation.

n_indices: int

Number of initial assets.

n_samples: int

Numbers of samples.

indices: numpy.ndarray

Indices of assets.

samples: numpy.ndarray

Indices of samples.

times: numpy.ndarray

Times of observed events.

property size: int

The number of indices.

Returns

Size of indices array.

Return type

int

number_of_events(sample: int) Tuple[numpy.ndarray, numpy.ndarray][source]

Counts the number of events with respect to times.

Parameters

sample (int) – Index of the sample.

Returns

The ordered times and total number of events as a tuple (times, counts).

Return type

Tuple[ndarray, ndarray]

mean_number_of_events() Tuple[numpy.ndarray, numpy.ndarray][source]

Mean number of events with respect to time.

Returns

The ordered times and mean number of events as a tuple (times, counts).

Return type

Tuple[ndarray, ndarray]

astuple() tuple[source]

Converts the dataclass attributes as a tuple.

class relife.data.RenewalData(T: float, n_indices: int, n_samples: int, indices: numpy.ndarray, samples: numpy.ndarray, times: numpy.ndarray, durations: numpy.ndarray)[source]

Bases: relife.data.CountData

Renewal process data.

Notes

Inherit from CountData and add a durations attribute.

durations: numpy.ndarray

Time between events.

T: float

Time at the end of the observation.

n_indices: int

Number of initial assets.

n_samples: int

Numbers of samples.

indices: numpy.ndarray

Indices of assets.

samples: numpy.ndarray

Indices of samples.

times: numpy.ndarray

Times of observed events.

class relife.data.RenewalRewardData(T: float, n_indices: int, n_samples: int, indices: numpy.ndarray, samples: numpy.ndarray, times: numpy.ndarray, durations: numpy.ndarray, rewards: numpy.ndarray)[source]

Bases: relife.data.RenewalData

Renewal reward process data.

Notes

Inherit from RenewalData and add a rewards attribute.

rewards: numpy.ndarray

Reward associated at each event.

total_reward(sample: int) Tuple[numpy.ndarray, numpy.ndarray][source]

Total reward with respect to time.

Parameters

sample (int) – Index of the sample.

Returns

The ordered times and total rewards as a tuple (times, z).

Return type

Tuple[ndarray, ndarray]

mean_total_reward() Tuple[numpy.ndarray, numpy.ndarray][source]

Mean total reward with respect to time.

Returns

The ordered times and mean total rewards as a tuple (times, z).

Return type

Tuple[ndarray, ndarray]

durations: numpy.ndarray

Time between events.

T: float

Time at the end of the observation.

n_indices: int

Number of initial assets.

n_samples: int

Numbers of samples.

indices: numpy.ndarray

Indices of assets.

samples: numpy.ndarray

Indices of samples.

times: numpy.ndarray

Times of observed events.

class relife.data.ReplacementPolicyData(T: float, n_indices: int, n_samples: int, indices: numpy.ndarray, samples: numpy.ndarray, times: numpy.ndarray, durations: numpy.ndarray, rewards: numpy.ndarray, events: numpy.ndarray, args: numpy.ndarray, a0: numpy.ndarray)[source]

Bases: relife.data.RenewalRewardData

Replacement policy data.

events: numpy.ndarray

Event types.

args: numpy.ndarray

Extra arguments required by the lifetime model.

a0: numpy.ndarray

Age of the assets at the first replacement.

to_lifetime_data(t0: float = 0, tf: Optional[float] = None, sample: Optional[int] = None) relife.data.LifetimeData[source]

Builds a lifetime data sample.

Parameters
  • t0 (float, optional) – Start of the observation period, by default 0.

  • tf (float, optional) – End of the observation period, by default the time at the end of the observation.

  • sample (int, optional) – Index of the sample, by default all sample are mixed.

Returns

The lifetime data sample built from the observation period [t0,tf] of the renewal process.

Return type

LifetimeData

Raises

ValueError – if t0 is greater than tf.

rewards: numpy.ndarray

Reward associated at each event.

durations: numpy.ndarray

Time between events.

T: float

Time at the end of the observation.

n_indices: int

Number of initial assets.

n_samples: int

Numbers of samples.

indices: numpy.ndarray

Indices of assets.

samples: numpy.ndarray

Indices of samples.

times: numpy.ndarray

Times of observed events.

relife.datasets module

Lifetime datasets to load.

relife.datasets.load_power_transformer() relife.data.LifetimeData[source]

Load and return the power transformer lifetime data.

The data were simulated from a real estimate:

  • time: time-to-event or durations in years,

  • event: if a failure occurs during the observation period,

  • entry: age of the power transformers in years at the beginning of the observation period.

Returns

The lifetime data as a dataclass instance.

Return type

LifetimeData

Examples

from relife.datasets import load_power_transformer
time, event, entry = load_power_transformer().astuple()
relife.datasets.load_circuit_breaker() relife.data.LifetimeData[source]

Load and return the circuit breaker lifetime data.

The data were simulated from a real estimate:

  • time: time-to-event or durations in years,

  • event: if a failure occurs during the observation period,

  • entry: age of the circuit breakers in years at the beginning of the observation period.

Returns

The lifetime data as a dataclass instance.

Return type

LifetimeData

Examples

from relife.datasets import load_circuit_breaker
time, event, entry = load_circuit_breaker().astuple()
relife.datasets.load_insulator_string() relife.data.LifetimeData[source]

Load and return the insulator string lifetime data for regression.

The data were simulated from a real estimate:

  • time: time-to-event or durations in years,

  • event: if a failure occurs during the observation period,

  • entry: age of the circuit breakers in years at the beginning of the observation period,

  • args: tuple of covariates related to the atmospheric polluants.

Returns

The lifetime data as a dataclass instance.

Return type

LifetimeData

Examples

import numpy as np
from scipy.stats import boxcox, zscore
from relife.datasets import load_circuit_breaker
time, event, entry, *args = load_insulator_string().astuple()
covar = zscore(np.column_stack([boxcox(col)[0] for col in args[0].T]))

relife.discounting module

Discount functions.

class relife.discounting.Discount[source]

Bases: abc.ABC

Generic discount function.

References

1

Van der Weide, J. A. M., & Van Noortwijk, J. M. (2008). Renewal theory with exponential and hyperbolic discounting. Probability in the Engineering and Informational Sciences, 22(1), 53-74.

abstract classmethod factor(t: numpy.ndarray, *discount_args: numpy.ndarray) numpy.ndarray[source]

The discount factor.

Parameters
  • t (ndarray) – Time.

  • *discount_args (ndarray) – Extra arguments required by the discount model.

Returns

The discount factor evaluated at t.

Return type

ndarray

Notes

The discount factor evaluated at \(t\) that multiplies the reward to get the discounted reward \(D(t) \cdot y\).

abstract classmethod rate(t: numpy.ndarray, *discount_args: numpy.ndarray) numpy.ndarray[source]

The discount rate.

Parameters
  • t (ndarray) – Time.

  • *discount_args (ndarray) – Extra arguments required by the discount model.

Returns

The discount rate evaluated at t.

Return type

ndarray

Notes

The discount rate evaluated at \(t\) is defined by:

\[r(t) = -\dfrac{D'(t)}{D(t)}\]

where \(D\) is the discount factor.

abstract classmethod annuity_factor(t: numpy.ndarray, *discount_args: numpy.ndarray) numpy.ndarray[source]

The annuity factor.

Parameters
  • t (ndarray) – Time.

  • *discount_args (ndarray) – Extra arguments required by the discount model.

Returns

The annuity factor evaluated at t.

Return type

ndarray

Notes

The annuity factor at time \(t\) is defined by:

\[AF(t) = \int_0^t D(x) \mathrm{d}x\]

where \(D\) is the discount factor.

It is used to compute the equivalent annual cost of continuous discounted cash flows over the period \([0, t]\).

class relife.discounting.ExponentialDiscounting[source]

Bases: relife.discounting.Discount

Exponential discounting model.

The exponetial discount factor is:

\[D(x) = e^{-\delta x}\]

where \(\delta\) is the rate.

classmethod factor(t: numpy.ndarray, rate: numpy.ndarray = 0) numpy.ndarray[source]

The discount factor.

Parameters
  • t (ndarray) – Time.

  • *discount_args (ndarray) – Extra arguments required by the discount model.

Returns

The discount factor evaluated at t.

Return type

ndarray

Notes

The discount factor evaluated at \(t\) that multiplies the reward to get the discounted reward \(D(t) \cdot y\).

classmethod rate(t: numpy.ndarray, rate: numpy.ndarray = 0) numpy.ndarray[source]

The discount rate.

Parameters
  • t (ndarray) – Time.

  • *discount_args (ndarray) – Extra arguments required by the discount model.

Returns

The discount rate evaluated at t.

Return type

ndarray

Notes

The discount rate evaluated at \(t\) is defined by:

\[r(t) = -\dfrac{D'(t)}{D(t)}\]

where \(D\) is the discount factor.

classmethod annuity_factor(t: numpy.ndarray, rate: numpy.ndarray = 0) numpy.ndarray[source]

The annuity factor.

Parameters
  • t (ndarray) – Time.

  • *discount_args (ndarray) – Extra arguments required by the discount model.

Returns

The annuity factor evaluated at t.

Return type

ndarray

Notes

The annuity factor at time \(t\) is defined by:

\[AF(t) = \int_0^t D(x) \mathrm{d}x\]

where \(D\) is the discount factor.

It is used to compute the equivalent annual cost of continuous discounted cash flows over the period \([0, t]\).

class relife.discounting.HyperbolicDiscounting[source]

Bases: relife.discounting.Discount

Hyperbolic discounting model.

The hyperbolic discount factor is:

\[D(x) = \dfrac{1}{1 + \beta x}\]

where \(\beta>0\).

classmethod factor(t: numpy.ndarray, beta: numpy.ndarray = 0) numpy.ndarray[source]

The discount factor.

Parameters
  • t (ndarray) – Time.

  • *discount_args (ndarray) – Extra arguments required by the discount model.

Returns

The discount factor evaluated at t.

Return type

ndarray

Notes

The discount factor evaluated at \(t\) that multiplies the reward to get the discounted reward \(D(t) \cdot y\).

classmethod rate(t: numpy.ndarray, beta: numpy.ndarray = 0) numpy.ndarray[source]

The discount rate.

Parameters
  • t (ndarray) – Time.

  • *discount_args (ndarray) – Extra arguments required by the discount model.

Returns

The discount rate evaluated at t.

Return type

ndarray

Notes

The discount rate evaluated at \(t\) is defined by:

\[r(t) = -\dfrac{D'(t)}{D(t)}\]

where \(D\) is the discount factor.

classmethod annuity_factor(t: numpy.ndarray, beta: numpy.ndarray = 0) numpy.ndarray[source]

The annuity factor.

Parameters
  • t (ndarray) – Time.

  • *discount_args (ndarray) – Extra arguments required by the discount model.

Returns

The annuity factor evaluated at t.

Return type

ndarray

Notes

The annuity factor at time \(t\) is defined by:

\[AF(t) = \int_0^t D(x) \mathrm{d}x\]

where \(D\) is the discount factor.

It is used to compute the equivalent annual cost of continuous discounted cash flows over the period \([0, t]\).

class relife.discounting.GeneralizedHyperbolicDiscounting[source]

Bases: relife.discounting.Discount

Generalized hyperbolic discounting model.

The generalized hyperbolic discount factor is:

\[D(x) = \dfrac{1}{(1 + \beta x)^\eta}\]

where \(\beta,\eta >0\).

classmethod factor(t: numpy.ndarray, beta: numpy.ndarray = 0, eta: numpy.ndarray = 1) numpy.ndarray[source]

The discount factor.

Parameters
  • t (ndarray) – Time.

  • *discount_args (ndarray) – Extra arguments required by the discount model.

Returns

The discount factor evaluated at t.

Return type

ndarray

Notes

The discount factor evaluated at \(t\) that multiplies the reward to get the discounted reward \(D(t) \cdot y\).

classmethod rate(t: numpy.ndarray, beta: numpy.ndarray = 0, eta: numpy.ndarray = 1) numpy.ndarray[source]

The discount rate.

Parameters
  • t (ndarray) – Time.

  • *discount_args (ndarray) – Extra arguments required by the discount model.

Returns

The discount rate evaluated at t.

Return type

ndarray

Notes

The discount rate evaluated at \(t\) is defined by:

\[r(t) = -\dfrac{D'(t)}{D(t)}\]

where \(D\) is the discount factor.

classmethod annuity_factor(t: numpy.ndarray, beta: numpy.ndarray = 0, eta: numpy.ndarray = 1) numpy.ndarray[source]

The annuity factor.

Parameters
  • t (ndarray) – Time.

  • *discount_args (ndarray) – Extra arguments required by the discount model.

Returns

The annuity factor evaluated at t.

Return type

ndarray

Notes

The annuity factor at time \(t\) is defined by:

\[AF(t) = \int_0^t D(x) \mathrm{d}x\]

where \(D\) is the discount factor.

It is used to compute the equivalent annual cost of continuous discounted cash flows over the period \([0, t]\).

relife.distribution module

Parametric lifetime distribution.

class relife.distribution.ParametricLifetimeDistribution[source]

Bases: relife.parametric.ParametricLifetimeModel

Generic class for parametric lifetime distribution.

property n_params: int

Number of parameters.

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[source]

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

plot(timeline: Optional[numpy.ndarray] = None, args: Tuple[numpy.ndarray] = (), alpha_ci: float = 0.05, fname: str = 'sf', **kwargs) None[source]

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’.

class relife.distribution.Exponential(rate: Optional[float] = None)[source]

Bases: relife.distribution.ParametricLifetimeDistribution

Exponential parametric lifetime distribution.

The exponential distribution is a 1-parameter distribution with \((\lambda)\). The probability density function is:

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

where:

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

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

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,)
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,)
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.

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.

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,)
class relife.distribution.Gompertz(c: Optional[float] = None, rate: Optional[float] = None)[source]

Bases: relife.distribution.ParametricLifetimeDistribution

Gompertz parametric lifetime distribution.

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

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

where:

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

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

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

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.

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

Bases: relife.distribution.ParametricLifetimeDistribution

Gamma parametric lifetime distribution.

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

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

where:

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

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

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

c: float = None
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,)
var(params: 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,)
class relife.distribution.LogLogistic(c: Optional[float] = None, rate: Optional[float] = None)[source]

Bases: relife.distribution.ParametricLifetimeDistribution

Log-logistic parametric lifetime distribution.

The Log-logistic distribution is defined as a 2-parameter distribution \((c, \lambda)\). The probability density function is:

\[f(t) = \frac{c \lambda^c t^{c-1}}{(1+(\lambda t)^{c})^2}\]

where:

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

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

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

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,)
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,)
class relife.distribution.MinimumDistribution(baseline: relife.distribution.ParametricLifetimeDistribution)[source]

Bases: relife.distribution.ParametricLifetimeDistribution

Series structure of n identical and independent components.

The hazard function of the system is given by:

\[h(t) = n \cdot h_0(t)\]

where \(h_0\) is the baseline hazard function of the components.

Examples

Computing the survival (or reliability) function for 3 structures of 3,6 and 9 identical and idependent components:

model = MinimumDistribution(Weibull(2, 0.05))
t = np.arange(0, 10, 0.1)
n = np.array([3, 6, 9]).reshape(-1, 1)
model.sf(t, n)
baseline: relife.distribution.ParametricLifetimeDistribution

Underlying lifetime model of the components.

property params: numpy.ndarray

Parameters of the hazard functions.

property n_params: int

Number of parameters.

relife.model module

Generic lifetime models.

class relife.model.LifetimeModel[source]

Bases: abc.ABC

Generic lifetime model.

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

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.

class relife.model.AgeReplacementModel(baseline: relife.model.LifetimeModel)[source]

Bases: relife.model.LifetimeModel

Age replacement model.

Lifetime model where the asset is replaced at age ar.

Notes

This is equivalent to the distribution of \(\min(X,a_r)\) where \(X\) is a baseline lifetime model and ar the age of replacement.

baseline: relife.model.LifetimeModel

Underlying lifetime model of the asset.

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

sf(t: numpy.ndarray, ar: 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),)
pdf(t: numpy.ndarray, ar: 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),)
isf(p: numpy.ndarray, ar: 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),)
ls_integrate(func: Callable, a: numpy.ndarray, b: numpy.ndarray, ar: numpy.ndarray, *args: numpy.ndarray, ndim: int = 0, deg: int = 100) 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.

class relife.model.HazardFunctions[source]

Bases: abc.ABC

Generic hazard functions.

Abstract class for the definition of a hazard functions: hazard rate, cumulative hazard function, and inverse cumulative hazard function.

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

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

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

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),)
class relife.model.AbsolutelyContinuousLifetimeModel[source]

Bases: relife.model.LifetimeModel, relife.model.HazardFunctions

Absolutely continuous lifetime model.

Abstract class that implements LifetimeModel with HazardFunctions.

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

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),)
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),)
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),)
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[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.

class relife.model.LeftTruncated(baseline: relife.model.AbsolutelyContinuousLifetimeModel)[source]

Bases: relife.model.AbsolutelyContinuousLifetimeModel

Left truncation of an absolutely continuous lifetime model.

Conditional distribution of the lifetime model for an asset having reach age a0.

baseline: relife.model.AbsolutelyContinuousLifetimeModel

Underlying absolutely continuous lifetime model of the asset.

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

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),)
hf(t: numpy.ndarray, a0: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray[source]

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, a0: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray[source]

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),)
class relife.model.EquilibriumDistribution(baseline: relife.model.LifetimeModel)[source]

Bases: relife.model.AbsolutelyContinuousLifetimeModel

Equilibrium distribution of a lifetime model.

The equilibirum distribution is the distrbution computed from a lifetime model that makes the associated delayed renewal process stationary [1]_.

1

Ross, S. M. (1996). Stochastic processes. New York: Wiley.

baseline: relife.model.LifetimeModel

Underlying lifetime model of the asset.

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

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),)
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),)
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),)
hf(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray[source]

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

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

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),)

relife.nonparametric module

Non-parametric estimator for survival analysis.

class relife.nonparametric.ECDF[source]

Bases: object

Empirical Cumulative Distribution Function.

fit(time: numpy.ndarray) relife.nonparametric.ECDF[source]

Fit the empirical cumuative distribution function.

Parameters

time (1D array) – Failure times.

Returns

Return the fitted empirical estimate as the current object.

Return type

ECDF

plot(alpha_ci: float = 0.05, fname: str = 'cdf', **kwargs: numpy.ndarray) None[source]

Plot the empirical cumulative distribution function.

Parameters
  • 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 ‘cdf’. Should be one of:

    • ’sf’ : survival function,

    • ’cdf’: cumulative distribution function.

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

Raises

ValueError – If fname value is not ‘sf’ or ‘cdf’.

class relife.nonparametric.KaplanMeier[source]

Bases: object

Kaplan-Meier Estimator.

Compute the non-parametric Kaplan-Meier estimator (also known as the product limit estimator) of the survival function from lifetime data.

Notes

For a given time instant \(t\) and \(n\) total observations, this estimator is defined as:

\[\hat{S}(t) = \prod_{i: t_i \leq t} \left( 1 - \frac{d_i}{n_i}\right)\]

where \(d_i\) is the number of failures until \(t_i\) and \(n_i\) is the number of assets at risk just prior to \(t_i\).

The variance estimation is obtained by:

\[\widehat{Var}[\hat{S}(t)] = \hat{S}(t)^2 \sum_{i: t_i \leq t} \frac{d_i}{n_i(n_i - d_i)}\]

which is often referred to as Greenwood’s formula.

References

1

Lawless, J. F. (2011). Statistical models and methods for lifetime data. John Wiley & Sons.

2

Kaplan, E. L., & Meier, P. (1958). Nonparametric estimation from incomplete observations. Journal of the American statistical association, 53(282), 457-481.

fit(time: numpy.ndarray, event: Optional[numpy.ndarray] = None, entry: Optional[numpy.ndarray] = None) relife.nonparametric.KaplanMeier[source]

Fit the Kaplan-Meier estimator to a time, event and entry arrays.

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.

Returns

Return the fitted Kaplan-Meier estimator as the current object.

Return type

KaplanMeier

plot(alpha_ci: float = 0.05, **kwargs) None[source]

Plot the Kaplan-Meier estimator of the survival function.

Parameters
  • 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.

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

class relife.nonparametric.NelsonAalen[source]

Bases: object

Nelson-Aalen Estimator.

Compute the non-parametric Nelson-Aalen estimator of the cumulative hazard function from lifetime data.

Notes

For a given time instant \(t\) and \(n\) total observations, this estimator is defined as:

\[\hat{H}(t) = \sum_{i: t_i \leq t} \frac{d_i}{n_i}\]

where \(d_i\) is the number of failures until \(t_i\) and \(n_i\) is the number of assets at risk just prior to \(t_i\).

The variance estimation is obtained by:

\[\widehat{Var}[\hat{H}(t)] = \sum_{i: t_i \leq t} \frac{d_i}{n_i^2}\]

Note that the alternative survivor function estimate:

\[\tilde{S}(t) = \exp{(-\hat{H}(t))}\]

is sometimes suggested for the continuous-time case.

References

1

Lawless, J. F. (2011). Statistical models and methods for lifetime data. John Wiley & Sons.

fit(time: numpy.ndarray, event: Optional[numpy.ndarray] = None, entry: Optional[numpy.ndarray] = None) relife.nonparametric.NelsonAalen[source]

Fit the Nelson-Aalen estimator 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.

Returns

The fitted Nelson-Aalen estimator as the current object.

Return type

NelsonAalen

plot(alpha_ci: float = 0.05, **kwargs: numpy.ndarray) None[source]

Plot the Nelson-Aalen estimator of the cumulative hazard function.

Parameters
  • 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.

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

relife.parametric module

Generic parametric models.

class relife.parametric.ParametricHazardFunctions[source]

Bases: relife.model.HazardFunctions

Generic parametric hazard functions.

Generic class for the parametric hazard functions with a fitting method based on the maximum likelihood estimator.

abstract property params: numpy.ndarray

Parameters of the hazard functions.

abstract property n_params: int

Number of parameters.

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

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),)
hf(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray[source]

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[source]

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),)
class relife.parametric.FittingResult(opt: scipy.optimize._optimize.OptimizeResult, jac: numpy.ndarray, var: numpy.ndarray, n_samples: int)[source]

Bases: object

Fitting results of the parametric model.

opt: scipy.optimize._optimize.OptimizeResult

Optimization result (see scipy.optimize.OptimizeResult doc).

jac: numpy.ndarray

Jacobian of the negative log-likelihood with the lifetime data.

var: numpy.ndarray

Covariance matrix (computed as the inverse of the Hessian matrix)

se: numpy.ndarray

Standard error, square root of the diagonal of the covariance matrix.

n_samples: int

Number of observations (samples).

n_params: int

Number of parameters.

AIC: float

Akaike Information Criterion.

AICc: float

Akaike Information Criterion with a correction for small sample sizes.

BIC: float

Bayesian Information Criterion.

standard_error(jac_f: numpy.ndarray) numpy.ndarray[source]

Standard error estimation function.

Parameters

jac_f (1D array) – The Jacobian of a function f with respect to params.

Returns

Standard error for f(params).

Return type

1D array

References

1

Meeker, W. Q., Escobar, L. A., & Pascual, F. G. (2022). Statistical methods for reliability data. John Wiley & Sons.

asdict() dict[source]

converts FittingResult into a dictionary.

Returns

Returns the fitting result as a dictionary.

Return type

dict

class relife.parametric.ParametricLifetimeModel[source]

Bases: relife.parametric.ParametricHazardFunctions, relife.model.AbsolutelyContinuousLifetimeModel

Parametric lifetime model.

relife.regression module

Survival regression models.

relife.regression.concordance_index(time: numpy.ndarray, event: numpy.ndarray, score: numpy.ndarray, include_tied_score: bool = True) Tuple[float, int, int, int][source]

Computes the concordance index (c-index).

The concordance index is a metric for evaluating the predictions of a survival regression model. It is the proportion of concordant pairs divided by the total number of possible evaluation pairs.

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

  • event (1D array) –

    Array of event types coded as follows:

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

    • 1 if the event has occured

  • score (1D array) – Vector of individual risk scores (e.g. the median).

  • include_tied_score (bool, optional) – Specifies whether ties in risk score are included in calculations, by default True.

Returns

  • cindex : The computed concordance index (float)

  • concordant : Number of concordant pairs (int)

  • discordant : Number of discordant pairs (int)

  • tied_score : Number of pairs having tied estimated risks (int)

Return type

Tuple[float, int, int, int]

class relife.regression.Regression(baseline: relife.parametric.ParametricLifetimeModel, beta: Optional[numpy.ndarray] = None)[source]

Bases: relife.parametric.ParametricLifetimeModel

Generic regression for parametric lifetime model.

A generic class for survival regression model. The model includes a baseline lifetime model and a multiplier function \(g\) that specifies the effect of the covariates (explanatory variables) on the baseline model:

\[g(\beta, x) = e^{\beta \cdot x}\]
baseline: relife.parametric.ParametricLifetimeModel

Baseline parametric lifetime model for the regression.

beta: numpy.ndarray = None

Coefficients for the covariates.

property params: numpy.ndarray

Parameters of the hazard functions.

property n_params: int

Number of parameters.

fit(time: numpy.ndarray, event: Optional[numpy.ndarray] = None, entry: Optional[numpy.ndarray] = None, covar: Optional[numpy.ndarray] = None, args: numpy.ndarray = (), params0: Optional[numpy.ndarray] = None, method: Optional[str] = None, **kwargs) relife.regression.Regression[source]

Fit the parametric survival regression model 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.

  • covar (2D array) – Array of covariates.

  • args (float or 2D array, optional) – Extra arguments required by the baseline 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.

Returns

Return the fitted regression as the current object.

Return type

self

class relife.regression.RegressionFittingResult(opt: scipy.optimize._optimize.OptimizeResult, jac: numpy.ndarray, var: numpy.ndarray, n_samples: int, cindex: float)[source]

Bases: relife.parametric.FittingResult

Class for the result of the fitted regression, inheriting from FittingResult.

Used as the type for the instance attribute ‘result’ for an object of the Regression class, after fitting.

cindex: float
opt: scipy.optimize._optimize.OptimizeResult

Optimization result (see scipy.optimize.OptimizeResult doc).

jac: numpy.ndarray

Jacobian of the negative log-likelihood with the lifetime data.

var: numpy.ndarray

Covariance matrix (computed as the inverse of the Hessian matrix)

se: numpy.ndarray

Standard error, square root of the diagonal of the covariance matrix.

n_samples: int

Number of observations (samples).

n_params: int

Number of parameters.

AIC: float

Akaike Information Criterion.

AICc: float

Akaike Information Criterion with a correction for small sample sizes.

BIC: float

Bayesian Information Criterion.

class relife.regression.AFT(baseline: relife.parametric.ParametricLifetimeModel, beta: Optional[numpy.ndarray] = None)[source]

Bases: relife.regression.Regression

Accelerated Failure Time Regression Model.

The cumulative hazard function \(H\) is linked to the multiplier function \(g\) by the relation:

\[H(t, x) = H_0\left(\dfrac{t}{g(\beta, x)}\right) = H_0(t e^{- \beta \cdot x})\]

where \(x\) is a vector of covariates, \(\beta\) is the coefficient vector of the effect of covariates, \(H_0\) is the baseline cumulative hazard function.

References

1

Kalbfleisch, J. D., & Prentice, R. L. (2011). The statistical analysis of failure time data. John Wiley & Sons.

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

baseline: relife.parametric.ParametricLifetimeModel

Baseline parametric lifetime model for the regression.

class relife.regression.ProportionalHazards(baseline: relife.parametric.ParametricLifetimeModel, beta: Optional[numpy.ndarray] = None)[source]

Bases: relife.regression.Regression

Parametric Proportional Hazards Regression Model.

The cumulative hazard function \(H\) is linked to the multiplier function \(g\) by the relation:

\[H(t, x) = g(\beta, x) H_0(t) = e^{\beta \cdot x} H_0(t)\]

where \(x\) is a vector of covariates, \(\beta\) is the coefficient vector of the effect of covariates, \(H_0\) is the baseline cumulative hazard function.

References

1

Sun, J. (2006). The statistical analysis of interval-censored failure time data (Vol. 3, No. 1). New York: springer.

baseline: relife.parametric.ParametricLifetimeModel

Baseline parametric lifetime model for the regression.

relife.renewal_process module

Generic renewal processes.

relife.renewal_process.renewal_equation_solver(F: numpy.ndarray, Fm: numpy.ndarray, y: numpy.ndarray, D: Optional[numpy.ndarray] = None) numpy.ndarray[source]

Renewal equation solver.

Parameters
  • F (ndarray) – The cumulative distribution function evaluated at each point of the timeline.

  • Fm (ndarray) – The cumulative distribution function evaluated at each midpoint of the timeline.

  • y (ndarray) – A given function evaluated at each point of the timeline.

  • D (ndarray, optional) – Discount function value at each point of the timeline, by default None.

Returns

Renewal function evaluated at each point of the timeline.

Return type

ndarray

Notes

The timeline must start at 0.

Solve the renewal equation for \(z\), such that for \(t\geq 0\).

\[\begin{split}\begin{aligned} z(t) & = y(t) + \int_0^t z(t-x) D(x) \mathrm{d}F(x) \\ & = y(t) + z \ast F(t) \end{aligned}\end{split}\]

where \(F\) is the cumulative distribution function, \(y\) a function and \(D\) the exponential discounting factor.

References

1

Dragomir, S. S. (2011). Approximating the Riemann–Stieltjes integral by a trapezoidal quadrature rule with applications. Mathematical and computer modelling, 54(1-2), 243-260.

2

Tortorella, M. (2005). Numerical solutions of renewal-type integral equations. INFORMS Journal on Computing, 17(1), 66-74.

relife.renewal_process.delayed_renewal(z: numpy.ndarray, F1: numpy.ndarray, F1m: numpy.ndarray, y1: numpy.ndarray, D: Optional[numpy.ndarray] = None) numpy.ndarray[source]

Add delay for the first renewal to a solution of a renewal equation.

Parameters
  • z (ndarray) – The solution of a renewal equation at each point of the timeline.

  • F1 (ndarray) – The cumulative distribution function of the first renewal evaluated at each point of the timeline.

  • F1m (ndarray) – The cumulative distribution function of the first renewal evaluated at each midpoint of the timeline.

  • y (ndarray) – A given function related to the first renewal evaluated at each point of the timeline.

  • D (ndarray, optional) – Discount function value at each point of the timeline, by default None.

Returns

Delayed solution of the renewal equation at each point of the timeline.

Return type

ndarray

Notes

The solution of the renewal equation is delayed by computing:

\[z_1(t) = y_1(t) + \int_0^t z(t-x) D(x) \mathrm{d}F_1(x)\]

where \(z\) is a solution of a renewal equation, \(D\) the exponential discounting factor, \(F_1\) is the cumulative distribution function of the first renwal and \(y_1\) a function related to the first renewal.

class relife.renewal_process.RenewalProcess(model: relife.model.LifetimeModel, model1: Optional[relife.model.LifetimeModel] = None)[source]

Bases: object

Renewal process.

Creates a renewal process.

Parameters
  • model (LifetimeModel) – A lifetime model representing the durations between events.

  • model1 (LifetimeModel, optional) – A lifetime model for the first renewal (delayed renewal process), by default None.

renewal_function(t: numpy.ndarray, model_args: Tuple[numpy.ndarray, ...] = (), model1_args: Tuple[numpy.ndarray, ...] = ()) numpy.ndarray[source]

The renewal function.

Parameters
  • t (1D array) – Timeline.

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

  • model1_args (Tuple[ndarray,...], optional) – Extra arguments required by the lifetime model of the first renewal, by default ().

Returns

The renewal function evaluated at each point of the timeline.

Return type

ndarray

Notes

The expected total number of renewals is computed by solving the renewal equation:

\[m(t) = F_1(t) + \int_0^t m(t-x) \mathrm{d}F(x)\]

where:

  • \(m\) is the renewal function,

  • \(F\) is the cumulative distribution function of the underlying lifetime model,

  • \(F_1\) is the cumulative distribution function of the underlying lifetime model for the fist renewal in the case of a delayed renewal process.

References

1

Rausand, M., Barros, A., & Hoyland, A. (2020). System Reliability Theory: Models, Statistical Methods, and Applications. John Wiley & Sons.

renewal_density(t: numpy.ndarray, model_args: Tuple[numpy.ndarray, ...] = (), model1_args: Tuple[numpy.ndarray, ...] = ()) numpy.ndarray[source]

The renewal density.

Parameters
  • t (1D array) – Timeline.

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

  • model1_args (Tuple[ndarray,...], optional) – Extra arguments required by the lifetime model of the first renewal, by default ().

Returns

Renewal density evaluated at each point of the timeline.

Return type

ndarray

Raises

NotImplementedError – If the lifetime model is not absolutely continuous.

Notes

The renewal density is the derivative of the renewal function with respect to time. It is computed by solving the renewal equation:

\[\mu(t) = f_1(t) + \int_0^t \mu(t-x) \mathrm{d}F(x)\]

where:

  • \(\mu\) is the renewal function,

  • \(F\) is the cumulative distribution function of the underlying lifetime model,

  • \(f_1\) is the probability density function of the underlying lifetime model for the fist renewal in the case of a delayed renewal process.

References

1

Rausand, M., Barros, A., & Hoyland, A. (2020). System Reliability Theory: Models, Statistical Methods, and Applications. John Wiley & Sons.

sample(T: float, model_args: Tuple[numpy.ndarray, ...] = (), model1_args: Tuple[numpy.ndarray, ...] = (), n_samples: int = 1, random_state: Optional[int] = None) relife.data.RenewalData[source]

Renewal data sampling.

Parameters
  • T (float) – Time at the end of the observation.

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

  • model1_args (Tuple[ndarray,...], optional) – Extra arguments required by the lifetime model of the first renewal, by default ().

  • n_samples (int, optional) – Number of samples, by default 1.

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

Returns

Samples of replacement times and durations.

Return type

RenewalData

class relife.renewal_process.RenewalRewardProcess(model: relife.model.LifetimeModel, reward: relife.reward.Reward, model1: typing.Optional[relife.model.LifetimeModel] = None, reward1: typing.Optional[relife.reward.Reward] = None, discount: relife.discounting.Discount = <relife.discounting.ExponentialDiscounting object>)[source]

Bases: relife.renewal_process.RenewalProcess

Renewal reward process.

Creates a renewal reward process.

Parameters
  • model (LifetimeModel) – A lifetime model representing the durations between events.

  • reward (Reward) – A reward associated to the interarrival time.

  • model1 (LifetimeModel, optional) – A lifetime model for the first renewal (delayed renewal process), by default None.

  • reward1 (Reward, optional) – A reward associated to the first renewal, by default None

  • discount (Discount, optional) – A discount function related to the rewards, by default ExponentialDiscounting()

expected_total_reward(t: numpy.ndarray, model_args: Tuple[numpy.ndarray, ...] = (), reward_args: Tuple[numpy.ndarray, ...] = (), model1_args: Tuple[numpy.ndarray, ...] = (), reward1_args: Tuple[numpy.ndarray, ...] = (), discount_args: Tuple[numpy.ndarray, ...] = ()) numpy.ndarray[source]

The expected total reward.

Parameters
  • t (1D array) – Timeline.

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

  • reward_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward, by default ().

  • model1_args (Tuple[ndarray,...], optional) – Extra arguments required by the lifetime model of the first renewal, by default ().

  • reward1_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward of the first renewal, by default ().

  • discount_args (Tuple[ndarray,...], optional) – Extra arguments required by the discount function, by default ().

Returns

Expected total reward of process evaluated at each point of the timeline.

Return type

ndarray

Raises

NotImplementedError – If the discount function is not exponential.

Notes

The renewal equation solved by the expected reward is:

\[z(t) = \int_0^t E[Y | X = x] D(x) \mathrm{d}F(x) + \int_0^t z(t-x) D(x)\mathrm{d}F(x)\]

where:

  • \(z\) is the expected total reward,

  • \(F\) is the cumulative distribution function of the underlying lifetime model,

  • \(X\) the interarrival random variable,

  • \(Y\) the associated reward,

  • \(D\) the exponential discount factor.

If the renewal reward process is delayed, the expected total reward is modified as:

\[z_1(t) = \int_0^t E[Y_1 | X_1 = x] D(x) \mathrm{d}F_1(x) + \int_0^t z(t-x) D(x) \mathrm{d}F_1(x)\]

where:

  • \(z_1\) is the expected total reward with delay,

  • \(F_1\) is the cumulative distribution function of the lifetime model for the first renewal,

  • \(X_1\) the interarrival random variable of the first renewal,

  • \(Y_1\) the associated reward of the first renewal,

expected_equivalent_annual_worth(t: numpy.ndarray, model_args: Tuple[numpy.ndarray, ...] = (), reward_args: Tuple[numpy.ndarray, ...] = (), model1_args: Tuple[numpy.ndarray, ...] = (), reward1_args: Tuple[numpy.ndarray, ...] = (), discount_args: Tuple[numpy.ndarray, ...] = ()) numpy.ndarray[source]

Expected equivalent annual worth.

Gives the equivalent annual worth of the expected total reward of the process at each point of the timeline.

Parameters
  • t (1D array) – Timeline.

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

  • reward_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward, by default ().

  • model1_args (Tuple[ndarray,...], optional) – Extra arguments required by the lifetime model of the first renewal, by default ().

  • reward1_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward of the first renewal, by default ().

  • discount_args (Tuple[ndarray,...], optional) – Extra arguments required by the discount function, by default ().

Returns

The expected equivalent annual worth evaluated at each point of the timeline.

Return type

ndarray

Notes

The equivalent annual worth at time \(t\) is equal to the expected total reward \(z\) divided by the annuity factor \(AF(t)\).

asymptotic_expected_total_reward(model_args: Tuple[numpy.ndarray, ...] = (), reward_args: Tuple[numpy.ndarray, ...] = (), model1_args: Tuple[numpy.ndarray, ...] = (), reward1_args: Tuple[numpy.ndarray, ...] = (), discount_args: Tuple[numpy.ndarray, ...] = ()) numpy.ndarray[source]

Asymptotic expected total reward.

Parameters
  • model_args (Tuple[ndarray,...], optional) – Extra arguments required by the underlying lifetime model, by default ().

  • reward_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward, by default ().

  • model1_args (Tuple[ndarray,...], optional) – Extra arguments required by the lifetime model of the first renewal, by default ().

  • reward1_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward of the first renewal, by default ().

  • discount_args (Tuple[ndarray,...], optional) – Extra arguments required by the discount function, by default ().

Returns

The assymptotic expected total reward of the process.

Return type

ndarray

Raises

NotImplementedError – If the discount function is not exponential.

Notes

The asymptotic expected total reward is:

\[z^\infty = \lim_{t\to \infty} z(t) = \dfrac{E[Y D(X)]}{1-E[D(X)]}\]

where:

  • \(X\) the interarrival random variable,

  • \(Y\) the associated reward,

  • \(D\) the exponential discount factor.

If the renewal reward process is delayed, the asymptotic expected total reward is modified as:

\[z_1^\infty = E[Y_1 D(X_1)] + z^\infty E[D(X_1)]\]

where:

  • \(X_1\) the interarrival random variable of the first renewal,

  • \(Y_1\) the associated reward of the first renewal,

asymptotic_expected_equivalent_annual_worth(model_args: Tuple[numpy.ndarray, ...] = (), reward_args: Tuple[numpy.ndarray, ...] = (), model1_args: Tuple[numpy.ndarray, ...] = (), reward1_args: Tuple[numpy.ndarray, ...] = (), discount_args: Tuple[numpy.ndarray, ...] = ()) numpy.ndarray[source]

Asymptotic expected equivalent annual worth.

Parameters
  • model_args (Tuple[ndarray,...], optional) – Extra arguments required by the underlying lifetime model, by default ().

  • reward_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward, by default ().

  • model1_args (Tuple[ndarray,...], optional) – Extra arguments required by the lifetime model of the first renewal, by default ().

  • reward1_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward of the first renewal, by default ().

  • discount_args (Tuple[ndarray,...], optional) – Extra arguments required by the discount function, by default ().

Returns

The asymptotic expected equivalent annual worth of the process.

Return type

ndarray

Raises

NotImplementedError – If the discount function is not exponential.

sample(T: float, model_args: Tuple[numpy.ndarray, ...] = (), reward_args: Tuple[numpy.ndarray, ...] = (), model1_args: Tuple[numpy.ndarray, ...] = (), reward1_args: Tuple[numpy.ndarray, ...] = (), discount_args: Tuple[numpy.ndarray, ...] = (), n_samples: int = 1, random_state: Optional[int] = None) relife.data.RenewalRewardData[source]

Renewal reward data sampling.

Parameters
  • T (float) – Time at the end of the observation.

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

  • reward_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward, by default ().

  • model1_args (Tuple[ndarray,...], optional) – Extra arguments required by the lifetime model of the first renewal, by default ().

  • reward1_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward of the first renewal, by default ().

  • discount_args (Tuple[ndarray,...], optional) – Extra arguments required by the discount function, by default ().

  • n_samples (int, optional) – Number of samples, by default 1.

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

Returns

Samples of replacement times, durations and rewards.

Return type

RenewalRewardData

relife.replacement_policy module

Run-to-failure and age replacement maintenance policies.

class relife.replacement_policy.OneCycleRunToFailure(model: relife.model.AbsolutelyContinuousLifetimeModel, args: Tuple[numpy.ndarray, ...] = (), a0: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, rate: numpy.ndarray = 0)[source]

Bases: object

One cyle run-to-failure policy.

One cycle run-to-failure policy.

Parameters
  • model (AbsolutelyContinuousLifetimeModel) – Absolutely continuous lifetime model of the asset.

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

  • a0 (float or 2D array, optional) – Current ages of the assets, by default 0 for each asset.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default 0.

Notes

If cf is set to None, if should be defined when using methods to compute costs.

If cf and rate are 2D or 3D array, then:

  • axis=-2 represents the indices of each asset,

  • axis=-3 represents the indices of each component of the cost vector.

References

1

Coolen-Schrijner, P., & Coolen, F. P. A. (2006). On optimality criteria for age replacement. Proceedings of the Institution of Mechanical Engineers, Part O: Journal of Risk and Reliability, 220(1), 21-29

reward: relife.reward.FailureCost = <relife.reward.FailureCost object>

The failure cost of the asset.

discount: relife.discounting.ExponentialDiscounting = <relife.discounting.ExponentialDiscounting object>

Exponential discounting.

rrp_args(cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) Tuple[Tuple[numpy.ndarray, ...], ...][source]

Arguments of the underlying renewal reward process.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

(model_args, reaward_args, discount_args)

Return type

Tuple[Tuple[ndarray,…],…]

Notes

If an argument is None, the value of the class attribute is taken.

expected_total_cost(t: numpy.ndarray, cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The expected total discounted cost.

Parameters
  • t (1D array) – Timeline.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The cumulative expected total cost for each asset along the timeline.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

asymptotic_expected_total_cost(cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The asymptotic expected total cost.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The asymptotic expected total cost for each asset.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

expected_equivalent_annual_cost(t: numpy.ndarray, cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, dt: float = 1.0) numpy.ndarray[source]

The expected equivalent annual cost.

Parameters
  • t (1D array) – Timeline.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • dt (float, optional) – The length of the first period before discounting, by default 1.

Returns

The expected equivalent annual cost until time t.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

The expected equivalent annual cost until time \(t\) is given by:

\[EEAC(t) = \int_0^t \frac{\delta c_f e^{-\delta x}}{1 - e^{-\delta x}} \mathrm{d}F(x)\]
asymptotic_expected_equivalent_annual_cost(cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, dt: float = 1.0) numpy.ndarray[source]

The asymptotic expected equivalent annual cost.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • dt (float, optional) – The length of the first period before discounting, by default 1.

Returns

The asymptotic expected equivalent annual cost.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

The asymptotic expected equivalent annual cost is:

\[EEAC_\infty = \int_0^\infty \frac{\delta c_f e^{-\delta x}}{1 - e^{-\delta x}} \mathrm{d}F(x)\]
sample(cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, n_samples: int = 1, random_state: Optional[int] = None) relife.data.ReplacementPolicyData[source]

One cycle run-to-failure policy sampling.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • n_samples (int, optional) – Number of samples, by default 1.

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

Returns

Samples of replacement times, durations, costs and events for each asset.

Return type

ReplacementPolicyData

Notes

If an argument is None, the value of the class attribute is taken.

class relife.replacement_policy.OneCycleAgeReplacementPolicy(model: relife.model.AbsolutelyContinuousLifetimeModel, args: Tuple[numpy.ndarray, ...] = (), a0: Optional[numpy.ndarray] = None, ar: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: numpy.ndarray = 0)[source]

Bases: object

One-cyle age replacement policy.

The asset is disposed at a fixed age ar with costs cp or upon failure with costs cf if earlier.

One-cyle age replacement policy.

Parameters
  • model (AbsolutelyContinuousLifetimeModel) – Absolutely continuous lifetime model of the asset.

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

  • a0 (float or 2D array, optional) – Current ages of the assets, by default 0 for each asset.

  • ar (float, 2D array, optional) – Ages of preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default 0.

Notes

If ar, cf or cp is set to None, the argument should be defined when using methods to compute costs.

If cf, cp and rate are 2D or 3D array, then:

  • axis=-2 represents the indices of each asset,

  • axis=-3 represents the indices of each component of the cost vector.

References

1

Coolen-Schrijner, P., & Coolen, F. P. A. (2006). On optimality criteria for age replacement. Proceedings of the Institution of Mechanical Engineers, Part O: Journal of Risk and Reliability, 220(1), 21-29

reward: relife.reward.AgeReplacementCost = <relife.reward.AgeReplacementCost object>

Costs of the replacement.

discount: relife.discounting.ExponentialDiscounting = <relife.discounting.ExponentialDiscounting object>

Exponential discounting.

rrp_args(ar: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) Tuple[Tuple[numpy.ndarray, ...], ...][source]

Arguments of the underlying renewal reward process.

Parameters
  • ar (float or 2D array, optional) – Ages of preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

(model_args, reaward_args, discount_args)

Return type

Tuple[Tuple[ndarray,…],…]

Notes

If an argument is None, the value of the class attribute is taken.

classmethod optimal_replacement_age(model: relife.model.AbsolutelyContinuousLifetimeModel, cf: numpy.ndarray, cp: numpy.ndarray, rate: numpy.ndarray = 0, args: Tuple[numpy.ndarray, ...] = ()) numpy.ndarray[source]

Compute the optimal age of preventive replacement for each asset.

The optimal age of preventive replacement is computed by minimizing the asymptotic expected equivalent annual cost on one-cycle.

Parameters
  • model (AbsolutelyContinuousLifetimeModel) – Absolutely continuous lifetime model.

  • cf (float, 2D array or 3D array) – Costs of failures.

  • cp (float, 2D array or 3D array) – Costs of preventive replacements.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default 0.

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

Returns

The optimal age of preventive replacement.

Return type

ndarray

Notes

The optimal age of replacement minimizes the asymptotic expected equivalent annual cost:

\[EEAC_\infty(a) = \sum_i {c_f}_i \int_0^a \dfrac{\delta_i e^{-\delta_i t}}{1 - e^{-\delta_i t}} f(t) \mathrm{d}t + {c_p}_i S(a)\dfrac{\delta_i e^{-\delta_i a}}{1 - e^{-\delta_i a}}\]

where:

  • \(a\) is the age of replacement,

  • \({c_f}_i, {c_p}_i, \delta_i\) are respectively the components of the failures costs, preventive costs and the associated discount rate,

  • \(S, f, h\) are respectively the survival function, the probability density function and the hazard function of the underlying lifetime model.

The optimal age of replacement is then solution of the equation:

\[\sum_i \dfrac{\delta_i e^{-\delta_i a}}{1 - e^{-\delta_i a}} \left( ({c_f}_i - {c_p}_i) h(a) - \dfrac{\delta_i {c_p}_i}{1 - e^{-\delta_i a}} \right) = 0\]
fit(cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) relife.replacement_policy.OneCycleAgeReplacementPolicy[source]

Computes and sets the optimal age of replacement for each asset.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The fitted policy as the current object.

Return type

self

Notes

If an argument is None, the value of the class attribute is taken.

expected_total_cost(t: numpy.ndarray, ar: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The expected total discounted cost.

Parameters
  • t (1D array) – Timeline.

  • ar (float or 2D array, optional) – Ages of replacement, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The cumulative expected total cost for each asset along the timeline.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

asymptotic_expected_total_cost(ar: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The asymptotic expected total cost.

Parameters
  • ar (float or 2D array, optional) – Ages of preventive replacement, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The asymptotic expected total cost for each asset.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

expected_equivalent_annual_cost(t: numpy.ndarray, ar: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, dt: float = 1.0) numpy.ndarray[source]

The expected equivalent annual cost.

Parameters
  • t (1D array) – Timeline.

  • ar (float or 2D array, optional) – Ages of preventive replacement, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • dt (float, optional) – The length of the first period before discounting, by default 1.

Returns

The cumulative expected equivalent annual cost until time t.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

The expected equivalent annual cost until time \(t\) is:

\[EEAC(t) = \int_0^t \frac{\delta c_f e^{-\delta x}}{1 - e^{-\delta x}} \mathrm{d}F(x)\]
asymptotic_expected_equivalent_annual_cost(ar: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, dt: float = 1.0) numpy.ndarray[source]

The asymptotic expected equivalent annual cost.

Parameters
  • ar (float or 2D array, optional) – Ages of preventive replacement, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • dt (float, optional) – The length of the first period before discounting, by default 1.

Returns

The asymptotic expected equivalent annual cost.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

The asymptotic expected equivalent annual cost is:

\[EEAC_\infty = \int_0^\infty \frac{\delta c_f e^{-\delta x}}{1 - e^{-\delta x}} \mathrm{d}F(x)\]
sample(ar: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, n_samples: int = 1, random_state: Optional[int] = None) relife.data.ReplacementPolicyData[source]

One-cycle age replacement policy sampling.

Parameters
  • ar (float or 2D array, optional) – Ages of preventive replacement, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • n_samples (int, optional) – Number of samples, by default 1.

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

Returns

Samples of replacement times, durations, costs and events for each asset.

Return type

ReplacementPolicyData

Notes

If an argument is None, the value of the class attribute is taken.

class relife.replacement_policy.RunToFailure(model: relife.model.AbsolutelyContinuousLifetimeModel, args: Tuple[numpy.ndarray, ...] = (), a0: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, rate: numpy.ndarray = 0)[source]

Bases: object

Run-to-failure renewal policy.

Run-to-failure renwal policy.

Renewal reward process where assets are replaced on failure with costs cf.

Parameters
  • model (AbsolutelyContinuousLifetimeModel) – Absolutely continuous lifetime model of the asset.

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

  • a0 (float or 2D array, optional) – Current ages of the assets, by default 0 for each asset.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default 0.

Notes

If cf is set to None, if should be defined when using methods to compute costs.

If cf and rate are 2D or 3D array, then:

  • axis=-2 represents the indices of each asset,

  • axis=-3 represents the indices of each component of the cost vector.

References

1

Van der Weide, J. A. M., & Van Noortwijk, J. M. (2008). Renewal theory with exponential and hyperbolic discounting. Probability in the Engineering and Informational Sciences, 22(1), 53-74.

reward: relife.reward.FailureCost = <relife.reward.FailureCost object>

The failure cost of the asset.

discount: relife.discounting.ExponentialDiscounting = <relife.discounting.ExponentialDiscounting object>

Exponential discounting.

rrp_args(cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) Tuple[Tuple[numpy.ndarray, ...], ...][source]

Arguments of the underlying renewal reward process.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

(model_args, reward_args, model1_args, reward1_args, discount_args)

Return type

Tuple[Tuple[ndarray,…],…]

Notes

If an argument is None, the value of the class attribute is taken.

expected_total_cost(t: numpy.ndarray, cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The expected total discounted cost.

The expected total discounted cost is computed by solving the renewal equation.

Parameters
  • t (1D array) – Timeline.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The cumulative expected total cost for each asset along the timeline.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

asymptotic_expected_total_cost(cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The asymptotic expected total cost.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The asymptotic expected total cost for each asset.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

expected_equivalent_annual_cost(t: numpy.ndarray, cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The expected equivalent annual cost.

where \(z\) is the expected total cost.

Parameters
  • t (1D array) – Timeline.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The expected equivalent annual cost for each asset along the timeline.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

The expected equivalent annual cost at time \(t\) is:

\[EEAC(t) = \dfrac{\delta z(t)}{1 - e^{-\delta t}}\]
asymptotic_expected_equivalent_annual_cost(cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The asymptotic expected equivalent annual cost.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The asymptotic expected equivalent annual cost for each asset.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

The asymptotic expected equivalent annual cost is:

\[EEAC_\infty = \lim_{t \to \infty} EEAC(t)\]
sample(T: float, cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, n_samples: int = 1, random_state: Optional[int] = None) relife.data.ReplacementPolicyData[source]

Run-to-failure renewal policy sampling.

Parameters
  • T (float) – End of the observation period.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • n_samples (int, optional) – Number of samples, by default 1.

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

Returns

Samples of replacement times, durations, costs and events for each asset.

Return type

ReplacementPolicyData

Notes

If an argument is None, the value of the class attribute is taken.

class relife.replacement_policy.AgeReplacementPolicy(model: relife.model.AbsolutelyContinuousLifetimeModel, args: Tuple[numpy.ndarray, ...] = (), a0: Optional[numpy.ndarray] = None, ar: Optional[numpy.ndarray] = None, ar1: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: numpy.ndarray = 0)[source]

Bases: object

Time based replacement policy.

Age replacement renewal policy.

Renewal reward process where assets are replaced at a fixed age ar with costs cp or upon failure with costs cf if earlier.

Parameters
  • model (AbsolutelyContinuousLifetimeModel) – Absolutely continuous lifetime model of the asset.

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

  • a0 (float or 2D array, optional) – Current ages of the assets, by default 0 for each asset.

  • ar (float, 2D array, optional) – Ages of preventive replacements, by default None.

  • ar1 (float, 2D array, optional) – Ages of the first preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default 0.

Notes

If ar, ar1, cf or cp is set to None, the argument should be defined when using methods to compute costs.

If cf, cp and rate are 2D or 3D array, then:

  • axis=-2 represents the indices of each asset,

  • axis=-3 represents the indices of each component of the cost vector.

References

1

Mazzuchi, T. A., Van Noortwijk, J. M., & Kallen, M. J. (2007). Maintenance optimization. Encyclopedia of Statistics in Quality and Reliability, 1000-1008.

reward: relife.reward.AgeReplacementCost = <relife.reward.AgeReplacementCost object>

Costs of the replacement.

discount: relife.discounting.ExponentialDiscounting = <relife.discounting.ExponentialDiscounting object>

Exponential discounting.

rrp_args(ar: Optional[numpy.ndarray] = None, ar1: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) Tuple[Tuple[numpy.ndarray, ...], ...][source]

Arguments of the underlying renewal reward process.

Parameters
  • ar (float, 2D array, optional) – Ages of preventive replacements, by default None.

  • ar1 (float, 2D array, optional) – Ages of the first preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default 0.

Returns

(model_args, reward_args, model1_args, reward1_args, discount_args)

Return type

Tuple[Tuple[ndarray,…],…]

Notes

If an argument is None, the value of the class attribute is taken.

classmethod optimal_replacement_age(model: relife.model.AbsolutelyContinuousLifetimeModel, cf: numpy.ndarray, cp: numpy.ndarray, rate: numpy.ndarray = 0, args: Tuple[numpy.ndarray, ...] = ()) numpy.ndarray[source]

Compute the optimal age of preventive replacement for each asset.

The optimal age of preventive replacement is computed by minimizing the asymptotic expected equivalent annual cost of the renewal reward process.

Parameters
  • model (AbsolutelyContinuousLifetimeModel) – Absolutely continuous lifetime model.

  • cf (float, 2D array or 3D array) – Costs of failures.

  • cp (float, 2D array or 3D array) – Costs of preventive replacements.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default 0.

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

Returns

The optimal age of preventive replacement.

Return type

ndarray

Notes

The optimal age of replacement minimizes the asymptotic expected equivalent annual cost:

\[EEAC_\infty(a) = \sum_i \dfrac{{c_f}_i \int_0^a e^{-\delta_i x} f(x) \mathrm{d}x + {c_p}_i e^{-\delta_i a} S(a)}{\int_0^a e^{-\delta_i x} S(x) \mathrm{d}x}\]

where:

  • \(a\) is the age of replacement,

  • \({c_f}_i, {c_p}_i, \delta_i\) are respectively the components of the failures costs, preventive costs and the associated discount rate,

  • \(S, f, h\) are respectively the survival function, the probability density function and the hazard function of the underlying lifetime model.

The optimal age of replacement is then solution of the equation:

\[\sum_i \dfrac{\left( ({c_f}_i - {c_p}_i) \left( h(a) \int_0^a e^{-\delta_i x} S(x) \mathrm{d}x - \int_0^a e^{-\delta_i x} f(x) \mathrm{d}x \right) - {c_p}_i \right)} {\left( \int_0^a e^{-\delta_i x} S(x) \mathrm{d}x \right)^2} = 0\]
fit(cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, fit_ar1: bool = True) relife.replacement_policy.AgeReplacementPolicy[source]

Computes and sets the optimal age of replacement for each asset.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • fit_ar1 (bool, optional) – If True, computes and sets the optimal age of replacement for the first replacement considering a one-cycle age replacement criteria.

Returns

The fitted policy as the current object.

Return type

self

Notes

If an argument is None, the value of the class attribute is taken.

expected_total_cost(t: numpy.ndarray, ar: Optional[numpy.ndarray] = None, ar1: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The expected total discounted cost.

The expected total discounted cost is computed by solving the renewal equation.

Parameters
  • t (1D array) – Timeline.

  • ar (float or 2D array, optional) – Ages of replacement, by default None.

  • ar1 (float, 2D array, optional) – Ages of the first preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The cumulative expected total cost for each asset along the timeline.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

asymptotic_expected_total_cost(ar: Optional[numpy.ndarray] = None, ar1: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The asymptotic expected total cost.

Parameters
  • ar (float or 2D array, optional) – Ages of preventive replacement, by default None.

  • ar1 (float, 2D array, optional) – Ages of the first preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The asymptotic expected total cost for each asset.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

expected_equivalent_annual_cost(t: numpy.ndarray, ar: Optional[numpy.ndarray] = None, ar1: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The expected equivalent annual cost.

Parameters
  • t (1D array) – Timeline.

  • ar (float or 2D array, optional) – Ages of replacement, by default None.

  • ar1 (float, 2D array, optional) – Ages of the first preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The expected equivalent annual cost for each asset along the timeline.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

The expected equivalent annual cost at time \(t\) is:

\[EEAC(t) = \dfrac{\delta z(t)}{1 - e^{-\delta t}}\]

where \(z\) is the expected total cost.

asymptotic_expected_equivalent_annual_cost(ar: Optional[numpy.ndarray] = None, ar1: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The asymptotic expected equivalent annual cost.

Parameters
  • ar (float or 2D array, optional) – Ages of replacement, by default None.

  • ar1 (float, 2D array, optional) – Ages of the first preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The asymptotic expected equivalent annual cost for each asset.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

The asymptotic expected equivalent annual cost is:

\[EEAC_\infty = \lim_{t \to \infty} EEAC(t)\]
sample(T: float, ar: Optional[numpy.ndarray] = None, ar1: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, n_samples: int = 1, random_state: Optional[int] = None) relife.data.ReplacementPolicyData[source]

Age replacement renewal policy sampling.

Parameters
  • T (float) – End of the observation period.

  • ar (float or 2D array, optional) – Ages of replacement, by default None.

  • ar1 (float, 2D array, optional) – Ages of the first preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • n_samples (int, optional) – Number of samples, by default 1.

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

Returns

Samples of replacement times, durations, costs and events for each asset.

Return type

ReplacementPolicyData

Notes

If an argument is None, the value of the class attribute is taken.

relife.reward module

Rewards for renewal reward processes.

class relife.reward.Reward[source]

Bases: abc.ABC

Generic reward class.

abstract conditional_expectation(x: numpy.ndarray, *reward_args: numpy.ndarray) numpy.ndarray[source]

Conditional expected reward.

Parameters
  • x (ndarray) – Duration.

  • *reward_args (ndarray) – Extra arguments of the reward random variable.

Returns

The conditional expected reward with respect to the duration.

Return type

ndarray

sample(x: numpy.ndarray, *reward_args: numpy.ndarray) numpy.ndarray[source]

Reward conditional sampling.

Parameters
  • x (ndarray) – Duration.

  • *reward_args (ndarray) – Extra arguments of the reward random variable.

Returns

Random drawing of a reward with respect to the duration.

Return type

ndarray

class relife.reward.FailureCost[source]

Bases: relife.reward.Reward

Run-to-failure costs.

The replacements occur upon failures with costs cf.

conditional_expectation(x: numpy.ndarray, cf: numpy.ndarray) numpy.ndarray[source]

Conditional expected reward.

Parameters
  • x (ndarray) – Duration.

  • *reward_args (ndarray) – Extra arguments of the reward random variable.

Returns

The conditional expected reward with respect to the duration.

Return type

ndarray

class relife.reward.AgeReplacementCost[source]

Bases: relife.reward.Reward

Age replacement costs.

The replacements occur at a fixed age ar with preventive costs cp or upon failure with failure costs cf if earlier.

conditional_expectation(x: numpy.ndarray, ar: numpy.ndarray, cf: numpy.ndarray, cp: numpy.ndarray) numpy.ndarray[source]

Conditional expected reward.

Parameters
  • x (ndarray) – Duration.

  • *reward_args (ndarray) – Extra arguments of the reward random variable.

Returns

The conditional expected reward with respect to the duration.

Return type

ndarray

relife.utils module

Numerical integration, args manipulation, plot, etc.

relife.utils.gauss_legendre(func: Callable, a: numpy.ndarray, b: numpy.ndarray, *args: numpy.ndarray, ndim: int = 0, deg: int = 100) numpy.ndarray[source]

Gauss-Legendre integration.

Parameters
  • func (Callable) – The function to be integrated.

  • a (float or ndarray.) – The lower bound of integration.

  • b (float or 1D array.) – The upper bound of integration.

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

  • ndim (int, optional) – Number of dimensions of the func, by default 0.

  • deg (int, optional) – Degree of the Legendre polynomials (see numpy.polynomial.legendre.leggauss documentation), by default 100.

Returns

The numerical integration of func from a to b.

Return type

ndarray

Notes

It is a numerical integration of:

\[\int_a^b f(x) \mathrm{d} x\]
relife.utils.gauss_laguerre(func: Callable, *args: numpy.ndarray, ndim: int = 0, deg: int = 100) numpy.ndarray[source]

Gauss-Laguerre integration.

Parameters
  • func (Callable) – The function to be integrated.

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

  • ndim (int, optional) – Number of dimensions of the func, by default 0.

  • deg (int) – Degree of the Laguerre polynomials (see numpy.polynomial.laguerre.laggauss documentation), by default 100.

Returns

The Gauss-Laguerre integration of the function func.

Return type

ndarray

Notes

It is the numerical integration of:

\[\int_0^{+\infty} f(x) e^{-x} \mathrm{d} x\]
relife.utils.shifted_laguerre(func: Callable, a: numpy.ndarray, *args: numpy.ndarray, ndim: int = 0, deg: int = 100) numpy.ndarray[source]

Shifted Gauss-Laguerre integration.

Parameters
  • func (Callable) – The function to be integrated.

  • a (float or ndarray) – The lower bound of integration.

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

  • ndim (int, optional) – Number of dimensions of the func, by default 0.

  • deg (int) – Degree of the Laguerre polynomials (see numpy.polynomial.laguerre.laggauss documentation), by default 100.

Returns

The Gauss-Laguerre integration of the function func from a to infinity.

Return type

ndarray

Notes

It is the numerical integration of:

\[\int_a^{+\infty} f(x) e^{-x} \mathrm{d} x\]
relife.utils.quad_laguerre(func: Callable, a: numpy.ndarray, *args: numpy.ndarray, ndim: int = 0, deg: int = 100) numpy.ndarray[source]

Numerical integration over the interval [a,inf].

Parameters
  • func (Callable) – The function to be integrated.

  • a (float or ndarray) – The lower bound of integration.

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

  • ndim (int, optional) – Number of dimensions of the func, by default 0.

  • deg (int, optional) – Degree of the Laguerre polynomials (see numpy.polynomial.laguerre.laggauss documentation), by default 100.

Returns

Numerical integration of func over the interval [a,inf].

Return type

ndarray

Notes

The numerical integration using Gauss-Laguerre quadrature of:

\[\int_a^{+\infty} f(x) \mathrm{d} x\]
relife.utils.args_size(*args) int[source]

Number of elements on axis=-2.

Parameters

*args (float or 2D array) – Sequence of arrays.

Returns

The number of elements.

Return type

int

Raises

ValueError – If args have not same size on axis=-2.

relife.utils.args_ndim(*args) int[source]

Max number of array dimension in args.

Parameters

*args (float or ndarray) – Sequence of arrays.

Returns

Maximum number of array dimension in args.

Return type

int

relife.utils.args_take(indices: numpy.ndarray, *args) Tuple[numpy.ndarray, ...][source]

Take elements in each array of args on axis=-2.

Parameters
  • indices (ndarray) – The indices of the values to extract for each array.

  • *args (float or 2D array) – Sequence of arrays.

Returns

The tuple of arrays where values at indices are extracted.

Return type

Tuple[ndarray, …]

relife.utils.plot(x: numpy.ndarray, y: numpy.ndarray, se: Optional[numpy.ndarray] = None, alpha_ci: float = 0.05, bounds=(- inf, inf), **kwargs) None[source]

Plot a function with a confidence interval.

Parameters
  • x (1D array) – x-axis values.

  • y (np.ndarray) – y-axis values.

  • se (np.ndarray, optional) – The standard error, by default None.

  • 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 se is None, no confidence interval is plotted, by default 0.05.

  • bounds (tuple, optional) – Bounds for clipping the value of the confidence interval, by default (-np.inf, np.inf).

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

Module contents

The relife package.

class relife.AgeReplacementModel(baseline: relife.model.LifetimeModel)[source]

Bases: relife.model.LifetimeModel

Age replacement model.

Lifetime model where the asset is replaced at age ar.

Notes

This is equivalent to the distribution of \(\min(X,a_r)\) where \(X\) is a baseline lifetime model and ar the age of replacement.

baseline: relife.model.LifetimeModel

Underlying lifetime model of the asset.

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

sf(t: numpy.ndarray, ar: 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),)
pdf(t: numpy.ndarray, ar: 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),)
isf(p: numpy.ndarray, ar: 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),)
ls_integrate(func: Callable, a: numpy.ndarray, b: numpy.ndarray, ar: numpy.ndarray, *args: numpy.ndarray, ndim: int = 0, deg: int = 100) 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.

class relife.LeftTruncated(baseline: relife.model.AbsolutelyContinuousLifetimeModel)[source]

Bases: relife.model.AbsolutelyContinuousLifetimeModel

Left truncation of an absolutely continuous lifetime model.

Conditional distribution of the lifetime model for an asset having reach age a0.

baseline: relife.model.AbsolutelyContinuousLifetimeModel

Underlying absolutely continuous lifetime model of the asset.

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

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),)
hf(t: numpy.ndarray, a0: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray[source]

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, a0: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray[source]

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),)
class relife.EquilibriumDistribution(baseline: relife.model.LifetimeModel)[source]

Bases: relife.model.AbsolutelyContinuousLifetimeModel

Equilibrium distribution of a lifetime model.

The equilibirum distribution is the distrbution computed from a lifetime model that makes the associated delayed renewal process stationary [1]_.

1

Ross, S. M. (1996). Stochastic processes. New York: Wiley.

baseline: relife.model.LifetimeModel

Underlying lifetime model of the asset.

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

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),)
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),)
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),)
hf(t: numpy.ndarray, *args: numpy.ndarray) numpy.ndarray[source]

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

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

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),)
class relife.Exponential(rate: Optional[float] = None)[source]

Bases: relife.distribution.ParametricLifetimeDistribution

Exponential parametric lifetime distribution.

The exponential distribution is a 1-parameter distribution with \((\lambda)\). The probability density function is:

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

where:

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

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

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,)
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,)
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.

class relife.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.

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,)
class relife.Gompertz(c: Optional[float] = None, rate: Optional[float] = None)[source]

Bases: relife.distribution.ParametricLifetimeDistribution

Gompertz parametric lifetime distribution.

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

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

where:

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

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

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

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.

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

Bases: relife.distribution.ParametricLifetimeDistribution

Gamma parametric lifetime distribution.

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

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

where:

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

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

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

c: float = None
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,)
var(params: 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,)
class relife.LogLogistic(c: Optional[float] = None, rate: Optional[float] = None)[source]

Bases: relife.distribution.ParametricLifetimeDistribution

Log-logistic parametric lifetime distribution.

The Log-logistic distribution is defined as a 2-parameter distribution \((c, \lambda)\). The probability density function is:

\[f(t) = \frac{c \lambda^c t^{c-1}}{(1+(\lambda t)^{c})^2}\]

where:

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

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

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

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,)
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,)
class relife.MinimumDistribution(baseline: relife.distribution.ParametricLifetimeDistribution)[source]

Bases: relife.distribution.ParametricLifetimeDistribution

Series structure of n identical and independent components.

The hazard function of the system is given by:

\[h(t) = n \cdot h_0(t)\]

where \(h_0\) is the baseline hazard function of the components.

Examples

Computing the survival (or reliability) function for 3 structures of 3,6 and 9 identical and idependent components:

model = MinimumDistribution(Weibull(2, 0.05))
t = np.arange(0, 10, 0.1)
n = np.array([3, 6, 9]).reshape(-1, 1)
model.sf(t, n)
baseline: relife.distribution.ParametricLifetimeDistribution

Underlying lifetime model of the components.

property params: numpy.ndarray

Parameters of the hazard functions.

property n_params: int

Number of parameters.

class relife.AFT(baseline: relife.parametric.ParametricLifetimeModel, beta: Optional[numpy.ndarray] = None)[source]

Bases: relife.regression.Regression

Accelerated Failure Time Regression Model.

The cumulative hazard function \(H\) is linked to the multiplier function \(g\) by the relation:

\[H(t, x) = H_0\left(\dfrac{t}{g(\beta, x)}\right) = H_0(t e^{- \beta \cdot x})\]

where \(x\) is a vector of covariates, \(\beta\) is the coefficient vector of the effect of covariates, \(H_0\) is the baseline cumulative hazard function.

References

1

Kalbfleisch, J. D., & Prentice, R. L. (2011). The statistical analysis of failure time data. John Wiley & Sons.

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

baseline: relife.parametric.ParametricLifetimeModel

Baseline parametric lifetime model for the regression.

class relife.ProportionalHazards(baseline: relife.parametric.ParametricLifetimeModel, beta: Optional[numpy.ndarray] = None)[source]

Bases: relife.regression.Regression

Parametric Proportional Hazards Regression Model.

The cumulative hazard function \(H\) is linked to the multiplier function \(g\) by the relation:

\[H(t, x) = g(\beta, x) H_0(t) = e^{\beta \cdot x} H_0(t)\]

where \(x\) is a vector of covariates, \(\beta\) is the coefficient vector of the effect of covariates, \(H_0\) is the baseline cumulative hazard function.

References

1

Sun, J. (2006). The statistical analysis of interval-censored failure time data (Vol. 3, No. 1). New York: springer.

baseline: relife.parametric.ParametricLifetimeModel

Baseline parametric lifetime model for the regression.

class relife.ECDF[source]

Bases: object

Empirical Cumulative Distribution Function.

fit(time: numpy.ndarray) relife.nonparametric.ECDF[source]

Fit the empirical cumuative distribution function.

Parameters

time (1D array) – Failure times.

Returns

Return the fitted empirical estimate as the current object.

Return type

ECDF

plot(alpha_ci: float = 0.05, fname: str = 'cdf', **kwargs: numpy.ndarray) None[source]

Plot the empirical cumulative distribution function.

Parameters
  • 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 ‘cdf’. Should be one of:

    • ’sf’ : survival function,

    • ’cdf’: cumulative distribution function.

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

Raises

ValueError – If fname value is not ‘sf’ or ‘cdf’.

class relife.KaplanMeier[source]

Bases: object

Kaplan-Meier Estimator.

Compute the non-parametric Kaplan-Meier estimator (also known as the product limit estimator) of the survival function from lifetime data.

Notes

For a given time instant \(t\) and \(n\) total observations, this estimator is defined as:

\[\hat{S}(t) = \prod_{i: t_i \leq t} \left( 1 - \frac{d_i}{n_i}\right)\]

where \(d_i\) is the number of failures until \(t_i\) and \(n_i\) is the number of assets at risk just prior to \(t_i\).

The variance estimation is obtained by:

\[\widehat{Var}[\hat{S}(t)] = \hat{S}(t)^2 \sum_{i: t_i \leq t} \frac{d_i}{n_i(n_i - d_i)}\]

which is often referred to as Greenwood’s formula.

References

1

Lawless, J. F. (2011). Statistical models and methods for lifetime data. John Wiley & Sons.

2

Kaplan, E. L., & Meier, P. (1958). Nonparametric estimation from incomplete observations. Journal of the American statistical association, 53(282), 457-481.

fit(time: numpy.ndarray, event: Optional[numpy.ndarray] = None, entry: Optional[numpy.ndarray] = None) relife.nonparametric.KaplanMeier[source]

Fit the Kaplan-Meier estimator to a time, event and entry arrays.

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.

Returns

Return the fitted Kaplan-Meier estimator as the current object.

Return type

KaplanMeier

plot(alpha_ci: float = 0.05, **kwargs) None[source]

Plot the Kaplan-Meier estimator of the survival function.

Parameters
  • 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.

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

class relife.NelsonAalen[source]

Bases: object

Nelson-Aalen Estimator.

Compute the non-parametric Nelson-Aalen estimator of the cumulative hazard function from lifetime data.

Notes

For a given time instant \(t\) and \(n\) total observations, this estimator is defined as:

\[\hat{H}(t) = \sum_{i: t_i \leq t} \frac{d_i}{n_i}\]

where \(d_i\) is the number of failures until \(t_i\) and \(n_i\) is the number of assets at risk just prior to \(t_i\).

The variance estimation is obtained by:

\[\widehat{Var}[\hat{H}(t)] = \sum_{i: t_i \leq t} \frac{d_i}{n_i^2}\]

Note that the alternative survivor function estimate:

\[\tilde{S}(t) = \exp{(-\hat{H}(t))}\]

is sometimes suggested for the continuous-time case.

References

1

Lawless, J. F. (2011). Statistical models and methods for lifetime data. John Wiley & Sons.

fit(time: numpy.ndarray, event: Optional[numpy.ndarray] = None, entry: Optional[numpy.ndarray] = None) relife.nonparametric.NelsonAalen[source]

Fit the Nelson-Aalen estimator 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.

Returns

The fitted Nelson-Aalen estimator as the current object.

Return type

NelsonAalen

plot(alpha_ci: float = 0.05, **kwargs: numpy.ndarray) None[source]

Plot the Nelson-Aalen estimator of the cumulative hazard function.

Parameters
  • 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.

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

class relife.RenewalProcess(model: relife.model.LifetimeModel, model1: Optional[relife.model.LifetimeModel] = None)[source]

Bases: object

Renewal process.

Creates a renewal process.

Parameters
  • model (LifetimeModel) – A lifetime model representing the durations between events.

  • model1 (LifetimeModel, optional) – A lifetime model for the first renewal (delayed renewal process), by default None.

renewal_function(t: numpy.ndarray, model_args: Tuple[numpy.ndarray, ...] = (), model1_args: Tuple[numpy.ndarray, ...] = ()) numpy.ndarray[source]

The renewal function.

Parameters
  • t (1D array) – Timeline.

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

  • model1_args (Tuple[ndarray,...], optional) – Extra arguments required by the lifetime model of the first renewal, by default ().

Returns

The renewal function evaluated at each point of the timeline.

Return type

ndarray

Notes

The expected total number of renewals is computed by solving the renewal equation:

\[m(t) = F_1(t) + \int_0^t m(t-x) \mathrm{d}F(x)\]

where:

  • \(m\) is the renewal function,

  • \(F\) is the cumulative distribution function of the underlying lifetime model,

  • \(F_1\) is the cumulative distribution function of the underlying lifetime model for the fist renewal in the case of a delayed renewal process.

References

1

Rausand, M., Barros, A., & Hoyland, A. (2020). System Reliability Theory: Models, Statistical Methods, and Applications. John Wiley & Sons.

renewal_density(t: numpy.ndarray, model_args: Tuple[numpy.ndarray, ...] = (), model1_args: Tuple[numpy.ndarray, ...] = ()) numpy.ndarray[source]

The renewal density.

Parameters
  • t (1D array) – Timeline.

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

  • model1_args (Tuple[ndarray,...], optional) – Extra arguments required by the lifetime model of the first renewal, by default ().

Returns

Renewal density evaluated at each point of the timeline.

Return type

ndarray

Raises

NotImplementedError – If the lifetime model is not absolutely continuous.

Notes

The renewal density is the derivative of the renewal function with respect to time. It is computed by solving the renewal equation:

\[\mu(t) = f_1(t) + \int_0^t \mu(t-x) \mathrm{d}F(x)\]

where:

  • \(\mu\) is the renewal function,

  • \(F\) is the cumulative distribution function of the underlying lifetime model,

  • \(f_1\) is the probability density function of the underlying lifetime model for the fist renewal in the case of a delayed renewal process.

References

1

Rausand, M., Barros, A., & Hoyland, A. (2020). System Reliability Theory: Models, Statistical Methods, and Applications. John Wiley & Sons.

sample(T: float, model_args: Tuple[numpy.ndarray, ...] = (), model1_args: Tuple[numpy.ndarray, ...] = (), n_samples: int = 1, random_state: Optional[int] = None) relife.data.RenewalData[source]

Renewal data sampling.

Parameters
  • T (float) – Time at the end of the observation.

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

  • model1_args (Tuple[ndarray,...], optional) – Extra arguments required by the lifetime model of the first renewal, by default ().

  • n_samples (int, optional) – Number of samples, by default 1.

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

Returns

Samples of replacement times and durations.

Return type

RenewalData

class relife.RenewalRewardProcess(model: relife.model.LifetimeModel, reward: relife.reward.Reward, model1: typing.Optional[relife.model.LifetimeModel] = None, reward1: typing.Optional[relife.reward.Reward] = None, discount: relife.discounting.Discount = <relife.discounting.ExponentialDiscounting object>)[source]

Bases: relife.renewal_process.RenewalProcess

Renewal reward process.

Creates a renewal reward process.

Parameters
  • model (LifetimeModel) – A lifetime model representing the durations between events.

  • reward (Reward) – A reward associated to the interarrival time.

  • model1 (LifetimeModel, optional) – A lifetime model for the first renewal (delayed renewal process), by default None.

  • reward1 (Reward, optional) – A reward associated to the first renewal, by default None

  • discount (Discount, optional) – A discount function related to the rewards, by default ExponentialDiscounting()

expected_total_reward(t: numpy.ndarray, model_args: Tuple[numpy.ndarray, ...] = (), reward_args: Tuple[numpy.ndarray, ...] = (), model1_args: Tuple[numpy.ndarray, ...] = (), reward1_args: Tuple[numpy.ndarray, ...] = (), discount_args: Tuple[numpy.ndarray, ...] = ()) numpy.ndarray[source]

The expected total reward.

Parameters
  • t (1D array) – Timeline.

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

  • reward_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward, by default ().

  • model1_args (Tuple[ndarray,...], optional) – Extra arguments required by the lifetime model of the first renewal, by default ().

  • reward1_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward of the first renewal, by default ().

  • discount_args (Tuple[ndarray,...], optional) – Extra arguments required by the discount function, by default ().

Returns

Expected total reward of process evaluated at each point of the timeline.

Return type

ndarray

Raises

NotImplementedError – If the discount function is not exponential.

Notes

The renewal equation solved by the expected reward is:

\[z(t) = \int_0^t E[Y | X = x] D(x) \mathrm{d}F(x) + \int_0^t z(t-x) D(x)\mathrm{d}F(x)\]

where:

  • \(z\) is the expected total reward,

  • \(F\) is the cumulative distribution function of the underlying lifetime model,

  • \(X\) the interarrival random variable,

  • \(Y\) the associated reward,

  • \(D\) the exponential discount factor.

If the renewal reward process is delayed, the expected total reward is modified as:

\[z_1(t) = \int_0^t E[Y_1 | X_1 = x] D(x) \mathrm{d}F_1(x) + \int_0^t z(t-x) D(x) \mathrm{d}F_1(x)\]

where:

  • \(z_1\) is the expected total reward with delay,

  • \(F_1\) is the cumulative distribution function of the lifetime model for the first renewal,

  • \(X_1\) the interarrival random variable of the first renewal,

  • \(Y_1\) the associated reward of the first renewal,

expected_equivalent_annual_worth(t: numpy.ndarray, model_args: Tuple[numpy.ndarray, ...] = (), reward_args: Tuple[numpy.ndarray, ...] = (), model1_args: Tuple[numpy.ndarray, ...] = (), reward1_args: Tuple[numpy.ndarray, ...] = (), discount_args: Tuple[numpy.ndarray, ...] = ()) numpy.ndarray[source]

Expected equivalent annual worth.

Gives the equivalent annual worth of the expected total reward of the process at each point of the timeline.

Parameters
  • t (1D array) – Timeline.

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

  • reward_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward, by default ().

  • model1_args (Tuple[ndarray,...], optional) – Extra arguments required by the lifetime model of the first renewal, by default ().

  • reward1_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward of the first renewal, by default ().

  • discount_args (Tuple[ndarray,...], optional) – Extra arguments required by the discount function, by default ().

Returns

The expected equivalent annual worth evaluated at each point of the timeline.

Return type

ndarray

Notes

The equivalent annual worth at time \(t\) is equal to the expected total reward \(z\) divided by the annuity factor \(AF(t)\).

asymptotic_expected_total_reward(model_args: Tuple[numpy.ndarray, ...] = (), reward_args: Tuple[numpy.ndarray, ...] = (), model1_args: Tuple[numpy.ndarray, ...] = (), reward1_args: Tuple[numpy.ndarray, ...] = (), discount_args: Tuple[numpy.ndarray, ...] = ()) numpy.ndarray[source]

Asymptotic expected total reward.

Parameters
  • model_args (Tuple[ndarray,...], optional) – Extra arguments required by the underlying lifetime model, by default ().

  • reward_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward, by default ().

  • model1_args (Tuple[ndarray,...], optional) – Extra arguments required by the lifetime model of the first renewal, by default ().

  • reward1_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward of the first renewal, by default ().

  • discount_args (Tuple[ndarray,...], optional) – Extra arguments required by the discount function, by default ().

Returns

The assymptotic expected total reward of the process.

Return type

ndarray

Raises

NotImplementedError – If the discount function is not exponential.

Notes

The asymptotic expected total reward is:

\[z^\infty = \lim_{t\to \infty} z(t) = \dfrac{E[Y D(X)]}{1-E[D(X)]}\]

where:

  • \(X\) the interarrival random variable,

  • \(Y\) the associated reward,

  • \(D\) the exponential discount factor.

If the renewal reward process is delayed, the asymptotic expected total reward is modified as:

\[z_1^\infty = E[Y_1 D(X_1)] + z^\infty E[D(X_1)]\]

where:

  • \(X_1\) the interarrival random variable of the first renewal,

  • \(Y_1\) the associated reward of the first renewal,

asymptotic_expected_equivalent_annual_worth(model_args: Tuple[numpy.ndarray, ...] = (), reward_args: Tuple[numpy.ndarray, ...] = (), model1_args: Tuple[numpy.ndarray, ...] = (), reward1_args: Tuple[numpy.ndarray, ...] = (), discount_args: Tuple[numpy.ndarray, ...] = ()) numpy.ndarray[source]

Asymptotic expected equivalent annual worth.

Parameters
  • model_args (Tuple[ndarray,...], optional) – Extra arguments required by the underlying lifetime model, by default ().

  • reward_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward, by default ().

  • model1_args (Tuple[ndarray,...], optional) – Extra arguments required by the lifetime model of the first renewal, by default ().

  • reward1_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward of the first renewal, by default ().

  • discount_args (Tuple[ndarray,...], optional) – Extra arguments required by the discount function, by default ().

Returns

The asymptotic expected equivalent annual worth of the process.

Return type

ndarray

Raises

NotImplementedError – If the discount function is not exponential.

sample(T: float, model_args: Tuple[numpy.ndarray, ...] = (), reward_args: Tuple[numpy.ndarray, ...] = (), model1_args: Tuple[numpy.ndarray, ...] = (), reward1_args: Tuple[numpy.ndarray, ...] = (), discount_args: Tuple[numpy.ndarray, ...] = (), n_samples: int = 1, random_state: Optional[int] = None) relife.data.RenewalRewardData[source]

Renewal reward data sampling.

Parameters
  • T (float) – Time at the end of the observation.

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

  • reward_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward, by default ().

  • model1_args (Tuple[ndarray,...], optional) – Extra arguments required by the lifetime model of the first renewal, by default ().

  • reward1_args (Tuple[ndarray,...], optional) – Extra arguments required by the associated reward of the first renewal, by default ().

  • discount_args (Tuple[ndarray,...], optional) – Extra arguments required by the discount function, by default ().

  • n_samples (int, optional) – Number of samples, by default 1.

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

Returns

Samples of replacement times, durations and rewards.

Return type

RenewalRewardData

class relife.OneCycleRunToFailure(model: relife.model.AbsolutelyContinuousLifetimeModel, args: Tuple[numpy.ndarray, ...] = (), a0: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, rate: numpy.ndarray = 0)[source]

Bases: object

One cyle run-to-failure policy.

One cycle run-to-failure policy.

Parameters
  • model (AbsolutelyContinuousLifetimeModel) – Absolutely continuous lifetime model of the asset.

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

  • a0 (float or 2D array, optional) – Current ages of the assets, by default 0 for each asset.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default 0.

Notes

If cf is set to None, if should be defined when using methods to compute costs.

If cf and rate are 2D or 3D array, then:

  • axis=-2 represents the indices of each asset,

  • axis=-3 represents the indices of each component of the cost vector.

References

1

Coolen-Schrijner, P., & Coolen, F. P. A. (2006). On optimality criteria for age replacement. Proceedings of the Institution of Mechanical Engineers, Part O: Journal of Risk and Reliability, 220(1), 21-29

reward: relife.reward.FailureCost = <relife.reward.FailureCost object>

The failure cost of the asset.

discount: relife.discounting.ExponentialDiscounting = <relife.discounting.ExponentialDiscounting object>

Exponential discounting.

rrp_args(cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) Tuple[Tuple[numpy.ndarray, ...], ...][source]

Arguments of the underlying renewal reward process.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

(model_args, reaward_args, discount_args)

Return type

Tuple[Tuple[ndarray,…],…]

Notes

If an argument is None, the value of the class attribute is taken.

expected_total_cost(t: numpy.ndarray, cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The expected total discounted cost.

Parameters
  • t (1D array) – Timeline.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The cumulative expected total cost for each asset along the timeline.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

asymptotic_expected_total_cost(cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The asymptotic expected total cost.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The asymptotic expected total cost for each asset.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

expected_equivalent_annual_cost(t: numpy.ndarray, cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, dt: float = 1.0) numpy.ndarray[source]

The expected equivalent annual cost.

Parameters
  • t (1D array) – Timeline.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • dt (float, optional) – The length of the first period before discounting, by default 1.

Returns

The expected equivalent annual cost until time t.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

The expected equivalent annual cost until time \(t\) is given by:

\[EEAC(t) = \int_0^t \frac{\delta c_f e^{-\delta x}}{1 - e^{-\delta x}} \mathrm{d}F(x)\]
asymptotic_expected_equivalent_annual_cost(cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, dt: float = 1.0) numpy.ndarray[source]

The asymptotic expected equivalent annual cost.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • dt (float, optional) – The length of the first period before discounting, by default 1.

Returns

The asymptotic expected equivalent annual cost.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

The asymptotic expected equivalent annual cost is:

\[EEAC_\infty = \int_0^\infty \frac{\delta c_f e^{-\delta x}}{1 - e^{-\delta x}} \mathrm{d}F(x)\]
sample(cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, n_samples: int = 1, random_state: Optional[int] = None) relife.data.ReplacementPolicyData[source]

One cycle run-to-failure policy sampling.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • n_samples (int, optional) – Number of samples, by default 1.

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

Returns

Samples of replacement times, durations, costs and events for each asset.

Return type

ReplacementPolicyData

Notes

If an argument is None, the value of the class attribute is taken.

class relife.RunToFailure(model: relife.model.AbsolutelyContinuousLifetimeModel, args: Tuple[numpy.ndarray, ...] = (), a0: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, rate: numpy.ndarray = 0)[source]

Bases: object

Run-to-failure renewal policy.

Run-to-failure renwal policy.

Renewal reward process where assets are replaced on failure with costs cf.

Parameters
  • model (AbsolutelyContinuousLifetimeModel) – Absolutely continuous lifetime model of the asset.

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

  • a0 (float or 2D array, optional) – Current ages of the assets, by default 0 for each asset.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default 0.

Notes

If cf is set to None, if should be defined when using methods to compute costs.

If cf and rate are 2D or 3D array, then:

  • axis=-2 represents the indices of each asset,

  • axis=-3 represents the indices of each component of the cost vector.

References

1

Van der Weide, J. A. M., & Van Noortwijk, J. M. (2008). Renewal theory with exponential and hyperbolic discounting. Probability in the Engineering and Informational Sciences, 22(1), 53-74.

reward: relife.reward.FailureCost = <relife.reward.FailureCost object>

The failure cost of the asset.

discount: relife.discounting.ExponentialDiscounting = <relife.discounting.ExponentialDiscounting object>

Exponential discounting.

rrp_args(cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) Tuple[Tuple[numpy.ndarray, ...], ...][source]

Arguments of the underlying renewal reward process.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

(model_args, reward_args, model1_args, reward1_args, discount_args)

Return type

Tuple[Tuple[ndarray,…],…]

Notes

If an argument is None, the value of the class attribute is taken.

expected_total_cost(t: numpy.ndarray, cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The expected total discounted cost.

The expected total discounted cost is computed by solving the renewal equation.

Parameters
  • t (1D array) – Timeline.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The cumulative expected total cost for each asset along the timeline.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

asymptotic_expected_total_cost(cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The asymptotic expected total cost.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The asymptotic expected total cost for each asset.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

expected_equivalent_annual_cost(t: numpy.ndarray, cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The expected equivalent annual cost.

where \(z\) is the expected total cost.

Parameters
  • t (1D array) – Timeline.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The expected equivalent annual cost for each asset along the timeline.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

The expected equivalent annual cost at time \(t\) is:

\[EEAC(t) = \dfrac{\delta z(t)}{1 - e^{-\delta t}}\]
asymptotic_expected_equivalent_annual_cost(cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The asymptotic expected equivalent annual cost.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The asymptotic expected equivalent annual cost for each asset.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

The asymptotic expected equivalent annual cost is:

\[EEAC_\infty = \lim_{t \to \infty} EEAC(t)\]
sample(T: float, cf: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, n_samples: int = 1, random_state: Optional[int] = None) relife.data.ReplacementPolicyData[source]

Run-to-failure renewal policy sampling.

Parameters
  • T (float) – End of the observation period.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • n_samples (int, optional) – Number of samples, by default 1.

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

Returns

Samples of replacement times, durations, costs and events for each asset.

Return type

ReplacementPolicyData

Notes

If an argument is None, the value of the class attribute is taken.

class relife.OneCycleAgeReplacementPolicy(model: relife.model.AbsolutelyContinuousLifetimeModel, args: Tuple[numpy.ndarray, ...] = (), a0: Optional[numpy.ndarray] = None, ar: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: numpy.ndarray = 0)[source]

Bases: object

One-cyle age replacement policy.

The asset is disposed at a fixed age ar with costs cp or upon failure with costs cf if earlier.

One-cyle age replacement policy.

Parameters
  • model (AbsolutelyContinuousLifetimeModel) – Absolutely continuous lifetime model of the asset.

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

  • a0 (float or 2D array, optional) – Current ages of the assets, by default 0 for each asset.

  • ar (float, 2D array, optional) – Ages of preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default 0.

Notes

If ar, cf or cp is set to None, the argument should be defined when using methods to compute costs.

If cf, cp and rate are 2D or 3D array, then:

  • axis=-2 represents the indices of each asset,

  • axis=-3 represents the indices of each component of the cost vector.

References

1

Coolen-Schrijner, P., & Coolen, F. P. A. (2006). On optimality criteria for age replacement. Proceedings of the Institution of Mechanical Engineers, Part O: Journal of Risk and Reliability, 220(1), 21-29

reward: relife.reward.AgeReplacementCost = <relife.reward.AgeReplacementCost object>

Costs of the replacement.

discount: relife.discounting.ExponentialDiscounting = <relife.discounting.ExponentialDiscounting object>

Exponential discounting.

rrp_args(ar: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) Tuple[Tuple[numpy.ndarray, ...], ...][source]

Arguments of the underlying renewal reward process.

Parameters
  • ar (float or 2D array, optional) – Ages of preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

(model_args, reaward_args, discount_args)

Return type

Tuple[Tuple[ndarray,…],…]

Notes

If an argument is None, the value of the class attribute is taken.

classmethod optimal_replacement_age(model: relife.model.AbsolutelyContinuousLifetimeModel, cf: numpy.ndarray, cp: numpy.ndarray, rate: numpy.ndarray = 0, args: Tuple[numpy.ndarray, ...] = ()) numpy.ndarray[source]

Compute the optimal age of preventive replacement for each asset.

The optimal age of preventive replacement is computed by minimizing the asymptotic expected equivalent annual cost on one-cycle.

Parameters
  • model (AbsolutelyContinuousLifetimeModel) – Absolutely continuous lifetime model.

  • cf (float, 2D array or 3D array) – Costs of failures.

  • cp (float, 2D array or 3D array) – Costs of preventive replacements.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default 0.

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

Returns

The optimal age of preventive replacement.

Return type

ndarray

Notes

The optimal age of replacement minimizes the asymptotic expected equivalent annual cost:

\[EEAC_\infty(a) = \sum_i {c_f}_i \int_0^a \dfrac{\delta_i e^{-\delta_i t}}{1 - e^{-\delta_i t}} f(t) \mathrm{d}t + {c_p}_i S(a)\dfrac{\delta_i e^{-\delta_i a}}{1 - e^{-\delta_i a}}\]

where:

  • \(a\) is the age of replacement,

  • \({c_f}_i, {c_p}_i, \delta_i\) are respectively the components of the failures costs, preventive costs and the associated discount rate,

  • \(S, f, h\) are respectively the survival function, the probability density function and the hazard function of the underlying lifetime model.

The optimal age of replacement is then solution of the equation:

\[\sum_i \dfrac{\delta_i e^{-\delta_i a}}{1 - e^{-\delta_i a}} \left( ({c_f}_i - {c_p}_i) h(a) - \dfrac{\delta_i {c_p}_i}{1 - e^{-\delta_i a}} \right) = 0\]
fit(cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) relife.replacement_policy.OneCycleAgeReplacementPolicy[source]

Computes and sets the optimal age of replacement for each asset.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The fitted policy as the current object.

Return type

self

Notes

If an argument is None, the value of the class attribute is taken.

expected_total_cost(t: numpy.ndarray, ar: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The expected total discounted cost.

Parameters
  • t (1D array) – Timeline.

  • ar (float or 2D array, optional) – Ages of replacement, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The cumulative expected total cost for each asset along the timeline.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

asymptotic_expected_total_cost(ar: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The asymptotic expected total cost.

Parameters
  • ar (float or 2D array, optional) – Ages of preventive replacement, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The asymptotic expected total cost for each asset.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

expected_equivalent_annual_cost(t: numpy.ndarray, ar: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, dt: float = 1.0) numpy.ndarray[source]

The expected equivalent annual cost.

Parameters
  • t (1D array) – Timeline.

  • ar (float or 2D array, optional) – Ages of preventive replacement, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • dt (float, optional) – The length of the first period before discounting, by default 1.

Returns

The cumulative expected equivalent annual cost until time t.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

The expected equivalent annual cost until time \(t\) is:

\[EEAC(t) = \int_0^t \frac{\delta c_f e^{-\delta x}}{1 - e^{-\delta x}} \mathrm{d}F(x)\]
asymptotic_expected_equivalent_annual_cost(ar: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, dt: float = 1.0) numpy.ndarray[source]

The asymptotic expected equivalent annual cost.

Parameters
  • ar (float or 2D array, optional) – Ages of preventive replacement, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • dt (float, optional) – The length of the first period before discounting, by default 1.

Returns

The asymptotic expected equivalent annual cost.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

The asymptotic expected equivalent annual cost is:

\[EEAC_\infty = \int_0^\infty \frac{\delta c_f e^{-\delta x}}{1 - e^{-\delta x}} \mathrm{d}F(x)\]
sample(ar: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, n_samples: int = 1, random_state: Optional[int] = None) relife.data.ReplacementPolicyData[source]

One-cycle age replacement policy sampling.

Parameters
  • ar (float or 2D array, optional) – Ages of preventive replacement, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • n_samples (int, optional) – Number of samples, by default 1.

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

Returns

Samples of replacement times, durations, costs and events for each asset.

Return type

ReplacementPolicyData

Notes

If an argument is None, the value of the class attribute is taken.

class relife.AgeReplacementPolicy(model: relife.model.AbsolutelyContinuousLifetimeModel, args: Tuple[numpy.ndarray, ...] = (), a0: Optional[numpy.ndarray] = None, ar: Optional[numpy.ndarray] = None, ar1: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: numpy.ndarray = 0)[source]

Bases: object

Time based replacement policy.

Age replacement renewal policy.

Renewal reward process where assets are replaced at a fixed age ar with costs cp or upon failure with costs cf if earlier.

Parameters
  • model (AbsolutelyContinuousLifetimeModel) – Absolutely continuous lifetime model of the asset.

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

  • a0 (float or 2D array, optional) – Current ages of the assets, by default 0 for each asset.

  • ar (float, 2D array, optional) – Ages of preventive replacements, by default None.

  • ar1 (float, 2D array, optional) – Ages of the first preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default 0.

Notes

If ar, ar1, cf or cp is set to None, the argument should be defined when using methods to compute costs.

If cf, cp and rate are 2D or 3D array, then:

  • axis=-2 represents the indices of each asset,

  • axis=-3 represents the indices of each component of the cost vector.

References

1

Mazzuchi, T. A., Van Noortwijk, J. M., & Kallen, M. J. (2007). Maintenance optimization. Encyclopedia of Statistics in Quality and Reliability, 1000-1008.

reward: relife.reward.AgeReplacementCost = <relife.reward.AgeReplacementCost object>

Costs of the replacement.

discount: relife.discounting.ExponentialDiscounting = <relife.discounting.ExponentialDiscounting object>

Exponential discounting.

rrp_args(ar: Optional[numpy.ndarray] = None, ar1: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) Tuple[Tuple[numpy.ndarray, ...], ...][source]

Arguments of the underlying renewal reward process.

Parameters
  • ar (float, 2D array, optional) – Ages of preventive replacements, by default None.

  • ar1 (float, 2D array, optional) – Ages of the first preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default 0.

Returns

(model_args, reward_args, model1_args, reward1_args, discount_args)

Return type

Tuple[Tuple[ndarray,…],…]

Notes

If an argument is None, the value of the class attribute is taken.

classmethod optimal_replacement_age(model: relife.model.AbsolutelyContinuousLifetimeModel, cf: numpy.ndarray, cp: numpy.ndarray, rate: numpy.ndarray = 0, args: Tuple[numpy.ndarray, ...] = ()) numpy.ndarray[source]

Compute the optimal age of preventive replacement for each asset.

The optimal age of preventive replacement is computed by minimizing the asymptotic expected equivalent annual cost of the renewal reward process.

Parameters
  • model (AbsolutelyContinuousLifetimeModel) – Absolutely continuous lifetime model.

  • cf (float, 2D array or 3D array) – Costs of failures.

  • cp (float, 2D array or 3D array) – Costs of preventive replacements.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default 0.

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

Returns

The optimal age of preventive replacement.

Return type

ndarray

Notes

The optimal age of replacement minimizes the asymptotic expected equivalent annual cost:

\[EEAC_\infty(a) = \sum_i \dfrac{{c_f}_i \int_0^a e^{-\delta_i x} f(x) \mathrm{d}x + {c_p}_i e^{-\delta_i a} S(a)}{\int_0^a e^{-\delta_i x} S(x) \mathrm{d}x}\]

where:

  • \(a\) is the age of replacement,

  • \({c_f}_i, {c_p}_i, \delta_i\) are respectively the components of the failures costs, preventive costs and the associated discount rate,

  • \(S, f, h\) are respectively the survival function, the probability density function and the hazard function of the underlying lifetime model.

The optimal age of replacement is then solution of the equation:

\[\sum_i \dfrac{\left( ({c_f}_i - {c_p}_i) \left( h(a) \int_0^a e^{-\delta_i x} S(x) \mathrm{d}x - \int_0^a e^{-\delta_i x} f(x) \mathrm{d}x \right) - {c_p}_i \right)} {\left( \int_0^a e^{-\delta_i x} S(x) \mathrm{d}x \right)^2} = 0\]
fit(cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, fit_ar1: bool = True) relife.replacement_policy.AgeReplacementPolicy[source]

Computes and sets the optimal age of replacement for each asset.

Parameters
  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • fit_ar1 (bool, optional) – If True, computes and sets the optimal age of replacement for the first replacement considering a one-cycle age replacement criteria.

Returns

The fitted policy as the current object.

Return type

self

Notes

If an argument is None, the value of the class attribute is taken.

expected_total_cost(t: numpy.ndarray, ar: Optional[numpy.ndarray] = None, ar1: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The expected total discounted cost.

The expected total discounted cost is computed by solving the renewal equation.

Parameters
  • t (1D array) – Timeline.

  • ar (float or 2D array, optional) – Ages of replacement, by default None.

  • ar1 (float, 2D array, optional) – Ages of the first preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The cumulative expected total cost for each asset along the timeline.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

asymptotic_expected_total_cost(ar: Optional[numpy.ndarray] = None, ar1: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The asymptotic expected total cost.

Parameters
  • ar (float or 2D array, optional) – Ages of preventive replacement, by default None.

  • ar1 (float, 2D array, optional) – Ages of the first preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The asymptotic expected total cost for each asset.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

expected_equivalent_annual_cost(t: numpy.ndarray, ar: Optional[numpy.ndarray] = None, ar1: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The expected equivalent annual cost.

Parameters
  • t (1D array) – Timeline.

  • ar (float or 2D array, optional) – Ages of replacement, by default None.

  • ar1 (float, 2D array, optional) – Ages of the first preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The expected equivalent annual cost for each asset along the timeline.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

The expected equivalent annual cost at time \(t\) is:

\[EEAC(t) = \dfrac{\delta z(t)}{1 - e^{-\delta t}}\]

where \(z\) is the expected total cost.

asymptotic_expected_equivalent_annual_cost(ar: Optional[numpy.ndarray] = None, ar1: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None) numpy.ndarray[source]

The asymptotic expected equivalent annual cost.

Parameters
  • ar (float or 2D array, optional) – Ages of replacement, by default None.

  • ar1 (float, 2D array, optional) – Ages of the first preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

Returns

The asymptotic expected equivalent annual cost for each asset.

Return type

ndarray

Notes

If an argument is None, the value of the class attribute is taken.

The asymptotic expected equivalent annual cost is:

\[EEAC_\infty = \lim_{t \to \infty} EEAC(t)\]
sample(T: float, ar: Optional[numpy.ndarray] = None, ar1: Optional[numpy.ndarray] = None, cf: Optional[numpy.ndarray] = None, cp: Optional[numpy.ndarray] = None, rate: Optional[numpy.ndarray] = None, n_samples: int = 1, random_state: Optional[int] = None) relife.data.ReplacementPolicyData[source]

Age replacement renewal policy sampling.

Parameters
  • T (float) – End of the observation period.

  • ar (float or 2D array, optional) – Ages of replacement, by default None.

  • ar1 (float, 2D array, optional) – Ages of the first preventive replacements, by default None.

  • cf (float, 2D array or 3D array, optional) – Costs of failures, by default None.

  • cp (float, 2D array or 3D array, optional) – Costs of preventive replacements, by default None.

  • rate (float, 2D array or 3D array, optional) – Discount rate, by default None.

  • n_samples (int, optional) – Number of samples, by default 1.

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

Returns

Samples of replacement times, durations, costs and events for each asset.

Return type

ReplacementPolicyData

Notes

If an argument is None, the value of the class attribute is taken.