Exponential#
- final class relife.lifetime_models.Exponential(rate=None)[source]#
Exponential 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.
- Parameters:
- ratefloat, default is None
Rate parameter.
- Attributes:
- fitting_resultsFittingResults, default is None
An object containing fitting results (AIC, BIC, etc.). If the model is not fitted, the value is None.
Methods
The cumulative density function.
The cumulative hazard function.
The derivate of the hazard function.
Estimation of parameters from lifetime data.
Get the parameters of this model.
Parameters names.
The hazard function.
Inverse cumulative hazard function.
Initialize the lifetime likelihood used to fit the parameters.
The inverse survival function.
The jacobian of the cumulative density function.
The jacobian of the cumulative hazard function.
The jacobian of the hazard function.
The jacobian of the probability density function.
The jacobian of the survival function.
Lebesgue-Stieltjes integration.
The mean of the distribution.
The median.
n-th order moment.
The mean residual life function.
The probability density function.
Plot function.
The percent point function.
Random variable sampling.
Set the parameters of this model.
The survival function.
The variance of the distribution.
- cdf(time)#
The cumulative density function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).
- Returns:
- outnp.float64 or np.ndarray
cdf values at each given time(s).
- chf(time)[source]#
The cumulative hazard function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).
- Returns:
- outnp.float64 or np.ndarray
chf values at each given time(s).
- dhf(time)[source]#
The derivate of the hazard function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).
- Returns:
- outnp.float64 or np.ndarray
Function values at each given time(s).
- fit(time, args=None, event=None, entry=None, **kwargs)#
Estimation of parameters from lifetime data.
- Parameters:
- time1d array
Observed lifetime values.
- argsany ndarray or tuple of ndarray, default is None
Additional arguments required by the model (e.g. covar).
- event1d array of bool, default is None
Boolean indicators tagging lifetime values as right censored or complete.
- entry1d array, default is None
Left truncations applied to lifetime values.
- **kwargs
Extra arguments used by scipy.optimize.minimize to search for the paremeters that minimize the negative log-likelihood. covariance_method can also be passed to control the method used to estimate parameters covariance. Values can be “cs”, “2point”, “exact” or False. To skip parameters covariance estimation, set covariance_method to False, otherwise the default method associated to the model will be used. If covariance_method is “exact” the hess must be passed too.
- Returns:
- outthe object instance
The estimated parameters are setted inplace.
- get_params()#
Get the parameters of this model.
- Returns:
- out1darray of number
Model parameters.
Notes
If parameter values are not set, they default to np.nan values.
- get_params_names()#
Parameters names.
- Returns:
- list of str
Parameters names
Notes
Parameters values can be requested (a.k.a. get) by their name at instance level.
- hf(time)[source]#
The hazard function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).
- Returns:
- outnp.float64 or np.ndarray
hf values at each given time(s).
- ichf(cumulative_hazard_rate)[source]#
Inverse cumulative hazard function.
- Parameters:
- cumulative_hazard_ratefloat or np.ndarray
Cumulative hazard rate value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).
- Returns:
- outnp.float64 or np.ndarray
ichf values at each given cumulative hazard rate(s).
- init_likelihood(time, args=None, event=None, entry=None, **kwargs)#
Initialize the lifetime likelihood used to fit the parameters.
fit method is the preferred way to fit model parameters. However, users can also interact with the likelihood returned by init_likelihood to study the optimization process.
- This method implementation is usally composed of 3 steps:
Initialize an object to preprocess and encapsulate observation values.
Create a OptimizerConfig config instance depending on the model needs.
Instanciate and return a LifetimeLikelihood.
init_likelihood is separated from fit in order to reuse existing likelihood parametrization in case of model composition. Any parameters initialization needed by the likelihood optimizer (e.g. x0 or bounds as required in step 2.) are left to specific functions alongside concrete model implementations. These functions are invoked within init_likelihood.
- Parameters:
- time1d array
Observed lifetime values.
- argsany ndarray or tuple of ndarray, default is None
Additional arguments required by the model (e.g. covar).
- event1d array of bool, default is None
Boolean indicators tagging lifetime values as right censored or complete.
- entry1d array, default is None
Left truncations applied to lifetime values.
- **kwargs
Extra arguments to control the parameters optimization. It can be:
those used by scipy.optimize.minimize to search for the paremeters that minimize the negative log-likelihood.
covariance_method to control the method used to estimate parameters covariance. Values can be “cs”, “2point”, “exact” or False. To skip parameters covariance estimation, set covariance_method to False, otherwise the default method associated to the model will be used. If covariance_method is “exact” the hess must be passed too.
- Returns:
- outLifetimeLikelihood instance
- isf(probability)#
The inverse survival function.
- Parameters:
- probabilityfloat or np.ndarray
Probability value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).
- Returns:
- outnp.float64 or np.ndarray
isf values at each given probability value(s).
- jac_cdf(time)#
The jacobian of the cumulative density function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).
- Returns:
- outnp.float64 or np.ndarray
The derivatives with respect to each parameter. If the result is an np.ndarray, the first dimension holds the number of parameters.
- jac_chf(time)[source]#
The jacobian of the cumulative hazard function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).
- Returns:
- outnp.float64 or np.ndarray
The derivatives with respect to each parameter. If the result is an np.ndarray, the first dimension holds the number of parameters.
- jac_hf(time)[source]#
The jacobian of the hazard function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).
- Returns:
- outnp.float64 or np.ndarray
The derivatives with respect to each parameter. If the result is an np.ndarray, the first dimension holds the number of parameters.
- jac_pdf(time)#
The jacobian of the probability density function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).
- Returns:
- outnp.float64 or np.ndarray
The derivatives with respect to each parameter. If the result is an np.ndarray, the first dimension holds the number of parameters.
- jac_sf(time)#
The jacobian of the survival function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).
- Returns:
- outnp.float64 or np.ndarray
The derivatives with respect to each parameter. If the result is an np.ndarray, the first dimension holds the number of parameters.
- ls_integrate(func, a, b, *, deg=10)#
Lebesgue-Stieltjes integration.
- Parameters:
- funccallable (in1 ndarray , out1 ndarray)
The callable must have only one ndarray object as argument and one ndarray object as output.
- andarray (maximum number of dimension is 2)
Lower bound(s) of integration.
- bndarray (maximum number of dimension is 2)
Upper bound(s) of integration. If lower bound(s) is infinite, use np.inf as value.
- degint, default 10
Degree of the polynomials interpolation.
- Returns:
- outnp.ndarray
Lebesgue-Stieltjes integral of func from a to b.
- median()#
The median.
- Returns:
- outnp.float64
- moment(n)#
n-th order moment.
- Parameters:
- nint
order of the moment, at least 1.
- Returns:
- outnp.float64
- mrl(time)[source]#
The mean residual life function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).
- Returns:
- outnp.float64 or np.ndarray
Function values at each given time(s).
- pdf(time)#
The probability density function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).
- Returns:
- outnp.float64 or np.ndarray
pdf values at each given time(s).
- plot(fname, time, *args, ax=None, **kwargs)#
Plot function.
- Parameters:
- fnamestr
The function name to plot. Allowed names are sf, cdf, chf, hf, pdf.
- time1d array
The timeline used for x-axis.
- *args
Any additional args required to compute the function.
- axplt.Axes, optional
An optional existing matplotlib.axes.
- **kwargs
- Extra arguments to configure the plot:
ci : bool, default is True, if False the CI is not plotted
alpha_ci :
any arguments allowed by matplotlib.plot
- ppf(probability)#
The percent point function.
- Parameters:
- probabilityfloat or np.ndarray
Probability value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).
- Returns:
- outnp.float64 or np.ndarray
ppf values at each given probability value(s).
- rvs(size, *, seed=None)#
Random variable sampling.
- Parameters:
- sizeint or tuple (m, n) of int
Size of the generated sample.
- seedoptional int, np.random.BitGenerator, np.random.Generator, np.random.RandomState, default is None
If int or BitGenerator, seed for random number generator. If np.random.RandomState or np.random.Generator, use as given.
- Returns:
- outfloat or ndarray
The sample values.
- set_params(new_params)#
Set the parameters of this model.
- Parameters:
- new_paramsarray-like of floats
Model parameters.
Notes
set_params definition expects an array-like of floats. At runtime, complex parameters might be setted temporarily to approximate fitted parameters covariance. This is contradictory to the given typing. At the moment, we don’t see a better solution and we believe that this is actually a limitation of what be expressed in the static typesystem.
- sf(time)#
The survival function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function. If ndarray, allowed shapes are (), (n,) or (m, n).
- Returns:
- outnp.float64 or np.ndarray
sf values at each given time(s).