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
Return a model with age replacement, left truncation, or both.
The cumulative distribution function.
The cumulative hazard function.
The derivative of the hazard function.
fitReturn a model with additional arguments stored.
Get the parameters of this model.
The hazard function.
Inverse cumulative hazard function.
Initialize the lifetime likelihood used to fit the parameters.
Whether fitting results are set.
Whether at least one parameter value is set.
The inverse survival function.
The Jacobian of the cumulative distribution 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.
The n-th order moment.
The mean residual life function.
The probability density function.
Plot function.
The percent point function, inverse of the CDF.
Random variate sampling.
Set the parameters of this model.
The survival function.
The variance of the distribution.
- apply_condition(*, ar=None, a0=None)#
Return a model with age replacement, left truncation, or both.
- Parameters:
- arfloat or ndarray, optional
Age replacement threshold.
- a0float or ndarray, optional
Initial age for left truncation.
- Returns:
- outParametricLifetimeModel
Conditioned lifetime model.
- property args_shape#
Shape of additional model arguments.
- cdf(time)#
The cumulative distribution function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function.
- 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.
- Returns:
- outnp.float64 or np.ndarray
chf values at each given time(s).
- dhf(time)[source]#
The derivative of the hazard function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function.
- Returns:
- outnp.float64
- freeze(*args)#
Return a model with additional arguments stored.
- get_params()#
Get the parameters of this model.
- Returns:
- out1darray of floats
Model parameters.
Notes
If parameter values are not set, they default to
np.nanvalues.
- hf(time)[source]#
The hazard function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function.
- 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.
- 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.
fitmethod is the preferred way to fit model parameters. However, users can also interact with the likelihood returned byinit_likelihoodto study the optimization process.- This method implementation is usually composed of 3 steps:
Initialize an object to store and preprocess lifetime values.
Create a
FitConfiginstance depending on the model needs.Instantiate and return a
LifetimeLikelihood.
init_likelihoodis separated fromfitin order to reuse existing likelihood parametrization in case of model composition. Any parameters initialization needed by the likelihood optimizer (e.g.x0orboundsas required in step 2.) are left to specific functions alongside concrete model implementations. These functions are invoked withininit_likelihood.- Parameters:
- time1d array or 2d array
Observed lifetime values. 1d array can handle complete and right censored lifetimes with
event. To add left censored or interval censored lifetimes, use 2d array.- 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 parameters 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
- is_fitted()#
Whether fitting results are set.
- is_parametrized()#
Whether at least one parameter value is set.
- isf(probability)#
The inverse survival function.
- Parameters:
- probabilityfloat or np.ndarray
Probability value(s) at which to compute the function.
- Returns:
- outnp.float64 or np.ndarray
isf values at each given probability value(s).
- jac_cdf(time)#
The Jacobian of the cumulative distribution function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function.
- Returns:
- outnp.float64
- 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.
- Returns:
- outnp.float64
- 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.
- Returns:
- outnp.float64
- 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.
- Returns:
- outnp.float64
- jac_sf(time)#
The Jacobian of the survival function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function.
- Returns:
- outnp.float64
- ls_integrate(func, a, b, *density_args, func_args=(), deg=10)#
Lebesgue-Stieltjes integration.
- Parameters:
- funcCallable
Function to integrate with respect to the lifetime distribution.
- afloat or ndarray
Lower bound of the integration.
- bfloat or ndarray
Upper bound of the integration.
- *density_args
Additional arguments required by the lifetime model.
- func_argstuple, default=()
Additional arguments required by
func.- degint, default=10
Number of sample points and weights for the quadrature.
- Returns:
- outnp.ndarray
Lebesgue-Stieltjes integration of
funcfromatob.
- median()#
The median.
- Returns:
- outnp.float64
- moment(n, *args)#
The n-th order moment.
- Parameters:
- nint
Order of the moment, at least 1.
- *args
Any additional args.
- Returns:
- outnp.float64 or np.ndarray
- mrl(time)[source]#
The mean residual life function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function.
- Returns:
- outnp.float64
- pdf(time)#
The probability density function.
- Parameters:
- timefloat or np.ndarray
Elapsed time value(s) at which to compute the function.
- 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 the model has fitting_results
alpha_ci :
any arguments allowed by matplotlib.plot
- ppf(probability)#
The percent point function, inverse of the CDF.
- Parameters:
- probabilityfloat or np.ndarray
Probability value(s) at which to compute the function.
- Returns:
- outnp.float64 or np.ndarray
ppf values at each given probability value(s).
- rvs(size=None, *, seed=None)#
Random variate 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
Sample values.
- set_params(new_params)#
Set the parameters of this model.
- Parameters:
- new_params1d array-like of floats
Model parameters.
Notes
set_paramsdefinition 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 can 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.
- Returns:
- outnp.float64 or np.ndarray
sf values at each given time(s).