https://raw.githubusercontent.com/MatthewReid854/reliability/master/docs/images/logo.png

Utils

Utils (utilities)

This is a collection of utilities that are used throughout the python reliability library. Functions have been placed here as to declutter the dropdown lists of your IDE and to provide a common resource across multiple modules. It is not expected that users will be using any utils directly.

Included functions are:

  • ALT_MLE_optimization - performs optimization for the ALT_Fitters

  • ALT_fitters_input_checking - performs input checking for the ALT_Fitters

  • ALT_least_squares - least squares estimation for ALT_Fitters

  • ALT_prob_plot - probability plotting for ALT_Fitters

  • LS_optimization - least squares optimization for Fitters

  • MLE_optimization - maximum likelihood estimation optimization for Fitters

  • anderson_darling - calculated the anderson darling (AD) goodness of fit statistic

  • axes_transforms - Custom scale functions used in Probability_plotting

  • clean_CI_arrays - cleans the CI arrays of nan and illegal values

  • colorprint - prints to the console in color, bold, italic, and underline

  • distribution_confidence_intervals - calculates and plots the confidence intervals for the distributions

  • fill_no_autoscale - creates a shaded region without adding it to the global list of objects to consider when autoscale is calculated

  • fitters_input_checking - error checking and default values for all the fitters

  • generate_X_array - generates the X values for all distributions

  • get_axes_limits - gets the current axes limits

  • least_squares - provides parameter estimates for distributions using the method of least squares. Used extensively by Fitters.

  • life_stress_plot - generates the life stress plot for ALT_Fitters

  • line_no_autoscale - creates a line without adding it to the global list of objects to consider when autoscale is calculated

  • linear_regression - given x and y data it will return slope and intercept of line of best fit. Includes options to specify slope or intercept.

  • make_fitted_dist_params_for_ALT_probplots - creates a class structure for the ALT probability plots to give to Probability_plotting

  • no_reverse - corrects for reversals in confidence intervals

  • probability_plot_xylims - sets the x and y limits on probability plots

  • probability_plot_xyticks - sets the x and y ticks on probability plots

  • removeNaNs - removes nan

  • restore_axes_limits - restores the axes limits based on values from get_axes_limits()

  • round_and_string - applies different rounding rules and converts to string

  • show_figure_from_object - Re-shows a figure from an axes or figure handle even after the figure has been closed.

  • transform_spaced - Creates linearly spaced array (in transform space) based on a specified transform. This is like np.logspace but it can make an array that is weibull spaced, normal spaced, etc.

  • validate_CI_params - checks that the confidence intervals have all the right parameters to be generated

  • write_df_to_xlsx - converts a dataframe to an xlsx file

  • xy_transform - provides conversions between spatial (-inf,inf) and axes coordinates (0,1).

  • zeroise_below_gamma - sets all y values to zero when x < gamma. Used when the HF and CHF equations are specified

class reliability.Utils.ALT_MLE_optimization(model, dist, LL_func, initial_guess, optimizer, failures, failure_stress_1, failure_stress_2=None, right_censored=None, right_censored_stress_1=None, right_censored_stress_2=None)

This performs the MLE method to find the parameters. If the optimizer is None then all bounded optimizers will be tried and the best result (lowest log-likelihood) will be returned. If the optimizer is specified then it will be used. If it fails then the initial guess will be returned with a warning.

Parameters:
  • model (str) – Must be either “Exponential”, “Eyring”, “Power”, “Dual_Exponential”, “Power_Exponential”, or “Dual_Power”.

  • dist (str) – Must be either “Weibull”, “Exponential”, “Lognormal”, or “Normal”.

  • LL_func (function) – The log-likelihood function from the fitter

  • initial_guess (list, array) – The initial guess of the model parameters that is used by the optimizer.

  • optimizer (str, None) – This must be either “TNC”, “L-BFGS-B”, “nelder-mead”, “powell”, “best”, “all” or None. Fot detail on how these optimizers are used, please see the documentation.

  • failures (list, array) – The failure data

  • right_censored (list, array) – The right censored data. If there is no right censored data then this should be an empty array.

  • failure_stress_1 (array, list) – The failure stresses.

  • failure_stress_2 (array, list) – The failure second stresses. This is only used for daul stress models.

  • right_censored_stress_1 (array, list) – The right censored stresses. If there is no right censored data then this should be an empty array.

  • right_censored_stress_2 (array, list) – The right censored second stresses. If there is no right censored data then this should be an empty array. This is only used for daul stress models.

Returns:

  • a (float) – Only returned for Exponential, Eyring, Power, Dual_exponential, and Power_Exponential

  • b (float) – Only returned for Exponential and Dual_Exponential

  • c (float) – Only returned for Eyring, Dual_Exponential, Power_Exponential and Dual_Power

  • n (float) – Only returned for Power, Power_Exponential, and Dual_Power

  • m (float) – Only returned for Dual_Power

  • beta (float) – Only returned for Weibull models

  • sigma (float) – Only returned for Normal and Lognormal models

  • success (bool) – Whether at least one optimizer succeeded. If False then the least squares result will be returned in place of the MLE result.

  • optimizer (str, None) – The optimizer used. If MLE failed then None is returned as the optimizer.

Notes

Not all of the above returns are always returned. It depends on which model is being used.

If the MLE method fails then the initial guess (from least squares) will be returned with a printed warning.

class reliability.Utils.ALT_fitters_input_checking(dist, life_stress_model, failures, failure_stress_1, failure_stress_2=None, right_censored=None, right_censored_stress_1=None, right_censored_stress_2=None, CI=0.95, use_level_stress=None, optimizer=None)

This function performs error checking and some basic default operations for all the inputs given to each of the ALT_fitters.

Parameters:
  • dist (str) – Must be one of “Exponential”, “Weibull”, “Lognormal”, “Normal”, “Everything”.

  • life_stress_model (str) – Must be one of “Exponential”, “Eyring”, “Power”,”Dual_Exponential”, “Power_Exponential”, “Dual_Power”, “Everything”.

  • failures (array, list) – The failure data

  • failure_stress_1 (array, list) – The stresses corresponding to the failure data

  • failure_stress_2 (array, list, optional) – The second stresses corresponding to the failure data. Only required for dual stress models. Default is None.

  • right_censored (array, list, optional) – The right censored data. Default is None.

  • right_censored_stress_1 (array, list, optional) – The stresses corresponding to the right censored data. Default is None.

  • right_censored_stress_2 (array, list, optional) – The second stresses corresponding to the right censored data. Only required for dual stress models. Default is None.

  • CI (float, optional) – The confidence interval (between 0 and 1). Default is 0.95 for 95% confidence interval (two sided).

  • optimizer (str, None) – This will return “TNC”, “L-BFGS-B”, “nelder-mead”, “powell”, “best”, or None. Default is None.

  • use_level_stress (float, int, list, array, optional) – The use level stress. Must be float or int for single stress models. Must be array or list [stress_1, stress_2] for dual stress models. Default is None.

Returns:

  • failures (array) – The failure times

  • failure_stress_1 (array) – The failure stresses

  • failure_stress_2 (array) – The second failure stresses. This will be an empty array if the input was None.

  • right_censored (array) – The right censored times. This will be an empty array if the input was None.

  • right_censored_stress_1 (array) – The right censored failure stresses. This will be an empty array if the input was None.

  • right_censored_stress_2 (array) – The right censored second failure stresses. This will be an empty array if the input was None.

  • CI (float) – The confidence interval (between 0 and 1)

  • optimizer (str, None) – This will return “TNC”, “L-BFGS-B”, “nelder-mead”, “powell”, “best”, or None.

  • use_level_stress (float, array, None) – The use level stress. This will be a float for single stress models, or an array for dual stress models. This will be None if the input was None.

  • failure_groups (array) – An array of arrays. This is the failure data grouped by failure stresses.

  • right_censored_groups (array) – An array of arrays. This is the right censored data grouped by right censored stresses.

  • stresses_for_groups (array) – An array of arrays. These are the stresses for each of the groups.

Notes

For full detail on what is checked and the errors produced, you should read the source code.

Some returns are None if the input is None. How None affects the behavior is governed by other functions such as the individual ALT fitters and other Utils.

reliability.Utils.ALT_least_squares(model, failures, stress_1_array, stress_2_array=None)

Uses least squares estimation to fit the parameters of the ALT stress-life model to the time to failure data.

Unlike least_squares for probability distributions, this function does not use the plotting positions because it is working on the life-stress model L(S) and not the life distribution F(t), so it uses the failure data directly.

This function therefore only fits the parameters of the model to the failure data and does not take into account the right censored data. Right censored data is only used when fitting the life-stress distribution (eg. “Weibull Eyring”) which is done using MLE.

The output of this function is used as the initial guess for the MLE method for the life-stress distribution.

Parameters:
  • model (str) – Must be either “Exponential”, “Eyring”, “Power”, “Dual_Exponential”, “Power_Exponential”, or “Dual_Power”

  • failures (array, list) – The failure data

  • stress_1_array (list, array) – The stresses corresponding to the failure data.

  • stress_2_array (list, array, optional) – The second stresses corresponding to the failure data. Used only for dual-stress models. Default is None.

Returns:

model_parameters (list) – The model’s parameters in a list. This depends on the model. Exponential - [a,b], Eyring - [a,c], Power - [a,n], Dual_Exponential - [a,b,c], Power_Exponential - [a,c,n], Dual_Power - [c,m,n]

Notes

For more information on least squares estimation, see the documentation. For more information on fitting ALT models, see the documentation.

For models with more than two parameters, linear algebra is equally valid, but in these cases it is not finding the line of best fit, it is instead finding the plane of best fit.

reliability.Utils.ALT_prob_plot(dist, model, stresses_for_groups, failure_groups, right_censored_groups, life_func, shape, scale_for_change_df, shape_for_change_df, use_level_stress=None, ax=True)

Generates an ALT probability plot using the inputs provided.

Parameters:
  • dist (str) – Must be either “Weibull”, “Exponential”, “Lognormal”, or “Normal”

  • model (str) – Must be either “Exponential”, “Eyring”, “Power”, “Dual_Exponential”, “Power_Exponential”, or “Dual_Power”.

  • stresses_for_groups (list) – The stresses for the failure groups

  • failure_groups (list) – The failure groups. This is a list of lists.

  • right_censored_groups – The failure groups. This is a list of lists.

  • life_func (function) – The life function for the ALT life model.

  • shape (float, int) – The shape parameter of the model.

  • scale_for_change_df (array, list) – The list of scale parameters for the lines.

  • shape_for_change_df – The list of shape parameters for the lines.

  • use_level_stress (float, int, array, list, None) – The use level stress. This must be an array or list for dual stress models. Default is None.

  • ax (axis, bool, optional) – The axis handle to use. Default is True which will create a new plot. If False then no plot will be generated.

Returns:

current_axis (axis) – The axis handle of the plot. If ax is specified in the inputs then this will be the same handle.

class reliability.Utils.LS_optimization(func_name, LL_func, failures, right_censored, method='LS', force_shape=None, LL_func_force=None)

This function is a control function for least squares regression and it is used by each of the Fitters. There is no actual “optimization” done here, with the exception of checking which method (RRX or RRY) gives the better solution.

Parameters:
  • func_name (str) – The function to be fitted. Eg. “Weibull_2P”.

  • LL_func (function) – The log-likelihood function from the fitter

  • failures (list, array) – The failure data

  • right_censored (list, array) – The right censored data. If there is no right censored data then this should be an empty array.

  • method (str, optional) – Must be either “RRX”, “RRY”, “LS”, or “NLLS”. Default is “LS”.

  • force_shape (float, int, optional) – The shape parameter to be forced. Default is None which results in no forcing of the shape parameter.

  • LL_func_force (function) – The log-likelihood function for when the shape parameter is forced. Only required if force_shape is not None.

Returns:

  • guess (list) – The guess of the models parameters. The length of this list depends on the number of parameters in the model. The guess is obtained using Utils.least_squares

  • method (str) – The method used. This will be either “RRX”, “RRY” or “NLLS”.

Notes

If method=”LS” then both “RRX” and “RRY” will be tried and the best one will be returned.

class reliability.Utils.MLE_optimization(func_name, LL_func, initial_guess, failures, right_censored, optimizer, force_shape=None, LL_func_force=None)

This function performs Maximum Likelihood Estimation (MLE) to find the optimal parameters of the probability distribution. This functions is used by each of the fitters.

Parameters:
  • func_name (str) – The function to be fitted. Eg. “Weibull_2P”.

  • LL_func (function) – The log-likelihood function from the fitter

  • initial_guess (list, array) – The initial guess of the model parameters that is used by the optimizer.

  • failures (list, array) – The failure data

  • right_censored (list, array) – The right censored data. If there is no right censored data then this should be an empty array.

  • optimizer (str, None) – This must be either “TNC”, “L-BFGS-B”, “nelder-mead”, “powell”, “best”, “all” or None. Fot detail on how these optimizers are used, please see the documentation.

  • force_shape (float, int, optional) – The shape parameter to be forced. Default is None which results in no forcing of the shape parameter.

  • LL_func_force (function) – The log-likelihood function for when the shape parameter is forced. Only required if force_shape is not None.

Returns:

  • scale (float) – Only returned for Weibull_2P, Weibull_3P, Lognormal_2P, Lognormal_3P, Gamma_2P, Gamma_3P, Loglogistic_2P, Loglogistic_3P, Exponential_1P, Exponential_2P, Normal_2P, Beta_2P, and Gumbel_2P

  • shape (float) – Only returned for Weibull_2P, Weibull_3P, Lognormal_2P, Lognormal_3P, Gamma_2P, Gamma_3P, Loglogistic_2P, Loglogistic_3P, Normal_2P, Beta_2P, and Gumbel_2P

  • alpha (float) – Only returned for Weibull_DS, Weibull_ZI and Weibull_DSZI

  • beta (float) – Only returned for Weibull_DS, Weibull_ZI and Weibull_DSZI

  • gamma (float) – Only returned for Weibull_3P, Exponential_2P, Gamma_3P, Lognormal_3P, and Loglogistic_3P.

  • DS (float) – Only returned for Weibull_DS and Weibull_DSZI

  • ZI (float) – Only returned for Weibull_ZI and Weibull_DSZI

  • alpha_1 (float) – Only returned for Weibull_mixture and Weibull_CR

  • beta_1 (float) – Only returned for Weibull_mixture and Weibull_CR

  • alpha_2 (float) – Only returned for Weibull_mixture and Weibull_CR

  • beta_2 (float) – Only returned for Weibull_mixture and Weibull_CR

  • proportion_1 (float) – Only returned for Weibull_mixture

  • proportion_2 (float) – Only returned for Weibull_mixture

  • success (bool) – Whether at least one optimizer succeeded. If False then the least squares result will be returned in place of the MLE result.

  • optimizer (str, None) – The optimizer used. If MLE failed then None is returned as the optimizer.

Notes

Not all of the above returns are always returned. It depends on which model is being used.

If the MLE method fails then the initial guess (from least squares) will be returned with a printed warning.

reliability.Utils.anderson_darling(fitted_cdf, empirical_cdf)

Calculates the Anderson-Darling goodness of fit statistic. These formulas are based on the method used in MINITAB which gives an adjusted form of the original AD statistic described on Wikipedia.

Parameters:
  • fitted_cdf (list, array) – The fitted CDF values at the data points

  • empirical_cdf (list, array) – The empirical (rank adjustment) CDF values at the data points

Returns:

AD (float) – The anderson darling (adjusted) test statistic.

class reliability.Utils.axes_transforms

Custom scale functions used in Probability_plotting Each of these functions is either a forward or inverse transform.

There are no parameters for this class, only a collection of subfunctions which can be called individually to perform the transforms.

static beta_forward(F, alpha, beta)
static beta_inverse(R, alpha, beta)
static exponential_forward(F)
static exponential_inverse(R)
static gamma_forward(F, beta)
static gamma_inverse(R, beta)
static gumbel_forward(F)
static gumbel_inverse(R)
static loglogistic_forward(F)
static loglogistic_inverse(R)
static normal_forward(F)
static normal_inverse(R)
static weibull_forward(F)
static weibull_inverse(R)
reliability.Utils.clean_CI_arrays(xlower, xupper, ylower, yupper, plot_type='CDF', x=None, q=None)

This function cleans the CI arrays of nans and numbers <= 0 and also removes numbers >= 1 if plot_type is CDF or SF.

Parameters:
  • xlower (list, array) – The lower x array for the confidence interval

  • xupper (list, array) – The upper x array for the confidence interval

  • ylower (list, array) – The lower y array for the confidence interval

  • yupper (list, array) – The upper y array for the confidence interval

  • plot_type (str, optional) – Must be “CDF”, “SF”, “CHF”. Default is “CDF”

  • x (array, optional) – The x array for CI extraction

  • q (array, optional) – The q array for CI extraction

Returns:

  • xlower (array) – The “cleaned” lower x array for the confidence interval

  • xupper (array) – The “cleaned” upper x array for the confidence interval

  • ylower (array) – The “cleaned” lower y array for the confidence interval

  • ylower (array) – The “cleaned” upper y array for the confidence interval

Notes

The returned arrays will all be the same length

The cleaning is done by deleting values. If the cleaned arrays are < 2 items in length then an error will be triggered.

reliability.Utils.colorprint(string, text_color=None, background_color=None, bold=False, underline=False, italic=False)

Provides easy access to color printing in the console.

This function is used to print warnings in red text, but it can also do a lot more.

Parameters:
  • string

  • text_color (str, None, optional) – Must be either grey, red, green, yellow, blue, pink, or turquoise. Use None to leave the color as white. Default is None.

  • background_color (str, None, optional) – Must be either grey, red, green, yellow, blue, pink, or turquoise. Use None to leave the color as the transparent. Default is None.

  • bold (bool, optional) – Default is False.

  • underline (bool, optional) – Default is False.

  • italic (bool, optional) – Default is False.

Returns:

None – The output is printed to the console.

Notes

Some flexibility in color names is allowed. eg. red and r will both give red.

As there is only one string argument, if you have multiple strings to print, you must first combine them using str(string_1,string_2,…).

class reliability.Utils.distribution_confidence_intervals

This class contains several subfunctions that provide all the confidence intervals for CDF, SF, CHF for each distribution for which it is implemented.

The class has no parameters or returns as it is used primarily to create the confidence interval object which is used by the subfunctions.

Parameters:

None

Returns:

None

static exponential_CI(self, func='CDF', plot_CI=None, CI=None, text_title='', color=None, q=None, x=None)

Generates the confidence intervals for CDF, SF, and CHF of the Exponential distribution.

Parameters:
  • self (object) – The distribution object

  • func (str) – Must be either “CDF”, “SF” or “CHF”. Default is “CDF”

  • plot_CI (bool, None) – The confidence intervals will only be plotted if plot_CI is True.

  • CI (float) – The confidence interval. Must be between 0 and 1

  • text_title (str) – The existing CDF/SF/CHF text title to which the confidence interval string will be added.

  • color (str) – The color to be used to fill the confidence intervals.

  • q (array, list, optional) – The quantiles to be calculated. Default is None.

  • x (array, list, optional) – The x-values to be calculated. Default is None.

Returns:

  • t_lower (array) – The lower bounds on time. Only returned if q is not None.

  • t_upper (array) – The upper bounds on time. Only returned if q is not None.

  • R_lower (array) – The lower bounds on reliability. Only returned if x is not None.

  • R_upper (array) – The upper bounds on reliability. Only returned if x is not None.

Notes

self must contain particular values for this function to work. These include self.Lambda_SE and self.Z.

As a Utils function, there is very limited error checking done, as this function is not intended for users to access directly.

For the Exponential distribution, the bounds on time and reliability are the same.

For an explaination of how the confidence inervals are calculated, please see the documentation.

static gamma_CI(self, func='CDF', plot_CI=None, CI_type=None, CI=None, text_title='', color=None, q=None, x=None)

Generates the confidence intervals for CDF, SF, and CHF of the Gamma distribution.

Parameters:
  • self (object) – The distribution object

  • func (str) – Must be either “CDF”, “SF” or “CHF”. Default is “CDF”.

  • plot_CI (bool, None) – The confidence intervals will only be plotted if plot_CI is True.

  • CI_type (str) – Must be either “time” or “reliability”

  • CI (float) – The confidence interval. Must be between 0 and 1

  • text_title (str) – The existing CDF/SF/CHF text title to which the confidence interval string will be added.

  • color (str) – The color to be used to fill the confidence intervals.

  • q (array, list, optional) – The quantiles to be calculated. Default is None. Only used if CI_type=’time’.

  • x (array, list, optional) – The x-values to be calculated. Default is None. Only used if CI_type=’reliability’.

Returns:

  • t_lower (array) – The lower bounds on time. Only returned if CI_type is “time” and q is not None.

  • t_upper (array) – The upper bounds on time. Only returned if CI_type is “time” and q is not None.

  • R_lower (array) – The lower bounds on reliability. Only returned if CI_type is “reliability” and x is not None.

  • R_upper (array) – The upper bounds on reliability. Only returned if CI_type is “reliability” and x is not None.

Notes

self must contain particular values for this function to work. These include self.mu_SE, self.beta_SE, self.Cov_mu_beta, self.Z.

As a Utils function, there is very limited error checking done, as this function is not intended for users to access directly.

For an explaination of how the confidence inervals are calculated, please see the documentation.

static gumbel_CI(self, func='CDF', plot_CI=None, CI_type=None, CI=None, text_title='', color=None, q=None, x=None)

Generates the confidence intervals for CDF, SF, and CHF of the Gumbel distribution.

Parameters:
  • self (object) – The distribution object

  • func (str) – Must be either “CDF”, “SF” or “CHF”. Default is “CDF”.

  • plot_CI (bool, None) – The confidence intervals will only be plotted if plot_CI is True.

  • CI_type (str) – Must be either “time” or “reliability”

  • CI (float) – The confidence interval. Must be between 0 and 1

  • text_title (str) – The existing CDF/SF/CHF text title to which the confidence interval string will be added.

  • color (str) – The color to be used to fill the confidence intervals.

  • q (array, list, optional) – The quantiles to be calculated. Default is None. Only used if CI_type=’time’.

  • x (array, list, optional) – The x-values to be calculated. Default is None. Only used if CI_type=’reliability’.

Returns:

  • t_lower (array) – The lower bounds on time. Only returned if CI_type is “time” and q is not None.

  • t_upper (array) – The upper bounds on time. Only returned if CI_type is “time” and q is not None.

  • R_lower (array) – The lower bounds on reliability. Only returned if CI_type is “reliability” and x is not None.

  • R_upper (array) – The upper bounds on reliability. Only returned if CI_type is “reliability” and x is not None.

Notes

self must contain particular values for this function to work. These include self.mu_SE, self.sigma_SE, self.Cov_mu_sigma, self.Z.

As a Utils function, there is very limited error checking done, as this function is not intended for users to access directly.

For an explaination of how the confidence inervals are calculated, please see the documentation.

static loglogistic_CI(self, func='CDF', plot_CI=None, CI_type=None, CI=None, text_title='', color=None, q=None, x=None)

Generates the confidence intervals for CDF, SF, and CHF of the Loglogistic distribution.

Parameters:
  • self (object) – The distribution object

  • func (str) – Must be either “CDF”, “SF” or “CHF”. Default is “CDF”.

  • plot_CI (bool, None) – The confidence intervals will only be plotted if plot_CI is True.

  • CI_type (str) – Must be either “time” or “reliability”

  • CI (float) – The confidence interval. Must be between 0 and 1

  • text_title (str) – The existing CDF/SF/CHF text title to which the confidence interval string will be added.

  • color (str) – The color to be used to fill the confidence intervals.

  • q (array, list, optional) – The quantiles to be calculated. Default is None. Only used if CI_type=’time’.

  • x (array, list, optional) – The x-values to be calculated. Default is None. Only used if CI_type=’reliability’.

Returns:

  • t_lower (array) – The lower bounds on time. Only returned if CI_type is “time” and q is not None.

  • t_upper (array) – The upper bounds on time. Only returned if CI_type is “time” and q is not None.

  • R_lower (array) – The lower bounds on reliability. Only returned if CI_type is “reliability” and x is not None.

  • R_upper (array) – The upper bounds on reliability. Only returned if CI_type is “reliability” and x is not None.

Notes

self must contain particular values for this function to work. These include self.alpha_SE, self.beta_SE, self.Cov_alpha_beta, self.Z.

As a Utils function, there is very limited error checking done, as this function is not intended for users to access directly.

For an explaination of how the confidence inervals are calculated, please see the documentation.

static lognormal_CI(self, func='CDF', plot_CI=None, CI_type=None, CI=None, text_title='', color=None, q=None, x=None)

Generates the confidence intervals for CDF, SF, and CHF of the Lognormal distribution.

Parameters:
  • self (object) – The distribution object

  • func (str) – Must be either “CDF”, “SF” or “CHF”. Default is “CDF”.

  • plot_CI (bool, None) – The confidence intervals will only be plotted if plot_CI is True.

  • CI_type (str) – Must be either “time” or “reliability”

  • CI (float) – The confidence interval. Must be between 0 and 1

  • text_title (str) – The existing CDF/SF/CHF text title to which the confidence interval string will be added.

  • color (str) – The color to be used to fill the confidence intervals.

  • q (array, list, optional) – The quantiles to be calculated. Default is None. Only used if CI_type=’time’.

  • x (array, list, optional) – The x-values to be calculated. Default is None. Only used if CI_type=’reliability’.

Returns:

  • t_lower (array) – The lower bounds on time. Only returned if CI_type is “time” and q is not None.

  • t_upper (array) – The upper bounds on time. Only returned if CI_type is “time” and q is not None.

  • R_lower (array) – The lower bounds on reliability. Only returned if CI_type is “reliability” and x is not None.

  • R_upper (array) – The upper bounds on reliability. Only returned if CI_type is “reliability” and x is not None.

Notes

self must contain particular values for this function to work. These include self.mu_SE, self.sigma_SE, self.Cov_mu_sigma, self.Z.

As a Utils function, there is very limited error checking done, as this function is not intended for users to access directly.

For an explaination of how the confidence inervals are calculated, please see the documentation.

static normal_CI(self, func='CDF', plot_CI=None, CI_type=None, CI=None, text_title='', color=None, q=None, x=None)

Generates the confidence intervals for CDF, SF, and CHF of the Normal distribution.

Parameters:
  • self (object) – The distribution object

  • func (str) – Must be either “CDF”, “SF” or “CHF”. Default is “CDF”.

  • plot_CI (bool, None) – The confidence intervals will only be plotted if plot_CI is True.

  • CI_type (str) – Must be either “time” or “reliability”

  • CI (float) – The confidence interval. Must be between 0 and 1

  • text_title (str) – The existing CDF/SF/CHF text title to which the confidence interval string will be added.

  • color (str) – The color to be used to fill the confidence intervals.

  • q (array, list, optional) – The quantiles to be calculated. Default is None. Only used if CI_type=’time’.

  • x (array, list, optional) – The x-values to be calculated. Default is None. Only used if CI_type=’reliability’.

Returns:

  • t_lower (array) – The lower bounds on time. Only returned if CI_type is “time” and q is not None.

  • t_upper (array) – The upper bounds on time. Only returned if CI_type is “time” and q is not None.

  • R_lower (array) – The lower bounds on reliability. Only returned if CI_type is “reliability” and x is not None.

  • R_upper (array) – The upper bounds on reliability. Only returned if CI_type is “reliability” and x is not None.

Notes

self must contain particular values for this function to work. These include self.mu_SE, self.sigma_SE, self.Cov_mu_sigma, self.Z.

As a Utils function, there is very limited error checking done, as this function is not intended for users to access directly.

For an explaination of how the confidence inervals are calculated, please see the documentation.

static weibull_CI(self, func='CDF', plot_CI=None, CI_type=None, CI=None, text_title='', color=None, q=None, x=None)

Generates the confidence intervals for CDF, SF, and CHF of the Weibull distribution.

Parameters:
  • self (object) – The distribution object

  • func (str) – Must be either “CDF”, “SF” or “CHF”. Default is “CDF”

  • plot_CI (bool, None) – The confidence intervals will only be plotted if plot_CI is True.

  • CI_type (str) – Must be either “time” or “reliability”

  • CI (float) – The confidence interval. Must be between 0 and 1

  • text_title (str) – The existing CDF/SF/CHF text title to which the confidence interval string will be added.

  • color (str) – The color to be used to fill the confidence intervals.

  • q (array, list, optional) – The quantiles to be calculated. Default is None. Only used if CI_type=’time’.

  • x (array, list, optional) – The x-values to be calculated. Default is None. Only used if CI_type=’reliability’.

Returns:

  • t_lower (array) – The lower bounds on time. Only returned if CI_type is “time” and q is not None.

  • t_upper (array) – The upper bounds on time. Only returned if CI_type is “time” and q is not None.

  • R_lower (array) – The lower bounds on reliability. Only returned if CI_type is “reliability” and x is not None.

  • R_upper (array) – The upper bounds on reliability. Only returned if CI_type is “reliability” and x is not None.

Notes

self must contain particular values for this function to work. These include self.alpha_SE, self.beta_SE, self.Cov_alpha_beta, self.Z.

As a Utils function, there is very limited error checking done, as this function is not intended for users to access directly.

For an explaination of how the confidence inervals are calculated, please see the documentation.

reliability.Utils.distributions_input_checking(self, func, xvals, xmin, xmax, show_plot=None, plot_CI=None, CI_type=None, CI=None, CI_y=None, CI_x=None)

Performs checks and sets default values for the inputs to distributions sub function (PDF, CDF, SF, HF, CHF)

Parameters:
  • self (object) – Distribution object created by reliability.Distributions

  • func (str) – Must be either ‘PDF’,’CDF’, ‘SF’, ‘HF’, ‘CHF’

  • xvals (array, list) – x-values for plotting.

  • xmin (int, float) – minimum x-value for plotting.

  • xmax (int, float) – maximum x-value for plotting.

  • show_plot (bool) – Whether the plot is to be shown.

  • plot_CI (bool, optional) – Whether the confidence intervals are to be shown on the plot. Default is None.

  • CI_type (str, optional) – If specified, it must be “time” or “reliability”. Default is None

  • CI (float, optional) – The confidence intervals. If specified, it must be between 0 and 1. Default is None.

  • CI_y (list, array, optional) – The confidence interval y-values to trace. Default is None.

  • CI_x (list, array, optional) – The confidence interval x-values to trace. Default is None.

Returns:

  • X (array) – An array of the x-values for the plot. Created using generate_X_array

  • xvals (array, list) – x-values for plotting.

  • xmin (int, float) – minimum x-value for plotting.

  • xmax (int, float) – maximum x-value for plotting.

  • show_plot (bool) – Whether the plot is to be shown. Default is True. Only returned if func is ‘PDF’,’CDF’, ‘SF’, ‘HF, or ‘CHF’

  • plot_CI (bool) – Whether the confidence intervals are to be shown on the plot. Default is True. Only returned if func is ‘CDF’, ‘SF’, or ‘CHF’ and self.name !=’Beta’.

  • CI_type (str) – The type of confidence interval. Will be either “time”, “reliability”, or “none”. Default is “time”. Only returned if func is ‘CDF’, ‘SF’, or ‘CHF’. If self.name ==’Beta’ or self.name==’Exponential’ it will return ‘none’. If self.CI_type is specified and CI_type is not specified then self.CI_type will be used for CI_type.

  • CI (float) – The confidence intervals between 0 and 1. Default is 0.95. Only returned if func is ‘CDF’, ‘SF’, or ‘CHF’ and self.name !=’Beta’. If self.CI is specified and CI is None then self.CI will be used for CI.

  • CI_y (list, array, float, int) – The confidence interval y-values to trace. Default is None. Only returned if func is ‘CDF’, ‘SF’, or ‘CHF’ and self.name !=’Beta’.

  • CI_x (list, array, float, int) – The confidence interval x-values to trace. Default is None. Only returned if func is ‘CDF’, ‘SF’, or ‘CHF’ and self.name !=’Beta’.

reliability.Utils.extract_CI(dist, func='CDF', CI_type='time', CI=0.95, CI_y=None, CI_x=None)

Extracts the confidence bounds at CI_x or CI_y.

Parameters:
  • dist (object) – Distribution object from reliability.Distributions

  • func (str) – Must be either ‘CDF’, ‘SF’, ‘CHF’

  • CI_type (str) – Must be either ‘time’ or ‘reliability’

  • CI (float) – The confidence interval. Must be between 0 and 1.

  • CI_y (list, array) – The y-values from which to extract the confidence interval (x-values) for bounds on time.

  • CI_x (list, array) – The x-values from which to extract the confidence interval (y-values) for bounds on reliability.

Returns:

  • lower (array) – An array of the lower confidence bounds at CI_x or CI_y

  • upper (array) – An array of the upper confidence bounds at CI_x or CI_y

Notes

If CI_type=”time” then CI_y must be specified in order to extract the confidence bounds on time.

If CI_type=”reliability” then CI_x must be specified in order to extract the confidence bounds on reliability.

reliability.Utils.fill_no_autoscale(xlower, xupper, ylower, yupper, **kwargs)

Creates a filled region (polygon) without adding it to the global list of autoscale objects. Use this function when you want to plot something but not have it considered when autoscale sets the range.

Parameters:
  • xlower (list, array) – The lower x array for the polygon.

  • xupper (list, array) – The upper x array for the polygon.

  • ylower (list, array) – The lower y array for the polygon.

  • ylower (list, array) – The upper y array for the polygon.

  • kwargs – keyword arguments passed to the matplotlib PolyCollection

Returns:

None – The filled polygon will be added to the plot.

class reliability.Utils.fitters_input_checking(dist, failures, right_censored=None, method=None, optimizer=None, CI=0.95, quantiles=False, force_beta=None, force_sigma=None, CI_type=None)

This function performs error checking and some basic default operations for all the inputs given to each of the fitters.

Parameters:
  • dist (str) – Must be one of “Everything”, “Weibull_2P”, “Weibull_3P”, “Gamma_2P”, “Gamma_3P”, “Exponential_1P”, “Exponential_2P”, “Gumbel_2P”, “Normal_2P”, “Lognormal_2P”, “Lognormal_3P”, “Loglogistic_2P”, “Loglogistic_3P”, “Beta_2P”, “Weibull_Mixture”, “Weibull_CR”, “Weibull_DSZI”, “Weibull_DS”, “Weibull_ZI”.

  • failures (array, list) – The failure data

  • right_censored (array, list, optional) – The right censored data

  • method (str, optional) – Must be either “MLE”,”LS”,”RRX”, or “RRY”. Some flexibility in input is tolerated. eg “LS”, “LEAST SQUARES”, “LSQ”, “NLRR”, “NLLS” will all be recogsised as “LS”. Default is MLE

  • optimizer (str, optional) – Must be one of “TNC”, “L-BFGS-B”, “nelder-mead”, “powell”, “best”. Default is None which will result in each being tried until one succeeds. For more detail see the documentation.

  • CI (float, optional) – Confidence interval. Must be between 0 and 1. Default is 0.95 for 95% confidence interval (2 sided).

  • quantiles (array, list, bool, optional) – An array or list of the quantiles to calculate. If True then the default array will be used. Default array is [0.01, 0.05, 0.1, 0.2, 0.25, 0.5, 0.75, 0.8, 0.9, 0.95, 0.99]. If False then no quantiles will be calculated. Default is False.

  • force_beta (float, int, optional) – Used to force beta for the Weibull_2P distribution. Default is None which will not force beta.

  • force_sigma (float, int, optional) – Used to force sigma for the Normal_2P and Lognormal_2P distributions. Default is None which will not force sigma.

  • CI_type (str, optional) – Must be either “time” or “reliability”. Default is None which results in “time” being used (controlled in Fitters). Some flexibility is strings is allowed. eg. “r”, “R”, “rel”, “REL”, “reliability”, “RELIABILITY” will all be recognized as “reliability”.

Returns:

  • failures (array) – The failure times

  • right_censored (array) – The right censored times. This will be an empty array if the input was None.

  • CI (float) – The confidence interval (between 0 and 1)

  • method (str, None) – This will return “MLE”, “LS”, “RRX”, “RRY” or None.

  • optimizer (str, None) – This will return “TNC”, “L-BFGS-B”, “nelder-mead”, “powell”, “best”, or None.

  • quantiles (array, None) – The quantiles or None.

  • force_beta (float, None) – The beta parameter to be forced in Weibull_2P

  • force_sigma (float, None) – The sigma parameter to be forced in Normal_2P, or Lognormal_2P

  • CI_type (str, None) – “time”, “reliability”, ‘None’ or None

Notes

For full detail on what is checked and the errors produced, you should read the source code.

Some returns are None if the input is None. How None affects the behavior is governed by other functions such as the individual fitters and other Utils.

reliability.Utils.generate_X_array(dist, xvals=None, xmin=None, xmax=None)

Generates the array of X values for each of the PDf, CDF, SF, HF, CHF functions within reliability.Distributions

This is done with a variety of cases in order to ensure that for regions of high gradient (particularly asymptotes to inf) the points are more concentrated. This ensures that the line always looks as smooth as possible using only 200 data points.

Parameters:
  • dist (object) – The distribution object

  • xvals (array, list, optional) – The xvals for the plot if specified

  • xmin (array, list, optional) – The xmin for the plot if specified

  • xmax (array, list, optional) – The xmax for the plot if specified

Returns:

X (array) – The X array that was generated.

reliability.Utils.get_axes_limits()

This function works in a pair with restore_axes_limits This function gets the previous xlim and ylim and also checks whether there was a previous plot (based on whether the default 0,1 axes had been changed).

It returns a list of items that are used by restore_axes_limits after the plot has been performed.

Parameters:

None – The plot properties are extracted automatically for analysis

Returns:

output (list) – A list of [xlims, ylims, use_prev_lims]. These values are used by restore_axes_limits to determine how the axes limits need to be changed after plotting.

reliability.Utils.least_squares(dist, failures, right_censored, method='RRX', force_shape=None)

Uses least squares or non-linear least squares estimation to fit the parameters of the distribution to the plotting positions.

Plotting positions are based on failures and right_censored so while least squares estimation does not consider the right_censored data in the same way as MLE, the plotting positions do. This means that right censored data are not ignored by least squares estimation, but the way the values are treated differs between least squares and MLE.

The output of this method may be used as the initial guess for the MLE method.

Parameters:
  • dist (object) – Thew distribution object

  • failures (array, list) – The failure data

  • right_censored (array, list) – The right censored data. If there is no data then this should be an empty list.

  • method (str, optional) – Must be “RRX” or “RRY”. Default is RRX.

  • force_shape (float, int, optional) – Used to force the shape (beta or sigma) parameter. Default is None which will not force the slope.

Returns:

model_parameters (list) – The model’s parameters in a list. eg. for “Weibull_2P” it will return [alpha,beta]. For “Weibull_3P” it will return [alpha,beta,gamma].

Notes

For more information on least squares estimation, see the documentation.

For cases where the CDF is not linearizable (eg. Weibull_3P), this function uses non-linear least squares (NLLS) which uses scipy’s curve_fit to find the parameters. This may sometimes fail as curve_fit is an optimization routine that needs an initial guess provided by this function.

reliability.Utils.life_stress_plot(model, dist, life_func, failure_groups, stresses_for_groups, use_level_stress=None, ax=True)

Generates a life stress plot using the inputs provided. The life stress plot is an output from each of the ALT_fitters.

Parameters:
  • model (str) – Must be either “Exponential”, “Eyring”, “Power”, “Dual_Exponential”, “Power_Exponential”, or “Dual_Power”.

  • dist (str) – Must be either “Weibull”, “Exponential”, “Lognormal”, or “Normal”

  • life_func (function) – The life function for the ALT life model.

  • failure_groups (list) – The failure groups. This is a list of lists.

  • stresses_for_groups (list) – The stresses for the failure groups

  • use_level_stress (float, int, array, list, None) – The use level stress. This must be an array or list for dual stress models. Default is None.

  • ax (axes, bool, optional) – The axes handle to use. Default is True which will create a new plot. If False then no plot will be generated. This is also used to flip the x and y axes to make a stress-life plot. Use ax=’swap’ to make the life-stress plot change its axes to be a stress-life plot (similar to SN diagram).

Returns:

current_axes (axes) – The axes handle of the plot. If ax is specified in the inputs then this will be the same handle.

reliability.Utils.line_no_autoscale(x, y, **kwargs)

Creates a line without adding it to the global list of autoscale objects. Use this when you want to plot something but not have it considered when autoscale sets the range.

Parameters:
  • x (array, list) – The x values for the line

  • y (array, list) – The y values for the line

  • kwargs – keyword arguments passed to the matplotlib LineCollection

Returns:

None – The line will be added to the plot.

reliability.Utils.linear_regression(x, y, slope=None, x_intercept=None, y_intercept=None, RRX_or_RRY='RRX', show_plot=False, **kwargs)

This function provides the linear algebra solution to find line of best fit passing through points (x,y). Options to specify slope or intercept enable these parameters to be forced.

Rank regression can be on X (RRX) or Y (RRY). Default is RRX. Note that slope depends on RRX_or_RRY. If you use RRY then slope is dy/dx but if you use RRX then slope is dx/dy.

Parameters:
  • x (array, list) – The x values

  • y (array, list) – The y values

  • slope (float, int, optional) – Used to force the slope. Default is None.

  • x_intercept (float, int, optional) – Used to force the x-intercept. Default is None. Only used for RRY.

  • y_intercept (float, int, optional) – Used to force the y-intercept. Default is None. Only used for RRX.

  • RRX_or_RRY (str, optional) – Must be “RRY” or “RRX”. Default is “RRY”.

  • show_plot (bool, optional) – If True, a plot of the line and points will be generated. Use plt.show() to show it.

  • kwargs – Keyword arguments for the plot that are passed to matplotlib for the line.

Returns:

  • slope (float) – The slope of the line.

  • intercept (float) – The intercept (x or y depending on RRX_or_RRY) of the line.

Notes

The equation of a line used here is Y = slope * X + intercept. This is the RRY form. For RRX it can be rearranged to X = (Y - intercept)/slope

For more information on linear regression, see the documentation.

class reliability.Utils.make_fitted_dist_params_for_ALT_probplots(dist, params)

This function creates a class structure for the ALT probability plots to give to Probability_plotting.

Parameters:
  • dist (str) – The distribution. Must be either “Weibull”, “Lognormal”, “Normal”, or “Exponential”.

  • params (list, array) – The parameters of the model. Must be 2 elements for Weibull, Lognormal, and Normal, and must be 1 element for Exponential.

Returns:

  • alpha (float) – Only returned for Weibull

  • beta (float) – Only returned for Weibull

  • gamma (int) – This will always be 0. Only returned for Weibull, Lognormal, and Exponential.

  • alpha_SE (None) – Only returned for Weibull

  • beta_SE (None) – Only returned for Weibull

  • Cov_alpha_beta (None) – Only returned for Weibull

  • mu (float) – Only returned for Normal and Lognormal

  • sigma (float) – Only returned for Normal and Lognormal

  • Cov_mu_sigma (None) – Only returned for Normal and Lognormal

  • Lambda (float) – Only returned for Exponential

  • Lambda_SE (None) – Only returned for Exponential

Notes

This function only exists to convert a list or array of parameters into a class with the correct parameters for the probability plots to use.

reliability.Utils.no_reverse(x, CI_type, plot_type)

This is used to convert an array that decreases and then increases into an array that decreases then is constant at its minimum.

The always decreasing rule will apply unless CI_type = ‘time’ and plot_type = ‘CHF’

This function is used to provide a correction to the confidence intervals which mathematically are correct but practically should never decrease.

Parameters:
  • x (array, list) – The array or list to which the no_reverse correction is applied

  • CI_type (str) – Must be either ‘time’ or ‘reliability’

  • plot_type (str) – Must be either ‘CDF’, ‘SF’, or ‘CHF’

Returns:

x (array) – A corrected form of the input x that obeys the always decreasing rule (or the always increasing rule in the case of CI_type = ‘time’ and plot_type = ‘CHF’).

reliability.Utils.probability_plot_xylims(x, y, dist, spacing=0.1, gamma_beta=None, beta_alpha=None, beta_beta=None)

This function finds what the x and y limits of probability plots should be and sets these limits. This is similar to autoscaling, but the rules here are different to the matplotlib defaults. It is used extensively by the functions within the probability_plotting module to achieve the plotting style used within this library.

Parameters:
  • x (list, array) – The x-values from the plot

  • y (list, array) – The y-values from the plot

  • dist (str) – Must be either “weibull”, “lognormal”, “loglogistic”, “normal”, “gamma”, “exponential”, “beta”, or “gumbel”.

  • spacing (float) – The spacing between the points and the edge of the plot. Default is 0.1 for 10% spacing.

  • gamma_beta (float, int, optional) – The beta parameter from the gamma distribution. Only required if dist = “gamma”.

  • beta_alpha (float, int, optional) – The alpha parameter from the beta distribution. Only required if dist = “beta”.

  • beta_beta (float, int, optional) – The beta parameter from the beta distribution. Only required if dist = “beta”.

Returns:

None – There are no outputs from this function. It will set the xlim() and ylim() of the probability plot automatically.

reliability.Utils.probability_plot_xyticks(yticks=None)

This function sets the x and y ticks for probability plots.

X ticks are selected using either MaxNLocator or LogLocator. X ticks are formatted using a custom formatter.

Y ticks are specified with FixedLocator due to their irregular spacing. Minor y ticks use MaxNLocator. Y ticks are formatted using a custom Percent Formatter that handles decimals better than the default.

This function is used by all the probability plots.

Within this function are several sub functions that are called internally.

Parameters:

yticks (list, array) – The yticks to use. If unspecified, the default yticks are [0.0001, 0.001, 0.002, 0.005, 0.01, 0.02, 0.03, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.95, 0.99, 0.999, 0.9999, 0.999999].

Returns:

None – This function will set the ticks but it does not return anything.

reliability.Utils.removeNaNs(X)

Removes NaNs from a list or array.

Parameters:

X (array, list) – The array or list to be processed.

Returns:

output (list, array) – A list or array of the same type as the input with the NaNs removed.

Notes

This is better than simply using “x = x[numpy.logical_not(numpy.isnan(x))]” as numpy crashes for str and bool.

reliability.Utils.reshow_figure(handle)

Shows a figure from an axes handle or figure handle. This is useful if the handle is saved to a variable but the figure has been closed. Note that the Navigation Toolbar (for pan, zoom, and save) is still connected to the old figure. There is no known work around for this issue.

Parameters:

handle (object) – The axes handle (type(_axes.Axes)) or figure handle (type(Figure))

Returns:

None – The figure is automatically shown using plt.show().

reliability.Utils.restore_axes_limits(limits, dist, func, X, Y, xvals=None, xmin=None, xmax=None)

This function works in a pair with get_axes_limits. Using the values producted by get_axes_limits which are [xlims, ylims, use_prev_lims], this function will determine how to change the axes limits to meet the style requirements of the library.

Parameters:
  • limits (list) – A list of [xlims, ylims, use_prev_lims] created by get_axes_limits

  • dist (object) – The distribution object which the axes limits are influenced by.

  • X (array, list) – The x-values of the plot

  • Y (array, list) – The y-values of the plot

  • xvals (array, list, optional) – The plot xvals if specified. May be None if not specified.

  • xmin (int, float, optional) – The plot xmin if specified. May be None if not specified.

  • xmax (int, float, optional) – The plot xmax if specified. May be None if not specified.

Returns:

None – This function will scale the plot but it does not return anything

Notes

No scaling will be done if the axes are not linear due to errors that result from log and function scaled axes when a limit of 0 is used. This means that this function is not able to be applied to the probability plots are they have non-linear scaled axes.

reliability.Utils.round_and_string(number, decimals=5, integer_floats_to_ints=True, large_scientific_limit=1000000000.0, small_scientific_limit=0.0001)

This function is used to round a number to a specified number of decimals and convert to string. It is used heavily in the formatting of the parameter titles within reliability.Distributions

The rules applied are slightly different than rounding to a number of significant figures as it keeps more preceeding zeros. Special formatting rules are applied when:

abs(number) <= small_scientific_limit abs(number) >= large_scientific_limit number = 0

Parameters:
  • number (float) – The number to be rounded

  • decimals (int) – The number of decimals (not including preceeding zeros) that are to be in the output

  • integer_floats_to_ints (bool, optional) – Default is True. Removes trailing zeros from floats if there are no significant decimals (eg. 12.0 becomes 12).

  • large_scientific_limit (int, float, optional) – The limit above which to keep numbers formatted in scientific notation. Default is 1e9.

  • small_scientific_limit (int, float, optional) – The limit below which to keep numbers formatted in scientific notation. Default is 1e-4.

Returns:

out (string) – The number formatted and converted to string.

Notes

Examples (with decimals = 5):

original: -1e+20 // new: -1e+20 original: -100000000.0 // new: -100000000 original: -10.0 // new: -10 original: -5.4857485e-05 // new: -5.48575e-05 original: -2.54875415e-16 // new: -2.54875e-16 original: 0.0 // new: 0 original: 0 // new: 0 original: 2.54875415e-16 // new: 2.54875e-16 original: 5.4857485e-05 // new: 5.48575e-05 original: 10.0 // new: 10 original: 100000000.0 // new: 100000000 original: 1e+20 // new: 1e+20

reliability.Utils.transform_spaced(transform, y_lower=1e-08, y_upper=0.99999999, num=1000, alpha=None, beta=None)

Creates linearly spaced array based on a specified transform.

This is similar to np.linspace or np.logspace but is designed for weibull space, exponential space, normal space, gamma space, loglogistic space, gumbel space and beta space.

It is useful if the points generated are going to be plotted on axes that are scaled using the same transform and need to look equally spaced in the transform space.

Parameters:
  • transform (str) – The transform name. Must be either weibull, exponential, normal, gamma, gumbel, loglogistic, or beta.

  • y_upper (float, optional) – The lower bound (must be within the bounds 0 to 1). Default is 1e-8

  • y_lower (float, optional) – The upper bound (must be within the bounds 0 to 1). Default is 1-1e-8

  • num (int, optional) – The number of values in the array. Default is 1000.

  • alpha (int, float, optional) – The alpha value of the beta distribution. Only used if the transform is beta

  • beta (int, float, optional) – The beta value of the beta or gamma distribution. Only used if the transform is beta or gamma

Returns:

transformed_array (array) – transform spaced array. This appears linearly spaced when plotted in transform space.

Notes

Note that lognormal is the same as normal, since the x-axis is what is transformed in lognormal, not the y-axis.

reliability.Utils.unpack_single_arrays(array)

Unpacks arrays with a single element to return just that element

Parameters:

array (float, int, list, array) – The value for unpacking

Returns:

output (float, list, int, array) – If the input was a single length numpy array then the output will be the item from the array. If the input was anything else then the output will match the input

reliability.Utils.validate_CI_params(*args)

Returns False if any of the args is None or Nan, else returns True. This function is different to using all() because it performs the checks using np.isfinite(arg).

Parameters:

*args (bool) – Any number of boolean arguments

Returns:

is_valid (bool) – False if any of the args is None or Nan else returns True.

reliability.Utils.write_df_to_xlsx(df, path, **kwargs)

Writes a dataframe to an xlsx file For use exclusively by the Convert_data module

Parameters:
  • df (dataframe) – The dataframe to be written

  • path (str) – The file path to the xlsx file.

Returns:

None – Writing the dataframe is the only action from this function.

Notes

The path must include the full file path including the extension. It is also necessary to use r at the start to specify raw text. See the documentation for an example.

reliability.Utils.xy_downsample(x, y, downsample_factor=None, default_max_values=1000)

This function downsamples the x and y arrays. This exists to make plotting much faster, particularly when matplotlib becomes very slow for tens of thousands of datapoints.

Parameters:
  • x (array, list) – The x values

  • y (array, list) – The y values

  • downsample_factor (int, optional) – How must downsampling to do. See Notes for more detail.

  • default_max_values (int, optional) – The maximum number of values to be returned if downsample_factor is None. See Notes for more detail.

Returns:

  • x (array) – The downsampled x values

  • y (array) – The downsampled y values

Notes

Downsampling is done using the downsample_factor. If the down_sample factor is 2 then every second value will be returned, if 3 then every third value will be returned. The first and last items will always be included in the downsampled dataset.

If downsample_factor is not specified, downsampling will only occur if there are more than default_max_values. The downsample factor will aim for the number of values to be returned to be between default_max_values/2 and default_max_values. By default this is between 500 and 1000.

reliability.Utils.xy_transform(value, direction='forward', axis='x')

This function converts between data values and axes coordinates (based on xlim() or ylim()).

If direction is forward the returned value will always be between 0 and 1 provided the value is on the plot.

If direction is reverse the input should be between 0 and 1 and the returned value will be the data value based on the current plot lims

Parameters:
  • value (int, float, list, array) – The value/s to be transformed

  • direction (str, optional) – Must be “forward” or “inverse”. Default is “forward”

  • axis (str, optional) – Must be “x” or “y”. Default is “x”.

Returns:

transformed_values (float, array) – The transformed values. This will be a float if the input was int or float, or an array if the input was list or array.

reliability.Utils.zeroise_below_gamma(X, Y, gamma)

This will make all Y values 0 for the corresponding X values being below gamma (the threshold parameter for Weibull, Exponential, Gamma, Loglogistic, and Lognormal).

Used by HF and CHF which need to be zeroized if the gamma shifted form of the equation is used.

Parameters:
  • X (array, list) – The x values of the distribution. These areused to determine whis Y values to zeroize.

  • Y (array, list) – The y-values of the distribution

  • gamma (float, int) – The gamma parameter. This is the point at which Y values corresponding to X values below gamma will be zeroized.

Returns:

Y (array) – The zeroized Y array