engineeringkit.reliability#
Halley’s life table and the bathtub hazard; Poisson failure counts;
exponential, Weibull, lognormal and gamma lifetimes, Epstein-Sobel MTBF
confidence bounds (scipy.stats.chi2) and the Kaplan-Meier estimator for
censored data; median ranks, Weibull rank regression and censored maximum
likelihood; Arrhenius, Eyring and inverse-power-law acceleration factors;
gamma-Poisson Bayesian updating of a failure rate; series, parallel,
k-out-of-n and cold-standby systems, minimal path and cut sets of general
block diagrams and Esary-Proschan bounds, with Birnbaum importance;
Freudenthal’s stress-strength interference, the Hasofer-Lind index and
Monte Carlo with importance sampling; FMEA risk priority numbers and
criticality, fault trees with repeated events, event trees and IEC 61508
safety integrity levels; Markov availability (scipy.linalg.expm),
Barlow-Proschan age replacement and Duane reliability growth.
engineeringkit.reliability: lifetimes, life data, redundancy, structural reliability, risk and maintenance.
Halley’s life table and the bathtub hazard; Poisson failure counts; exponential, Weibull, lognormal and gamma lifetimes with Epstein-Sobel confidence bounds and the Kaplan-Meier estimator for censored data; Weibull parameters by median-rank regression and maximum likelihood; Arrhenius, Eyring and inverse-power-law accelerated life testing; Bayesian updating of a failure rate; series, parallel, k-out-of-n, cold-standby and general block-diagram systems with minimal cut sets and Birnbaum importance; Freudenthal’s stress-strength interference, the Hasofer-Lind index and Monte Carlo; FMEA, Watson’s fault trees, WASH-1400 event trees and IEC 61508 safety integrity levels; Markov availability, Barlow-Proschan age replacement and Duane reliability growth. Models are hand-written closed forms; SciPy supplies special functions, chi-square quantiles and the matrix exponential.
- class engineeringkit.reliability.EventTreeResult(outcomes, frequencies)[source]#
Bases:
objectOutput of
engineeringkit.reliability.event_tree_probability().- Parameters:
outcomes (ndarray)
frequencies (ndarray)
- frequencies: ndarray#
Frequency of each sequence [1/s] (or probability if the initiator was a probability).
- Type:
ndarray
- frequency(failed)[source]#
Total frequency of the sequences in which the functions listed in
failedall fail.- Parameters:
failed (sequence of int) – Indices of the safety functions that must fail.
- Returns:
Summed sequence frequency [1/s].
- Return type:
float
- outcomes: ndarray#
Truewhere a safety function fails in a sequence.- Type:
ndarray of bool, shape
(2**m, m)
- class engineeringkit.reliability.FMEAResult(modes, severity, occurrence, detection, rpn)[source]#
Bases:
objectOutput of
engineeringkit.reliability.fmea_ranking(), failure modes in decreasing risk priority.- Parameters:
modes (tuple)
severity (ndarray)
occurrence (ndarray)
detection (ndarray)
rpn (ndarray)
- detection: ndarray#
Detection ranking of each mode, 1 (certain detection) to 10.
- Type:
ndarray of int
- modes: tuple#
Failure-mode names, highest risk priority number first.
- Type:
tuple of str
- occurrence: ndarray#
Occurrence ranking of each mode, 1 to 10.
- Type:
ndarray of int
- plot(ax=None)[source]#
Draw a Pareto chart of the risk priority numbers; return
(fig, ax).- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to draw on; a new figure is created if omitted.
- Returns:
(fig, ax).- Return type:
tuple
- rpn: ndarray#
Risk priority number, severity x occurrence x detection.
- Type:
ndarray of int
- severity: ndarray#
Severity ranking of each mode, 1 to 10.
- Type:
ndarray of int
- class engineeringkit.reliability.FailureRatePosterior(shape, rate, prior_shape, prior_rate)[source]#
Bases:
objectOutput of
engineeringkit.reliability.bayesian_failure_rate(): a gamma distribution on the failure rate.- Parameters:
shape (float)
rate (float)
prior_shape (float)
prior_rate (float)
- credible_interval(confidence=0.9)[source]#
Equal-tailed credible interval on the failure rate.
- Parameters:
confidence (float, optional) – Posterior probability inside the interval [-], in (0, 1).
- Returns:
(lower, upper)[1/s].- Return type:
tuple of float
- property mean: float#
Posterior mean failure rate, shape over rate [1/s].
- plot(ax=None)[source]#
Draw the prior and posterior densities of the failure rate; return
(fig, ax).- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to draw on; a new figure is created if omitted.
- Returns:
(fig, ax).- Return type:
tuple
- property prior_mean: float#
Prior mean failure rate [1/s].
- prior_rate: float#
Prior gamma rate [s].
- Type:
float
- prior_shape: float#
Prior gamma shape [-].
- Type:
float
- rate: float#
Posterior gamma rate, prior rate plus the time on test [s].
- Type:
float
- shape: float#
Posterior gamma shape, prior shape plus the failures observed [-].
- Type:
float
- class engineeringkit.reliability.HasoferLindResult(beta, design_point, alpha, iterations)[source]#
Bases:
objectOutput of
engineeringkit.reliability.hasofer_lind_index().- Parameters:
beta (float)
design_point (ndarray)
alpha (ndarray)
iterations (int)
- alpha: ndarray#
Unit sensitivity vector;
alpha[i]**2is variablei’s share of the uncertainty [-].- Type:
ndarray
- beta: float#
Hasofer-Lind reliability index, the distance to the limit state in standard normal space [-].
- Type:
float
- design_point: ndarray#
Most probable failure point in the original variables (same units as
mean).- Type:
ndarray
- property failure_probability: float#
First-order failure probability \(\Phi(-\beta)\) [-].
- iterations: int#
HL-RF iterations used.
- Type:
int
- class engineeringkit.reliability.KaplanMeierResult(times, survival, at_risk, failures, std_error, n, censored)[source]#
Bases:
objectOutput of
engineeringkit.reliability.kaplan_meier().- Parameters:
times (ndarray)
survival (ndarray)
at_risk (ndarray)
failures (ndarray)
std_error (ndarray)
n (int)
censored (int)
- at_risk: ndarray#
Units still on test just before each failure time.
- Type:
ndarray of int
- censored: int#
Number of units removed from test without failing.
- Type:
int
- failures: ndarray#
Failures observed at each failure time.
- Type:
ndarray of int
- n: int#
Number of units on test.
- Type:
int
- plot(ax=None, label='Kaplan-Meier')[source]#
Draw the survival step function; return
(fig, ax).- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to draw on; a new figure is created if omitted.
label (str, optional) – Legend label of the curve.
- Returns:
(fig, ax).- Return type:
tuple
- std_error: ndarray#
Greenwood standard error of the survival estimate [-].
- Type:
ndarray
- summary()[source]#
Units on test, failures, censored units and the last survival estimate.
- Return type:
dict
- survival: ndarray#
Product-limit survival estimate just after each failure time [-].
- Type:
ndarray
- survival_at(t)[source]#
Step-function survival estimate, one before the first failure.
- Parameters:
t (float or array_like) – Time(s) [s].
- Returns:
Survival probability [-].
- Return type:
float or ndarray
- times: ndarray#
Distinct failure times [s], increasing.
- Type:
ndarray
- class engineeringkit.reliability.MonteCarloResult(failure_probability, std_error, samples, failures, importance_sampling)[source]#
Bases:
objectOutput of
engineeringkit.reliability.monte_carlo_failure_probability().- Parameters:
failure_probability (float)
std_error (float)
samples (int)
failures (int)
importance_sampling (bool)
- property beta: float#
Reliability index \(-\Phi^{-1}(p_f)\) equivalent to the estimate [-].
- confidence_interval(confidence=0.95)[source]#
Normal-approximation confidence interval on the failure probability, clipped at zero.
- Parameters:
confidence (float, optional) – Two-sided confidence level [-], in (0, 1).
- Returns:
(lower, upper)[-].- Return type:
tuple of float
- property cov: float#
Coefficient of variation of the estimate, standard error over estimate [-] (infinite with no failures).
- failure_probability: float#
Estimated failure probability [-].
- Type:
float
- failures: int#
Number of samples that fell in the failure domain.
- Type:
int
- importance_sampling: bool#
Trueif samples were drawn around a shifted centre and weighted.- Type:
bool
- samples: int#
Number of samples drawn.
- Type:
int
- std_error: float#
Standard error of the estimate [-].
- Type:
float
- class engineeringkit.reliability.WeibullFitResult(eta, beta, method, failure_times, median_ranks, units)[source]#
Bases:
objectOutput of
weibull_rank_regression()andweibull_mle().- Parameters:
eta (float)
beta (float)
method (str)
failure_times (ndarray)
median_ranks (ndarray)
units (int)
- b_life(p)[source]#
Time by which a fraction
pof the population has failed, \(\eta(-\ln(1-p))^{1/\beta}\).- Parameters:
p (float or array_like) – Failure fraction [-], in (0, 1);
0.1gives the B10 life.- Returns:
Life [s].
- Return type:
float or ndarray
- beta: float#
Fitted shape [-].
- Type:
float
- eta: float#
Fitted scale, the characteristic life (63.2% failed) [s].
- Type:
float
- failure_times: ndarray#
Failure times in increasing order [s]; censored units are not listed.
- Type:
ndarray
- median_ranks: ndarray#
Median-rank estimate of the failure probability at each failure time [-].
- Type:
ndarray
- method: str#
"rank regression on y","rank regression on x"or"maximum likelihood".- Type:
str
- plot(ax=None)[source]#
Draw the data and the fitted line on Weibull probability axes; return
(fig, ax).The axes are \(\ln t\) against \(\ln(-\ln(1 - F))\), on which a Weibull distribution is a straight line of slope \(\beta\).
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to draw on; a new figure is created if omitted.
- Returns:
(fig, ax).- Return type:
tuple
- units: int#
Number of units on test, censored ones included.
- Type:
int
- engineeringkit.reliability.adjusted_ranks(times, failed=None)[source]#
Johnson’s adjusted order numbers of the failures in a censored sample.
Units are sorted by time. At the unit in position \(j\) with reverse rank \(r = n - j + 1\), a failure gets the order number \(O_j = (r\,O_{prev} + n + 1)/(r + 1)\), where \(O_{prev}\) is that of the previous failure (zero at first). A censored unit takes no order number but makes every later increment larger, since it might have failed anywhere after its removal. Without censoring the order numbers are
1, 2, ..., n.- Parameters:
times (array_like) – Failure or censoring time of each unit [s], positive.
failed (array_like of {0, 1} or bool, optional) –
1where the unit failed,0where it was censored. Default: every unit failed. At a tie, failures are ranked first.
- Returns:
(failure_times, order): the failure times in increasing order [s] and their adjusted order numbers [-], formedian_ranks().- Return type:
tuple of ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
L. G. Johnson, The Statistical Treatment of Fatigue Experiments (Elsevier, Amsterdam, 1964), ch. 3.
Examples
>>> failure_times, order = adjusted_ranks([10, 20, 30, 40], [1, 0, 1, 1]) >>> np.round(order, 3) array([1. , 2.333, 3.667])
- engineeringkit.reliability.age_replacement_cost_rate(T, preventive_cost, failure_cost, eta, beta)[source]#
Long-run cost per unit time of replacing a Weibull unit at age
Tor at failure.Barlow and Proschan’s renewal-reward ratio, \(C(T) = [c_p R(T) + c_f F(T)] / \int_0^T R(t)\,dt\), with the Weibull integral \(\eta\,\Gamma(1+1/\beta)\,P(1/\beta, (T/\eta)^\beta)\) (\(P\) the regularised lower incomplete gamma function).
- Parameters:
T (float or array_like) – Planned replacement age [s], positive.
preventive_cost (float) – Cost of a planned replacement [currency], nonnegative.
failure_cost (float) – Cost of a replacement after failure [currency], nonnegative.
eta (float) – Weibull scale [s], positive.
beta (float) – Weibull shape [-], positive.
- Returns:
Cost rate [currency/s].
- Return type:
float or ndarray
Notes
A finite optimum exists only if \(\beta > 1\) and \(c_f > c_p\); otherwise the cost rate keeps falling toward \(c_f/\mathrm{MTTF}\) (run to failure). Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
R. E. Barlow and F. Proschan, Mathematical Theory of Reliability (Wiley, 1965), ch. 4.
Examples
>>> round(float(age_replacement_cost_rate(1e9, 1.0, 10.0, 1000.0, 1.0)), 4) 0.01
- engineeringkit.reliability.arrhenius_acceleration_factor(activation_energy, use_temperature, test_temperature)[source]#
Arrhenius acceleration factor \(AF = \exp\left[\frac{E_a}{k_B}\left(\frac{1}{T_u} - \frac{1}{T_t}\right)\right]\).
- Parameters:
activation_energy (float or array_like) – Activation energy \(E_a\) of the failure mechanism [J], nonnegative; 0.7 eV is
0.7 * scipy.constants.eV.use_temperature (float or array_like) – Absolute temperature in service \(T_u\) [K], positive.
test_temperature (float or array_like) – Absolute test temperature \(T_t\) [K], positive.
- Returns:
Ratio of life in service to life on test [-]; above one when the test is hotter.
- Return type:
float or ndarray
Notes
Assumes the test does not switch on a failure mechanism absent in service. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
S. Arrhenius, “Über die Reaktionsgeschwindigkeit bei der Inversion von Rohrzucker durch Säuren,” Z. Phys. Chem. 4 (1889) 226-248.
Examples
>>> from scipy.constants import eV >>> round(float(arrhenius_acceleration_factor(0.7 * eV, 328.15, 398.15)), 1) 77.6
- engineeringkit.reliability.arrhenius_fit(temperatures, lives)[source]#
Least-squares Arrhenius life model \(L = C\,e^{E_a/(k_B T)}\) from lives at several temperatures.
\(\ln L\) is linear in \(1/T\) with slope \(E_a/k_B\), so a straight line through the test points gives the activation energy and the constant; two temperatures fix it exactly.
- Parameters:
temperatures (array_like) – Absolute test temperatures [K], positive, at least two different.
lives (array_like) – Matching characteristic lives (for example Weibull \(\eta\) or median lives) [s], positive.
- Returns:
(activation_energy, constant): \(E_a\) [J] and \(C\) [s].- Return type:
tuple of float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
W. Nelson, Accelerated Testing: Statistical Models, Test Plans, and Data Analyses (Wiley, New York, 1990), ch. 2.
Examples
>>> from scipy.constants import eV >>> energy, constant = arrhenius_fit([398.15, 423.15], [5000.0, 1800.0]) >>> round(energy / eV, 3) 0.593
- engineeringkit.reliability.availability(mtbf, mttr)[source]#
Steady-state availability \(A = \mathrm{MTBF}/(\mathrm{MTBF} + \mathrm{MTTR})\).
- Parameters:
mtbf (float or array_like) – Mean time between failures [s], positive.
mttr (float or array_like) – Mean time to repair [s], nonnegative.
- Returns:
Long-run fraction of time the unit is up [-].
- Return type:
float or ndarray
Notes
This is a long-run average, not the probability of surviving a mission. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> availability(100.0, 25.0) 0.8
- engineeringkit.reliability.bathtub_hazard(t, early_scale=1, early_rate=1, random_rate=0.01, wear_scale=1e-06, wear_power=2)[source]#
Bathtub-shaped hazard: decaying infant mortality, a constant floor and power-law wear-out.
\(h(t) = a e^{-b t} + c + d\,t^{p}\).
- Parameters:
t (float or array_like) – Age [s], nonnegative.
early_scale (float, optional) – Infant-mortality hazard at age zero, \(a\) [1/s].
early_rate (float, optional) – Decay rate of infant mortality, \(b\) [1/s].
random_rate (float, optional) – Constant random-failure hazard, \(c\) [1/s].
wear_scale (float, optional) – Wear-out coefficient, \(d\) [1/s^(p+1)].
wear_power (float, optional) – Wear-out exponent, \(p\) [-].
- Returns:
Hazard rate [1/s].
- Return type:
float or ndarray
Notes
All parameters are nonnegative. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> float(bathtub_hazard(0.0)) 1.01
- engineeringkit.reliability.bayesian_failure_rate(prior_shape, prior_rate, failures, total_time)[source]#
Posterior gamma distribution of a failure rate after a life test.
- Parameters:
prior_shape (float) – Prior gamma shape \(a\) [-], positive.
prior_rate (float) – Prior gamma rate \(b\) [s], positive; the prior mean rate is \(a/b\).
failures (int) – Failures observed \(r\), nonnegative.
total_time (float) – Total time on test summed over all units [s], nonnegative.
- Returns:
The posterior \(\mathrm{Gamma}(a + r, b + T)\), with its mean, credible bounds and
plot()of prior and posterior.- Return type:
Notes
prior_shape,prior_rateandtotal_timeare scalar-only, since the result describes one posterior distribution; update several parts in a loop. The posterior mean \((a + r)/(b + T)\) is a weighted average of the prior mean and the classical estimate \(r/T\), with the data gaining weight as \(T\) grows. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.References
H. Raiffa and R. Schlaifer, Applied Statistical Decision Theory (Harvard University, Boston, 1961), ch. 3 and 7; H. F. Martz and R. A. Waller, Bayesian Reliability Analysis (Wiley, New York, 1982).
Examples
>>> posterior = bayesian_failure_rate(2.0, 1e6, 3, 4e6) >>> posterior.mean 1e-06
- engineeringkit.reliability.birnbaum_importance_series(reliabilities, i)[source]#
Birnbaum importance \(\partial R_s/\partial R_i = \prod_{j \ne i} R_j\) of a series component.
- Parameters:
reliabilities (array_like) – Component reliabilities [-], each in [0, 1].
i (int) – Index of the component, from zero.
- Returns:
Sensitivity of system reliability to component
i[-].- Return type:
float
Notes
In a series system the least reliable component has the largest importance. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
Z. W. Birnbaum, “On the importance of different components in a multicomponent system,” in Multivariate Analysis II (Academic Press, 1969) 581-592.
Examples
>>> round(birnbaum_importance_series([0.7, 0.8, 0.9], 0), 2) 0.72
- engineeringkit.reliability.esary_proschan_bounds(components, reliabilities, source, sink)[source]#
Esary-Proschan lower and upper bounds on block-diagram reliability from minimal cuts and paths.
\(\prod_{C}\left(1 - \prod_{i \in C} q_i\right) \le R \le 1 - \prod_{P}\left(1 - \prod_{i \in P} p_i\right)\), over the minimal cut sets \(C\) and path sets \(P\). The bounds treat the cuts (or paths) as if they failed independently; they are tight when components are reliable (lower) or unreliable (upper).
- Parameters:
components (mapping of str to tuple) –
{name: (node_a, node_b)}.reliabilities (mapping of str to float) – Reliability of each component [-], in [0, 1].
source (hashable) – Input and output nodes of the diagram.
sink (hashable) – Input and output nodes of the diagram.
- Returns:
(lower, upper)[-].- Return type:
tuple of float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
J. D. Esary and F. Proschan, “Coherent structures of non-identical components,” Technometrics 5 (1963) 191-209.
Examples
>>> bridge = {"A": ("s", 1), "B": ("s", 2), "C": (1, 2), "D": (1, "t"), "E": (2, "t")} >>> [round(b, 4) for b in esary_proschan_bounds(bridge, dict.fromkeys(bridge, 0.9), "s", "t")] [0.9781, 0.9973]
- engineeringkit.reliability.event_tree_probability(initiating_frequency, failure_probabilities)[source]#
Frequencies of every sequence of an event tree with independent branch points.
After an initiating event of frequency \(f_0\), each of \(m\) safety functions succeeds or fails; a sequence’s frequency is \(f_0 \prod_j q_j^{\,o_j}(1-q_j)^{1-o_j}\).
- Parameters:
initiating_frequency (float) – Initiating-event frequency [1/s] (or a probability), nonnegative.
failure_probabilities (array_like) – Failure-on-demand probability of each safety function [-], in [0, 1], in the order the tree asks them (at most 20).
- Returns:
The \(2^m\) outcome rows (first function most significant, all successes first) and their frequencies.
- Return type:
Notes
Real event trees prune branches that cannot matter and condition later functions on earlier ones; this helper keeps every branch and assumes independence. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
U.S. Nuclear Regulatory Commission, Reactor Safety Study (WASH-1400, NUREG-75/014, 1975).
Examples
>>> result = event_tree_probability(1e-2, [0.1, 0.5]) >>> np.round(result.frequencies, 4) array([0.0045, 0.0045, 0.0005, 0.0005])
- engineeringkit.reliability.expected_failures(lam, total_time)[source]#
Expected number of failures \(\lambda T\) in a total operating time.
- Parameters:
lam (float or array_like) – Constant failure rate [1/s], nonnegative.
total_time (float or array_like) – Accumulated operating time [s], nonnegative.
- Returns:
Expected count [-].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> expected_failures(0.5, 2.0) 1.0
- engineeringkit.reliability.exponential_failure_probability(t, lam)[source]#
Failure probability \(F(t) = 1 - e^{-\lambda t}\), accurate for tiny \(\lambda t\).
- Parameters:
t (float or array_like) – Time [s], nonnegative.
lam (float or array_like) – Constant failure rate [1/s], nonnegative.
- Returns:
Probability of failure by time
t[-].- Return type:
float or ndarray
Notes
expm1keeps the result accurate when \(\lambda t \ll 1\). Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.Examples
>>> round(float(exponential_failure_probability(1.0, 1e-12)) / 1e-12, 9) 1.0
- engineeringkit.reliability.exponential_hazard(lam)[source]#
Hazard rate of an exponential life, the constant \(\lambda\) itself.
- Parameters:
lam (float or array_like) – Constant failure rate [1/s], nonnegative.
- Returns:
Hazard rate [1/s].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> exponential_hazard(2e-6) 2e-06
- engineeringkit.reliability.exponential_mttf(lam)[source]#
Mean time to failure \(1/\lambda\) of an exponential life.
- Parameters:
lam (float) – Constant failure rate [1/s], positive.
- Returns:
Mean time to failure [s].
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> exponential_mttf(0.5) 2.0
- engineeringkit.reliability.exponential_reliability(t, lam)[source]#
Survival probability \(R(t) = e^{-\lambda t}\) under a constant hazard.
- Parameters:
t (float or array_like) – Time [s], nonnegative.
lam (float or array_like) – Constant failure rate \(\lambda\) [1/s], nonnegative.
- Returns:
Reliability [-], in [0, 1].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> round(float(exponential_reliability(1000.0, 1e-3)), 4) 0.3679
- engineeringkit.reliability.eyring_acceleration_factor(activation_energy, use_temperature, test_temperature)[source]#
Eyring acceleration factor \(AF = \frac{T_t}{T_u}\exp\left[\frac{E_a}{k_B}\left(\frac{1}{T_u} - \frac{1}{T_t}\right)\right]\).
Eyring’s rate \((k_B T/h)\,e^{-\Delta G^\ddagger/(k_B T)}\) puts the temperature in front of the exponential, so life is \(L \propto T^{-1} e^{E_a/(k_B T)}\) and the factor is the Arrhenius one times \(T_t/T_u\).
- Parameters:
activation_energy (float or array_like) – Activation energy [J], nonnegative.
use_temperature (float or array_like) – Absolute temperature in service [K], positive.
test_temperature (float or array_like) – Absolute test temperature [K], positive.
- Returns:
Ratio of life in service to life on test [-].
- Return type:
float or ndarray
Notes
Fitted to the same data, Eyring’s model needs a slightly smaller activation energy than Arrhenius’s, since the prefactor supplies part of the temperature dependence. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
H. Eyring, “The activated complex in chemical reactions,” J. Chem. Phys. 3 (1935) 107-115.
Examples
>>> from scipy.constants import eV >>> round(float(eyring_acceleration_factor(0.7 * eV, 328.15, 398.15)), 1) 94.2
- engineeringkit.reliability.failure_mode_criticality(mode_ratio, loss_probability, lam, time)[source]#
MIL-STD-1629A failure-mode criticality number \(C_m = \beta\,\alpha\,\lambda_p\,t\).
- Parameters:
mode_ratio (float or array_like) – Fraction \(\alpha\) of the part’s failures that occur in this mode [-], in [0, 1].
loss_probability (float or array_like) – Conditional probability \(\beta\) that the mode causes the effect being ranked (loss of mission) [-], in [0, 1].
lam (float or array_like) – Part failure rate \(\lambda_p\) [1/s], nonnegative.
time (float or array_like) – Operating time per mission \(t\) [s], nonnegative.
- Returns:
Expected number of losses from this mode per mission [-]; summing over a part’s modes gives the item criticality.
- Return type:
float or ndarray
Notes
This is the quantitative criticality of the military standard; the RPN of
risk_priority_number()is the qualitative ranking used where failure rates are unknown. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.References
U.S. Department of Defense, Procedures for Performing a Failure Mode, Effects and Criticality Analysis (MIL-STD-1629A, 1980), task 102.
Examples
>>> round(float(failure_mode_criticality(0.4, 0.5, 2e-6, 1e4)), 6) 0.004
- engineeringkit.reliability.failure_probability_from_index(beta)[source]#
Failure probability \(p_f = \Phi(-\beta)\) for a reliability index.
- Parameters:
beta (float or array_like) – Reliability index [-]; negative values mean failure is more likely than not.
- Returns:
Failure probability [-].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> round(float(failure_probability_from_index(3.0)), 6) 0.00135
- engineeringkit.reliability.failure_rate_from_mtbf(mtbf)[source]#
Constant failure rate \(\lambda = 1/\mathrm{MTBF}\).
- Parameters:
mtbf (float or array_like) – Mean time between failures [s], positive.
- Returns:
Failure rate [1/s].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> failure_rate_from_mtbf(10.0) 0.1
- engineeringkit.reliability.fault_tree_probability(tree, probabilities)[source]#
Probability of a fault tree’s top event from independent basic-event probabilities.
A tree is a basic-event name (
str) or a gate tuple("and", child, ...)/("or", child, ...). If no basic event appears twice, gates combine directly: \(\prod p_i\) for AND and \(1 - \prod(1 - p_i)\) for OR. A repeated event makes the gate inputs dependent, so the top event is then evaluated exactly over every state of the basic events.- Parameters:
tree (str or tuple) – Fault-tree structure.
probabilities (mapping of str to float) – Probability of each basic event [-], in [0, 1].
- Returns:
Top-event probability [-].
- Return type:
float
Notes
Exact enumeration is limited to 20 distinct basic events. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
H. A. Watson, Launch Control Safety Study (Bell Telephone Laboratories, 1961); D. F. Haasl, “Advanced concepts in fault tree analysis,” System Safety Symposium (Seattle, 1965).
Examples
>>> round(fault_tree_probability(("or", "A", ("and", "B", "C")), {"A": 0.1, "B": 0.2, "C": 0.5}), 3) 0.19
- engineeringkit.reliability.fmea_ranking(modes)[source]#
Rank failure modes by risk priority number, highest first.
- Parameters:
modes (mapping of str to tuple of int) –
{mode: (severity, occurrence, detection)}, each ranking from 1 to 10.- Returns:
The modes and their rankings sorted by decreasing RPN (ties broken by severity, then name), with
plot()for a Pareto chart.- Return type:
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
U.S. Department of Defense, Procedures for Performing a Failure Mode, Effects and Criticality Analysis (MIL-P-1629, 9 November 1949).
Examples
>>> result = fmea_ranking({"seal leak": (6, 5, 4), "bearing seizure": (9, 2, 7)}) >>> result.modes, result.rpn.tolist() (('bearing seizure', 'seal leak'), [126, 120])
- engineeringkit.reliability.gamma_cdf(t, shape, scale)[source]#
Gamma failure probability \(F(t) = P(k, t/\theta)\), the regularised lower incomplete gamma function.
- Parameters:
t (float or array_like) – Time [s], nonnegative.
shape (float or array_like) – Shape \(k\) [-], positive.
scale (float or array_like) – Scale \(\theta\) [s], positive.
- Returns:
Probability of failure by time
t[-].- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> round(float(gamma_cdf(1.0, 1.0, 1.0)), 4) 0.6321
- engineeringkit.reliability.gamma_hazard(t, shape, scale)[source]#
Gamma hazard rate \(h(t) = f(t)/R(t)\).
- Parameters:
t (float or array_like) – Time [s], nonnegative.
shape (float or array_like) – Shape \(k\) [-], positive.
scale (float or array_like) – Scale \(\theta\) [s], positive.
- Returns:
Hazard rate [1/s]. At
t = 0it is infinite for \(k < 1\), \(1/\theta\) for \(k = 1\) and zero for \(k > 1\); it tends to \(1/\theta\) as \(t \to \infty\) for every shape.- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> round(float(gamma_hazard(1.0, 2.0, 1.0)), 4) 0.5
- engineeringkit.reliability.gamma_mttf(shape, scale)[source]#
Gamma mean life \(k\theta\).
- Parameters:
shape (float or array_like) – Shape \(k\) [-], positive.
scale (float or array_like) – Scale \(\theta\) [s], positive.
- Returns:
Mean time to failure [s].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> gamma_mttf(3.0, 2.0) 6.0
- engineeringkit.reliability.gamma_prior_from_bounds(median, upper, confidence=0.95)[source]#
Gamma prior on a failure rate with a given median and upper percentile.
An engineer can more easily say “the rate is probably about \(\lambda_{50}\) and almost certainly below \(\lambda_{u}\)” than choose a shape and rate. The ratio \(\lambda_u/\lambda_{50}\) fixes the shape \(a\) (it falls as \(a\) grows), found by bisection, and then \(b = P^{-1}(a, 1/2)/\lambda_{50}\).
- Parameters:
median (float) – Prior median failure rate [1/s], positive.
upper (float) – Rate the prior puts below it with probability
confidence[1/s], greater thanmedian.confidence (float, optional) – Prior probability below
upper[-], in (0.5, 1).
- Returns:
(prior_shape, prior_rate): \(a\) [-] and \(b\) [s].- Return type:
tuple of float
- Raises:
ValueError – If the ratio is too wide to fit with a shape above \(10^{-3}\).
Notes
median,upperandconfidenceare scalar-only, since the shape is a root found for one pair of bounds. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.Examples
>>> shape, rate = gamma_prior_from_bounds(1e-6, 3e-6, 0.95) >>> round(shape, 3) 1.782
- engineeringkit.reliability.gamma_reliability(t, shape, scale)[source]#
Gamma survival probability \(R(t) = Q(k, t/\theta)\), the regularised upper incomplete gamma function.
- Parameters:
t (float or array_like) – Time [s], nonnegative.
shape (float or array_like) – Shape \(k\) [-], positive; an integer \(k\) is the life of \(k\) exponential stages in sequence (the Erlang distribution).
scale (float or array_like) – Scale \(\theta\) [s], positive; the mean life of one stage.
- Returns:
Reliability [-].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> round(float(gamma_reliability(1.0, 2.0, 1.0)), 4) 0.7358
- engineeringkit.reliability.hasofer_lind_index(limit_state, mean, std, tol=1e-08, max_iter=100)[source]#
Hasofer-Lind reliability index for independent normal variables (HL-RF iteration).
Each variable is standardised, \(u_i = (x_i - \mu_i)/\sigma_i\), and \(\beta\) is the distance from the origin to the nearest point of the failure surface \(g = 0\). The Rackwitz-Fiessler update \(u_{k+1} = [(\nabla g \cdot u_k - g)/|\nabla g|^2]\,\nabla g\) finds it, with central-difference gradients.
- Parameters:
limit_state (callable) – \(g(x)\) for a 1-D array
x; failure is \(g < 0\).mean (array_like) – Means of the variables (their own units).
std (array_like) – Standard deviations, positive, same length as
mean.tol (float, optional) – Convergence tolerance on the design point in standard space [-].
max_iter (int, optional) – Maximum number of iterations.
- Returns:
Index, design point, sensitivity vector and iteration count. The index is negative if the mean point already lies in the failure domain.
- Return type:
- Raises:
ValueError – If the gradient vanishes or the iteration does not converge.
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
A. M. Hasofer and N. C. Lind, “Exact and invariant second-moment code format,” J. Eng. Mech. Div. ASCE 100 (1974) 111-121; R. Rackwitz and B. Fiessler, “Structural reliability under combined random load sequences,” Comput. Struct. 9 (1978) 489-494.
Examples
>>> result = hasofer_lind_index(lambda x: x[0] - x[1], [500.0, 400.0], [30.0, 40.0]) >>> round(result.beta, 4) 2.0
- engineeringkit.reliability.inverse_power_law_acceleration_factor(use_stress, test_stress, exponent)[source]#
Inverse-power-law acceleration factor \(AF = (V_t/V_u)^n\) for life \(L \propto V^{-n}\).
- Parameters:
use_stress (float or array_like) – Stress in service \(V_u\) (voltage [V], pressure [Pa], mechanical stress [Pa], …), positive.
test_stress (float or array_like) – Test stress \(V_t\), positive, in the same unit.
exponent (float or array_like) – Life-stress exponent \(n\) [-], nonnegative.
- Returns:
Ratio of life in service to life on test [-].
- Return type:
float or ndarray
Notes
Basquin’s fatigue law is the same model with stress amplitude. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
W. Nelson, Accelerated Testing: Statistical Models, Test Plans, and Data Analyses (Wiley, New York, 1990), ch. 2.
Examples
>>> round(float(inverse_power_law_acceleration_factor(230.0, 460.0, 3.0)), 1) 8.0
- engineeringkit.reliability.k_of_n_reliability(n, k, r)[source]#
Reliability of a \(k\)-out-of-\(n\) system of identical independent components.
\(R = \sum_{i=k}^{n} \binom{n}{i} r^i (1-r)^{n-i}\).
- Parameters:
n (int) – Number of components, at least one.
k (int) – Number that must work, from zero to
n.r (float) – Component reliability [-], in [0, 1].
- Returns:
System reliability [-].
- Return type:
float
Notes
k = nis a series system andk = 1a parallel one. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.References
Z. W. Birnbaum, J. D. Esary and S. C. Saunders, “Multi-component systems and structures and their reliability,” Technometrics 3 (1961) 55-77.
Examples
>>> round(k_of_n_reliability(3, 2, 0.9), 3) 0.972
- engineeringkit.reliability.kaplan_meier(times, failed=None)[source]#
Kaplan-Meier product-limit estimate of survival from censored life data.
At each distinct failure time \(t_j\), with \(n_j\) units at risk and \(d_j\) failures, \(\hat S(t) = \prod_{t_j \le t}(1 - d_j/n_j)\). Censored units leave the risk set without moving the curve; a unit censored at a failure time counts as at risk for that failure.
- Parameters:
times (array_like) – Failure or censoring time of each unit [s], nonnegative.
failed (array_like of {0, 1} or bool, optional) –
1where the unit failed,0where it was censored (removed or still running). Default: every unit failed.
- Returns:
Failure times, survival estimate, risk-set sizes, failure counts and Greenwood standard errors.
- Return type:
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
E. L. Kaplan and P. Meier, “Nonparametric estimation from incomplete observations,” J. Amer. Statist. Assoc. 53 (1958) 457-481.
Examples
>>> result = kaplan_meier([1, 2, 3, 4], [1, 0, 1, 1]) >>> np.round(result.survival, 4) array([0.75 , 0.375, 0. ])
- engineeringkit.reliability.life_table_hazard(ages, survivors)[source]#
Piecewise-constant hazard rates from a life table of survivor counts.
Over each interval \([x_i, x_{i+1})\) the hazard \(h_i = -\ln(l_{i+1}/l_i)/(x_{i+1}-x_i)\) reproduces the recorded fall from \(l_i\) to \(l_{i+1}\) survivors exactly.
- Parameters:
ages (array_like) – Ages at which survivors are counted [s], strictly increasing, at least two.
survivors (array_like) – Number alive at each age [-], positive and nonincreasing.
- Returns:
Hazard rate on each of the
len(ages) - 1intervals [1/s].- Return type:
ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
E. Halley, “An estimate of the degrees of the mortality of mankind,” Phil. Trans. R. Soc. 17 (1693) 596-610.
Examples
>>> np.round(life_table_hazard([0, 1, 2], [1000, 500, 250]), 4) array([0.6931, 0.6931])
- engineeringkit.reliability.lognormal_cdf(t, mu, sigma)[source]#
Lognormal failure probability \(F(t) = \Phi\left((\ln t - \mu)/\sigma\right)\).
- Parameters:
t (float or array_like) – Time [s], nonnegative.
mu (float or array_like) – Mean of \(\ln t\) [ln s].
sigma (float or array_like) – Standard deviation of \(\ln t\) [-], positive.
- Returns:
Probability of failure by time
t[-].- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> round(float(lognormal_cdf(np.e, 0.0, 1.0)), 4) 0.8413
- engineeringkit.reliability.lognormal_hazard(t, mu, sigma)[source]#
Lognormal hazard rate \(h(t) = \phi(z)/(\sigma t\,\Phi(-z))\), \(z = (\ln t - \mu)/\sigma\).
- Parameters:
t (float or array_like) – Time [s], nonnegative.
mu (float or array_like) – Mean of \(\ln t\) [ln s].
sigma (float or array_like) – Standard deviation of \(\ln t\) [-], positive.
- Returns:
Hazard rate [1/s]; zero at
t = 0.- Return type:
float or ndarray
Notes
The hazard rises from zero to a maximum and then falls slowly back toward zero, so a lognormal life never wears out for good. The ratio is formed in log space (
log_ndtr) to stay finite far into the tail. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.Examples
>>> round(float(lognormal_hazard(1.0, 0.0, 1.0)), 4) 0.7979
- engineeringkit.reliability.lognormal_mttf(mu, sigma)[source]#
Lognormal mean life \(e^{\mu + \sigma^2/2}\).
- Parameters:
mu (float or array_like) – Mean of \(\ln t\) [ln s].
sigma (float or array_like) – Standard deviation of \(\ln t\) [-], positive.
- Returns:
Mean time to failure [s], longer than the median \(e^\mu\).
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> round(float(lognormal_mttf(0.0, 1.0)), 4) 1.6487
- engineeringkit.reliability.lognormal_reliability(t, mu, sigma)[source]#
Lognormal survival probability \(R(t) = \Phi\left(-(\ln t - \mu)/\sigma\right)\).
- Parameters:
t (float or array_like) – Time [s], nonnegative.
mu (float or array_like) – Mean of \(\ln t\), the log of the median life in seconds [ln s].
sigma (float or array_like) – Standard deviation of \(\ln t\) [-], positive.
- Returns:
Reliability [-].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
D. McAlister, “The law of the geometric mean,” Proc. R. Soc. Lond. 29 (1879) 367-376.
Examples
>>> float(lognormal_reliability(100.0, np.log(100.0), 0.5)) 0.5
- engineeringkit.reliability.maintainability(t, mu)[source]#
Probability \(M(t) = 1 - e^{-\mu t}\) that a repair is finished within
t.- Parameters:
t (float or array_like) – Time since the repair started [s], nonnegative.
mu (float or array_like) – Constant repair rate [1/s], nonnegative.
- Returns:
Probability [-].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> round(float(maintainability(2.0, 0.5)), 4) 0.6321
- engineeringkit.reliability.markov_availability(t, lam, mu)[source]#
Point availability of a repairable unit that starts working at
t = 0.The two-state Markov model gives \(A(t) = \frac{\mu}{\lambda+\mu} + \frac{\lambda}{\lambda+\mu}e^{-(\lambda+\mu)t}\), which decays from one to the steady state with time constant \(1/(\lambda+\mu)\).
- Parameters:
t (float or array_like) – Time [s], nonnegative.
lam (float) – Constant failure rate [1/s], nonnegative.
mu (float) – Constant repair rate [1/s], nonnegative;
lam + mumust be positive.
- Returns:
Probability that the unit is up at time
t[-].- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
R. E. Barlow and F. Proschan, Mathematical Theory of Reliability (Wiley, 1965), ch. 5.
Examples
>>> round(float(markov_availability(1e6, 1e-3, 0.1)), 4) 0.9901
- engineeringkit.reliability.markov_state_probabilities(generator, initial, t)[source]#
State probabilities \(p(t) = p(0)\,e^{Qt}\) of a continuous-time Markov chain.
- Parameters:
- Returns:
Shape
(n,)for scalart, otherwise(len(t), n)[-].- Return type:
ndarray
Notes
Uses SciPy’s matrix exponential. Availability is the summed probability of the up states. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> Q = [[-1e-3, 1e-3], [0.1, -0.1]] >>> np.round(markov_state_probabilities(Q, [1, 0], 1e6), 4) array([0.9901, 0.0099])
- engineeringkit.reliability.median_ranks(n, order=None, method='exact')[source]#
Median-rank plotting positions of ordered failures in a sample of
n.The \(i\)-th smallest of \(n\) lives has a population failure fraction distributed as \(\mathrm{Beta}(i, n - i + 1)\); its median is the exact median rank (Johnson). Benard’s approximation is \((i - 0.3)/(n + 0.4)\).
- Parameters:
n (int) – Number of units on test, at least one.
order (array_like, optional) – Order numbers \(i\) in [1, n]; fractional values from
adjusted_ranks()are allowed. Default:1, 2, ..., n.method ({"exact", "benard"}, optional) – Beta-distribution median or Benard’s approximation.
- Returns:
Estimated failure probability at each order number [-].
- Return type:
ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
L. G. Johnson, “The median ranks of sample values in their population with an application to certain fatigue studies,” Industrial Mathematics 2 (1951) 1-9; A. Benard and E. C. Bos-Levenbach, “Het uitzetten van waarnemingen op waarschijnlijkheids-papier,” Statistica Neerlandica 7 (1953) 163-173.
Examples
>>> np.round(median_ranks(5), 4) array([0.1294, 0.3138, 0.5 , 0.6862, 0.8706]) >>> np.round(median_ranks(5, method="benard"), 4) array([0.1296, 0.3148, 0.5 , 0.6852, 0.8704])
- engineeringkit.reliability.minimal_cut_sets(components, source, sink)[source]#
Minimal cut sets of a reliability block diagram drawn as a network.
A cut set is a set of components whose failure alone disconnects
sourcefromsink; it is minimal if no component can be dropped. The minimal cut sets are the minimal sets that meet every minimal path set, found here by trying sets in order of size.- Parameters:
components (mapping of str to tuple) –
{name: (node_a, node_b)}.source (hashable) – Input and output nodes of the diagram.
sink (hashable) – Input and output nodes of the diagram.
- Returns:
Minimal cut sets, each sorted, smallest first. Empty if
sourceandsinkare not connected at all.- Return type:
list of tuple of str
Notes
Limited to 20 components that lie on some path. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
J. D. Esary and F. Proschan, “Coherent structures of non-identical components,” Technometrics 5 (1963) 191-209.
Examples
>>> bridge = {"A": ("s", 1), "B": ("s", 2), "C": (1, 2), "D": (1, "t"), "E": (2, "t")} >>> minimal_cut_sets(bridge, "s", "t") [('A', 'B'), ('D', 'E'), ('A', 'C', 'E'), ('B', 'C', 'D')]
- engineeringkit.reliability.minimal_path_sets(components, source, sink)[source]#
Minimal path sets of a reliability block diagram drawn as a network.
Each component is a link between two nodes, usable in either direction; the system works if the working components connect
sourcetosink. A minimal path set is a set of components whose working alone connects them and none of which can be dropped: the components along each simple path.- Parameters:
components (mapping of str to tuple) –
{name: (node_a, node_b)}; nodes are any hashable labels.source (hashable) – Input and output nodes of the diagram.
sink (hashable) – Input and output nodes of the diagram.
- Returns:
Minimal path sets, each sorted, shortest first.
- Return type:
list of tuple of str
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
J. D. Esary and F. Proschan, “Coherent structures of non-identical components,” Technometrics 5 (1963) 191-209.
Examples
>>> bridge = {"A": ("s", 1), "B": ("s", 2), "C": (1, 2), "D": (1, "t"), "E": (2, "t")} >>> minimal_path_sets(bridge, "s", "t") [('A', 'D'), ('B', 'E'), ('A', 'C', 'E'), ('B', 'C', 'D')]
- engineeringkit.reliability.monte_carlo_failure_probability(limit_state, mean, std, samples=100000, seed=None, center=None)[source]#
Monte Carlo estimate of \(P(g(X) < 0)\) for independent normal variables.
Crude Monte Carlo draws \(X \sim N(\mu, \sigma^2)\) and counts the fraction of samples with \(g < 0\); its standard error is \(\sqrt{p_f(1 - p_f)/N}\), so about \(100/p_f\) samples are needed for 10% accuracy. Given a
center(typically the Hasofer-Lind design point), samples are drawn around it instead and weighted by the ratio of the true density to the sampling density, \(w = e^{-c \cdot z - |c|^2/2}\) in standard normal space.- Parameters:
limit_state (callable) – \(g(x)\), called once with an array of shape
(m, samples)whose rowiholds the samples of variablei, and returningsamplesvalues; failure is \(g < 0\). A function written withx[0],x[1], … works for both this andhasofer_lind_index().mean (array_like) – Means of the variables (their own units).
std (array_like) – Standard deviations, positive, same length as
mean.samples (int, optional) – Number of samples, at least two.
seed (int or numpy.random.Generator, optional) – Seed or generator, for reproducible results.
center (array_like, optional) – Centre of the importance-sampling density in the original variables. Default: crude Monte Carlo around
mean.
- Returns:
Estimate, standard error, sample and failure counts.
- Return type:
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
N. Metropolis and S. Ulam, “The Monte Carlo method,” J. Amer. Statist. Assoc. 44 (1949) 335-341; G. Harbitz, “An efficient sampling method for probability of failure calculation,” Struct. Saf. 3 (1986) 109-115.
Examples
>>> result = monte_carlo_failure_probability(lambda x: x[0] - x[1], [500.0, 400.0], [30.0, 40.0], seed=1) >>> abs(result.failure_probability - 0.02275) < 3 * result.std_error True
- engineeringkit.reliability.mtbf_confidence_bounds(total_time, failures, confidence=0.9, time_terminated=False)[source]#
Two-sided chi-square confidence bounds on an exponential MTBF from a life test.
With \(r\) failures in total unit-time \(T\), the estimate is \(\hat\theta = T/r\) and \(2T/\theta\) is chi-square with \(2r\) degrees of freedom for a failure-terminated test (Epstein and Sobel). A time-terminated test uses \(2r + 2\) degrees of freedom for the lower bound.
- Parameters:
total_time (float) – Total time on test summed over all units, censored ones included [s], positive.
failures (int) – Number of failures \(r\); at least one for a failure-terminated test, at least zero for a time-terminated one.
confidence (float, optional) – Two-sided confidence level [-], in (0, 1).
time_terminated (bool, optional) –
Trueif the test stopped at a fixed time rather than at the \(r\)-th failure.
- Returns:
(lower, upper)MTBF bounds [s];upperis infinite for a time-terminated test with no failures.- Return type:
tuple of float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
B. Epstein and M. Sobel, “Life testing,” J. Amer. Statist. Assoc. 48 (1953) 486-502.
Examples
>>> [round(b) for b in mtbf_confidence_bounds(10000.0, 5)] [1092, 5076]
- engineeringkit.reliability.network_reliability(components, reliabilities, source, sink)[source]#
Exact reliability of a block diagram with independent components.
The system works in every state of the components in which some minimal path set works entirely; the probabilities of those states are summed over all \(2^m\) states of the \(m\) components on paths.
- Parameters:
components (mapping of str to tuple) –
{name: (node_a, node_b)}.reliabilities (mapping of str to float) – Reliability of each component [-], in [0, 1].
source (hashable) – Input and output nodes of the diagram.
sink (hashable) – Input and output nodes of the diagram.
- Returns:
System reliability [-].
- Return type:
float
Notes
Limited to 20 components that lie on some path. Series, parallel and k-out-of-n systems are special cases. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> bridge = {"A": ("s", 1), "B": ("s", 2), "C": (1, 2), "D": (1, "t"), "E": (2, "t")} >>> round(network_reliability(bridge, dict.fromkeys(bridge, 0.9), "s", "t"), 5) 0.97848
- engineeringkit.reliability.parallel_reliability(*r)[source]#
Reliability of independent components in active parallel, \(1 - \prod_i (1 - R_i)\).
- Parameters:
*r (float) – Component reliabilities [-], each in [0, 1].
- Returns:
System reliability [-].
- Return type:
float
Notes
Assumes perfect switching and no common-cause failures. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
J. von Neumann, “Probabilistic logics and the synthesis of reliable organisms from unreliable components,” in Automata Studies (Princeton, 1956) 43-98.
Examples
>>> round(parallel_reliability(0.9, 0.8), 2) 0.98
- engineeringkit.reliability.poisson_failures_probability(k, lam, total_time)[source]#
Poisson probability of exactly
kfailures, \((\lambda T)^k e^{-\lambda T}/k!\).- Parameters:
k (int) – Number of failures, nonnegative.
lam (float) – Constant failure rate [1/s], nonnegative.
total_time (float) – Accumulated operating time [s], nonnegative.
- Returns:
Probability [-].
- Return type:
float
Notes
Evaluated in log space with
gammalnso that large counts do not overflow. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.References
S.-D. Poisson, Recherches sur la probabilité des jugements en matière criminelle et en matière civile (Paris, Bachelier, 1837).
Examples
>>> round(poisson_failures_probability(0, 1.0, 1.0), 4) 0.3679
- engineeringkit.reliability.reliability_growth_duane(t, K, alpha)[source]#
Duane’s cumulative MTBF \(\theta_c(t) = K t^{\alpha}\) after test time
t.- Parameters:
t (float or array_like) – Cumulative test time [s], positive.
K (float) – Coefficient [s^(1-alpha)], positive: the cumulative MTBF at
t = 1.alpha (float) – Growth rate [-], nonnegative; Duane found 0.3-0.6 for vigorous programmes.
- Returns:
Cumulative MTBF [s]. The instantaneous (current) MTBF is \(\theta_c/(1-\alpha)\).
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
J. T. Duane, “Learning curve approach to reliability monitoring,” IEEE Trans. Aerospace 2 (1964) 563-566.
Examples
>>> float(reliability_growth_duane(4.0, 2.0, 0.5)) 4.0
- engineeringkit.reliability.reliability_index_from_probability(pf)[source]#
Reliability index \(\beta = -\Phi^{-1}(p_f)\) for a failure probability.
- Parameters:
pf (float or array_like) – Failure probability [-], in the open interval (0, 1).
- Returns:
Reliability index [-].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> round(float(reliability_index_from_probability(1e-4)), 3) 3.719
- engineeringkit.reliability.renewal_interval_cost_rate(preventive_cost, failure_cost, lam, T)[source]#
Constant-hazard maintenance cost-rate baseline \(c_p/T + c_f\lambda\).
- Parameters:
preventive_cost (float) – Cost of each scheduled maintenance action [currency], nonnegative.
failure_cost (float) – Cost of each failure [currency], nonnegative.
lam (float) – Constant failure rate [1/s], nonnegative.
T (float) – Maintenance interval [s], positive.
- Returns:
Cost rate [currency/s].
- Return type:
float
Notes
With a constant hazard, scheduled replacement does not change the failure rate, so this cost only falls as
Tgrows. Useage_replacement_cost_rate()for wear-out. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.Examples
>>> renewal_interval_cost_rate(10.0, 20.0, 0.1, 2.0) 7.0
- engineeringkit.reliability.repair_rate(mttr)[source]#
Constant repair rate \(\mu = 1/\mathrm{MTTR}\).
- Parameters:
mttr (float or array_like) – Mean time to repair [s], positive.
- Returns:
Repair rate [1/s].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> repair_rate(2.0) 0.5
- engineeringkit.reliability.risk_priority_number(severity, occurrence, detection)[source]#
FMEA risk priority number \(\mathrm{RPN} = S \times O \times D\).
- Parameters:
severity (int or array_like of int) – Severity of the failure effect, 1 (none) to 10 (hazardous without warning) [-].
occurrence (int or array_like of int) – Likelihood of the failure mode, 1 (remote) to 10 (almost certain) [-].
detection (int or array_like of int) – Chance that current controls miss the mode before it reaches the user, 1 (certain detection) to 10 (no chance) [-].
- Returns:
Risk priority number, 1 to 1000 [-].
- Return type:
int or ndarray of int
Notes
The rankings are ordinal, so the product orders modes but its ratios mean little: a mode with \(S = 10\) can have a lower RPN than a trivial but frequent one, which is why high severities are reviewed whatever their RPN. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
P. D. T. O’Connor and A. Kleyner, Practical Reliability Engineering (5th ed., Wiley, 2012), §7.3.
Examples
>>> risk_priority_number(8, 3, 6) 144
- engineeringkit.reliability.safety_integrity_level(pfd_avg)[source]#
IEC 61508 safety integrity level for a low-demand PFDavg (0 if it meets none).
SIL
PFDavg
4
\(< 10^{-4}\)
3
\([10^{-4}, 10^{-3})\)
2
\([10^{-3}, 10^{-2})\)
1
\([10^{-2}, 10^{-1})\)
0
\(\ge 10^{-1}\)
- Parameters:
pfd_avg (float or array_like) – Average probability of failure on demand [-], in [0, 1].
- Returns:
Safety integrity level.
- Return type:
int or ndarray of int
Notes
The standard’s SIL 4 band starts at \(10^{-5}\); a lower PFDavg is still reported as SIL 4. A level also needs architectural constraints and systematic capability, which a number alone cannot show. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> safety_integrity_level(8.76e-3) 2
- engineeringkit.reliability.safety_integrity_pfd(lam_du, test_interval)[source]#
Average probability of failure on demand of a single channel, \(\lambda_{DU} T/2\).
- Parameters:
lam_du (float or array_like) – Dangerous undetected failure rate [1/s], nonnegative.
test_interval (float or array_like) – Proof-test interval [s], positive.
- Returns:
PFDavg [-].
- Return type:
float or ndarray
- Raises:
ValueError – If any \(\lambda_{DU} T > 0.1\), where the rare-failure approximation no longer holds.
Notes
Assumes perfect proof tests and negligible repair time. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
IEC 61508-6, Functional safety of electrical/electronic/programmable electronic safety-related systems (1998; 2nd ed. 2010), Annex B.
Examples
>>> safety_integrity_pfd(0.001, 10.0) 0.005
- engineeringkit.reliability.series_reliability(*r)[source]#
Reliability of independent components in series, \(R_s = \prod_i R_i\).
- Parameters:
*r (float) – Component reliabilities [-], each in [0, 1].
- Returns:
System reliability [-].
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> round(series_reliability(0.9, 0.8), 2) 0.72
- engineeringkit.reliability.standby_mttf(lam, n=2, switch_reliability=1.0)[source]#
Mean life of
nidentical units in cold standby, \(\sum_{k=0}^{n-1} p^k/\lambda\).- Parameters:
lam (float) – Failure rate of a running unit [1/s], positive.
n (int, optional) – Number of units, at least one.
switch_reliability (float, optional) – Probability that a changeover succeeds [-], in [0, 1].
- Returns:
Mean time to failure [s]; \(n/\lambda\) with a perfect switch.
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> standby_mttf(0.5, 3) 6.0
- engineeringkit.reliability.standby_reliability(t, lam, n=2, switch_reliability=1.0)[source]#
Reliability of
nidentical units in cold standby, \(e^{-\lambda t}\sum_{k=0}^{n-1} p^k(\lambda t)^k/k!\).One unit runs; when it fails a switch, which works with probability \(p\) at each changeover, brings in the next. Spares do not age while waiting. With a perfect switch the system life is the sum of \(n\) exponential lives, a gamma (Erlang) distribution of shape \(n\).
- Parameters:
t (float or array_like) – Mission time [s], nonnegative.
lam (float) – Failure rate of a running unit [1/s], nonnegative.
n (int, optional) – Number of units, the running one included, at least one.
switch_reliability (float, optional) – Probability \(p\) that a changeover succeeds [-], in [0, 1].
- Returns:
System reliability [-].
- Return type:
float or ndarray
Notes
Cold standby with a perfect switch beats active parallel redundancy of the same units, since the spares do not wear while waiting. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
C. E. Ebeling, An Introduction to Reliability and Maintainability Engineering (McGraw-Hill, 1997), §6.5.
Examples
>>> round(float(standby_reliability(1000.0, 1e-3, 2)), 4) 0.7358
- engineeringkit.reliability.stress_strength_reliability(strength_mean, strength_std, stress_mean, stress_std)[source]#
Probability that a normal strength exceeds an independent normal stress.
\(R = \Phi\left((\mu_S - \mu_s)/\sqrt{\sigma_S^2 + \sigma_s^2}\right)\).
- Parameters:
strength_mean (float or array_like) – Mean and standard deviation of the strength [Pa] (or any load unit); the standard deviation is nonnegative.
strength_std (float or array_like) – Mean and standard deviation of the strength [Pa] (or any load unit); the standard deviation is nonnegative.
stress_mean (float or array_like) – Mean and standard deviation of the applied stress, in the same unit.
stress_std (float or array_like) – Mean and standard deviation of the applied stress, in the same unit.
- Returns:
Reliability [-].
- Return type:
float or ndarray
Notes
The two standard deviations may not both be zero. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
A. M. Freudenthal, “The safety of structures,” Trans. ASCE 112 (1947) 125-180.
Examples
>>> round(float(stress_strength_reliability(500e6, 30e6, 400e6, 40e6)), 4) 0.9772
Steady-state unavailability \(1 - A = \mathrm{MTTR}/(\mathrm{MTBF} + \mathrm{MTTR})\).
- Parameters:
mtbf (float or array_like) – Mean time between failures [s], positive.
mttr (float or array_like) – Mean time to repair [s], nonnegative.
- Returns:
Long-run fraction of time the unit is down [-].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> round(unavailability(100.0, 25.0), 2) 0.2
- engineeringkit.reliability.weibull_cdf(t, eta, beta)[source]#
Weibull failure probability \(F(t) = 1 - e^{-(t/\eta)^\beta}\).
- Parameters:
t (float or array_like) – Time [s], nonnegative.
eta (float or array_like) – Scale [s], positive.
beta (float or array_like) – Shape [-], positive.
- Returns:
Probability of failure by time
t[-].- Return type:
float or ndarray
Notes
expm1keeps early-life probabilities accurate. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.Examples
>>> round(float(weibull_cdf(1.0, 1.0, 1.0)), 4) 0.6321
- engineeringkit.reliability.weibull_hazard(t, eta, beta)[source]#
Weibull hazard rate \(h(t) = (\beta/\eta)(t/\eta)^{\beta-1}\).
- Parameters:
t (float or array_like) – Time [s], nonnegative.
eta (float or array_like) – Scale [s], positive.
beta (float or array_like) – Shape [-], positive.
- Returns:
Hazard rate [1/s]; infinite at
t = 0whenbeta < 1.- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> float(weibull_hazard(2.0, 2.0, 1.0)) 0.5
- engineeringkit.reliability.weibull_mle(times, failed=None, ranks='exact')[source]#
Maximum-likelihood Weibull scale and shape from complete or censored life data.
With \(r\) failures among \(n\) units and every unit’s time \(t_i\) (failure or censoring), the shape solves Cohen’s equation
\[\frac{\sum_{i=1}^n t_i^\beta \ln t_i}{\sum_{i=1}^n t_i^\beta} - \frac{1}{\beta} - \frac{1}{r}\sum_{\text{failures}} \ln t_i = 0,\]whose left side increases with \(\beta\), and then \(\eta = (\sum_i t_i^\beta / r)^{1/\beta}\).
- Parameters:
times (array_like) – Failure or censoring time of each unit [s], positive.
failed (array_like of {0, 1} or bool, optional) –
1where the unit failed,0where it was censored. Default: every unit failed.ranks ({"exact", "benard"}, optional) – Median-rank method for the plotted points of the result; the fit does not use them.
- Returns:
Scale, shape and the points for
plot().- Return type:
- Raises:
ValueError – With no failures, or when every failure is at the longest time on test (the likelihood then grows without bound in \(\beta\)).
Notes
Times are scaled by the longest one before solving, which leaves the equation unchanged and keeps \(t^\beta\) from overflowing. Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
A. C. Cohen, “Maximum likelihood estimation in the Weibull distribution based on complete and on censored samples,” Technometrics 7 (1965) 579-588.
Examples
>>> fit = weibull_mle([16, 34, 53, 75, 93, 120]) >>> round(fit.beta, 3), round(fit.eta, 1) (1.933, 73.5)
- engineeringkit.reliability.weibull_mttf(eta, beta)[source]#
Weibull mean life \(\eta\,\Gamma(1 + 1/\beta)\).
- Parameters:
eta (float or array_like) – Scale [s], positive.
beta (float or array_like) – Shape [-], positive.
- Returns:
Mean time to failure [s].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> round(float(weibull_mttf(3.0, 2.0)), 5) 2.65868
- engineeringkit.reliability.weibull_rank_regression(times, failed=None, regress='y', ranks='exact')[source]#
Fit a two-parameter Weibull distribution by least squares on a probability plot.
Each failure time \(t_i\) is plotted at its median rank \(F_i\) (with Johnson’s adjusted ranks for censored data) on the axes \(x = \ln t\), \(y = \ln(-\ln(1 - F))\), where \(y = \beta x - \beta \ln\eta\). Regressing \(y\) on \(x\) is the textbook method; regressing \(x\) on \(y\) treats the times as the uncertain quantity.
- Parameters:
times (array_like) – Failure or censoring time of each unit [s], positive.
failed (array_like of {0, 1} or bool, optional) –
1where the unit failed,0where it was censored. Default: every unit failed.regress ({"y", "x"}, optional) – Dependent variable of the least-squares line.
ranks ({"exact", "benard"}, optional) – Median-rank method, as in
median_ranks().
- Returns:
Scale, shape, the plotted points and
plot()for the probability plot.- Return type:
- Raises:
ValueError – With fewer than two failures at different times.
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
L. G. Johnson, “The median ranks of sample values in their population with an application to certain fatigue studies,” Industrial Mathematics 2 (1951) 1-9; C. E. Ebeling, An Introduction to Reliability and Maintainability Engineering (McGraw-Hill, 1997), §15.
Examples
>>> fit = weibull_rank_regression([16, 34, 53, 75, 93, 120]) >>> round(fit.beta, 3), round(fit.eta, 1) (1.43, 76.3)
- engineeringkit.reliability.weibull_reliability(t, eta, beta)[source]#
Weibull survival probability \(R(t) = e^{-(t/\eta)^\beta}\).
- Parameters:
t (float or array_like) – Time [s], nonnegative.
eta (float or array_like) – Scale (characteristic life, 63.2% failed) [s], positive.
beta (float or array_like) – Shape [-], positive: below one the hazard falls, at one it is constant (exponential), above one it rises.
- Returns:
Reliability [-].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
References
W. Weibull, “A statistical distribution function of wide applicability,” J. Appl. Mech. 18 (1951) 293-297.
Examples
>>> round(float(weibull_reliability(3.0, 3.0, 2.0)), 4) 0.3679
Utilities#
Supporting numerics for engineeringkit.reliability’s systems/ modules.
- engineeringkit.reliability.utils.failure_probability_from_index(beta)[source]#
Failure probability \(p_f = \Phi(-\beta)\) for a reliability index.
- Parameters:
beta (float or array_like) – Reliability index [-]; negative values mean failure is more likely than not.
- Returns:
Failure probability [-].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> round(float(failure_probability_from_index(3.0)), 6) 0.00135
- engineeringkit.reliability.utils.reliability_index_from_probability(pf)[source]#
Reliability index \(\beta = -\Phi^{-1}(p_f)\) for a failure probability.
- Parameters:
pf (float or array_like) – Failure probability [-], in the open interval (0, 1).
- Returns:
Reliability index [-].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Reliability: distributions, independence and rate units.
Examples
>>> round(float(reliability_index_from_probability(1e-4)), 3) 3.719
Visualizers#
Matplotlib visualizers for engineeringkit.reliability.
- engineeringkit.reliability.visualizers.plot_hazard(times, hazard, ax=None, label=None, log=False)[source]#
Plot a hazard rate against time.
- Parameters:
times (array_like) – Times [s].
hazard (array_like) – Matching hazard rates [1/s].
ax (matplotlib.axes.Axes, optional) – Axes to draw on; a new figure is created if omitted.
label (str, optional) – Legend label.
log (bool, optional) – Use a logarithmic hazard axis.
- Return type:
matplotlib.axes.Axes
- engineeringkit.reliability.visualizers.plot_survival(times, survival, ax=None, label=None, step=True)[source]#
Plot a survival (reliability) curve against time.
- Parameters:
times (array_like) – Times [s].
survival (array_like) – Matching survival probabilities [-].
ax (matplotlib.axes.Axes, optional) – Axes to draw on; a new figure is created if omitted.
label (str, optional) – Legend label.
step (bool, optional) – Draw a right-continuous step function (for empirical estimates) instead of a line.
- Return type:
matplotlib.axes.Axes
- engineeringkit.reliability.visualizers.plot_weibull_probability(times, failure_probability, eta=None, beta=None, ax=None, label=None)[source]#
Plot life data on Weibull probability axes, with an optional fitted line.
The axes are \(\ln t\) and \(\ln(-\ln(1 - F))\), the scales of Weibull probability paper, on which a Weibull distribution is a straight line of slope \(\beta\) crossing zero at \(t = \eta\). The right axis is labelled in failure probability.
- Parameters:
times (array_like) – Failure times [s], positive.
failure_probability (array_like) – Matching plotting positions (median ranks) [-], in (0, 1).
eta (float, optional) – Scale [s] and shape [-] of a fitted line to draw; both or neither.
beta (float, optional) – Scale [s] and shape [-] of a fitted line to draw; both or neither.
ax (matplotlib.axes.Axes, optional) – Axes to draw on; a new figure is created if omitted.
label (str, optional) – Legend label of the fitted line.
- Return type:
matplotlib.axes.Axes