How to use the reliability.Utils.round_to_decimals function in reliability

To help you get started, we’ve selected a few reliability examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MatthewReid854 / reliability / reliability / Probability_plotting.py View on Github external
plt.yticks(ytickvals)
    plt.gca().set_yticklabels(['{:,.2%}'.format(x) for x in ytickvals])  # formats y ticks as percentage
    delta = max(x) - min(x)
    xvals = np.linspace(min(x) - delta * 0.5, max(x) + delta * 0.5, 1000)
    if __fitted_dist_params is not None:
        mu = __fitted_dist_params.mu
        sigma = __fitted_dist_params.sigma
    else:
        from reliability.Fitters import Fit_Normal_2P
        fit = Fit_Normal_2P(failures=failures, right_censored=right_censored, show_probability_plot=False, print_results=False)
        mu = fit.mu
        sigma = fit.sigma
    if 'label' in kwargs:
        label = kwargs.pop('label')
    else:
        label = str('Fitted Normal_2P (μ=' + str(round_to_decimals(mu, dec)) + ', σ=' + str(round_to_decimals(sigma, dec)) + ')')
    if 'color' in kwargs:
        color = kwargs.pop('color')
        data_color = color
    else:
        color = 'red'
        data_color = 'k'
    plt.scatter(x, y, marker='.', linewidth=2, c=data_color)
    nf = Normal_Distribution(mu=mu, sigma=sigma).CDF(show_plot=False, xvals=xvals)
    xrange = plt.gca().get_xlim()  # this ensures the previously plotted objects are considered when setting the range
    xrange_min = min(min(x) - delta * 0.2, xrange[0])
    xrange_max = max(max(x) + delta * 0.2, xrange[1])
    plt.xlim([xrange_min, xrange_max])
    plt.title('Probability plot\nNormal CDF')
    plt.xlabel('Time')
    plt.ylabel('Fraction failing')
    plt.gcf().set_size_inches(9, 7)  # adjust the figsize. This is done post figure creation so that layering is easier
github MatthewReid854 / reliability / reliability / Probability_plotting.py View on Github external
beta = __fitted_dist_params.beta
            alpha_SE = __fitted_dist_params.alpha_SE
            beta_SE = __fitted_dist_params.beta_SE
            Cov_alpha_beta = __fitted_dist_params.Cov_alpha_beta
        else:
            from reliability.Fitters import Fit_Weibull_2P
            fit = Fit_Weibull_2P(failures=failures, right_censored=right_censored, CI=CI, show_probability_plot=False, print_results=False)
            alpha = fit.alpha
            beta = fit.beta
            alpha_SE = fit.alpha_SE
            beta_SE = fit.beta_SE
            Cov_alpha_beta = fit.Cov_alpha_beta
        if 'label' in kwargs:
            label = kwargs.pop('label')
        else:
            label = str('Fitted Weibull_2P (α=' + str(round_to_decimals(alpha, dec)) + ', β=' + str(round_to_decimals(beta, dec)) + ')')
        if 'color' in kwargs:
            data_color = kwargs.get('color')
        else:
            data_color = 'k'
        xlabel = 'Time'
    elif fit_gamma is True:
        if __fitted_dist_params is not None:
            alpha = __fitted_dist_params.alpha
            beta = __fitted_dist_params.beta
            gamma = __fitted_dist_params.gamma
            alpha_SE = __fitted_dist_params.alpha_SE
            beta_SE = __fitted_dist_params.beta_SE
            Cov_alpha_beta = __fitted_dist_params.Cov_alpha_beta
        else:
            from reliability.Fitters import Fit_Weibull_3P
            fit = Fit_Weibull_3P(failures=failures, right_censored=right_censored, CI=CI, show_probability_plot=False, print_results=False)
github MatthewReid854 / reliability / reliability / Probability_plotting.py View on Github external
elif fit_gamma is True:
        if __fitted_dist_params is not None:
            Lambda = __fitted_dist_params.Lambda
            Lambda_SE = __fitted_dist_params.Lambda_SE  ####
            gamma = __fitted_dist_params.gamma  ####
        else:
            from reliability.Fitters import Fit_Expon_2P
            fit = Fit_Expon_2P(failures=failures, right_censored=right_censored, CI=CI, show_probability_plot=False, print_results=False)
            Lambda = fit.Lambda
            Lambda_SE = fit.Lambda_SE  ####
            gamma = fit.gamma  ####

        if 'label' in kwargs:
            label = kwargs.pop('label')
        else:
            label = str('Fitted Exponential_2P\n(λ=' + str(round_to_decimals(Lambda, dec)) + ', γ=' + str(round_to_decimals(gamma, dec)) + ')')
        if 'color' in kwargs:  ####
            data_color = kwargs.get('color')  ####
        else:  ####
            data_color = 'k'  ####
        xlabel = 'Time - gamma'  ####
        failures = failures - gamma + 0.009  # this 0.009 adjustment is to avoid taking the log of 0. It causes negligible difference to the fit and plot. 0.009 is chosen to be the same as Weibull_Fit_3P adjustment.
        if right_censored is not None:
            right_censored = right_censored - gamma + 0.009  # this 0.009 adjustment is to avoid taking the log of 0. It causes negligible difference to the fit and plot. 0.009 is chosen to be the same as Weibull_Fit_3P adjustment.

        #### recalculate the xvals for the plotting range when gamma>0
        if max(failures) - gamma < 1:
            xvals = np.logspace(-5, 1, 1000)
        else:
            xvals = np.logspace(-4, np.ceil(np.log10(max(failures) - gamma)) + 1, 1000)  ####needed to adjust the lower lim here so it is > 0
    ef = Exponential_Distribution(Lambda=Lambda, Lambda_SE=Lambda_SE, CI=CI)  ####added extra params and removed .CDF
github MatthewReid854 / reliability / reliability / Probability_plotting.py View on Github external
elif fit_gamma is True:
        if __fitted_dist_params is not None:
            mu = __fitted_dist_params.mu
            sigma = __fitted_dist_params.sigma
            gamma = __fitted_dist_params.gamma
        else:
            from reliability.Fitters import Fit_Lognormal_3P
            fit = Fit_Lognormal_3P(failures=failures, right_censored=right_censored, show_probability_plot=False, print_results=False)
            mu = fit.mu
            sigma = fit.sigma
            gamma = fit.gamma
        lnf = Lognormal_Distribution(mu=mu, sigma=sigma).CDF(show_plot=False, xvals=xvals)
        if 'label' in kwargs:
            label = kwargs.pop('label')
        else:
            label = str('Fitted Lognormal_3P (μ=' + str(round_to_decimals(mu, dec)) + ', σ=' + str(round_to_decimals(sigma, dec)) + ', γ=' + str(round_to_decimals(gamma, dec)) + ')')
        if 'color' in kwargs:
            color = kwargs.pop('color')
            data_color = color
        else:
            color = 'red'
            data_color = 'k'
        plt.xlabel('Time - gamma')
        failures = failures - gamma
        if right_censored is not None:
            right_censored = right_censored - gamma
    # plot the failure points and format the scale and axes
    x, y = plotting_positions(failures=failures, right_censored=right_censored, h1=h1, h2=h2)
    plt.scatter(x, y, marker='.', linewidth=2, c=data_color)
    plt.gca().set_yscale('function', functions=(axes_transforms.normal_forward, axes_transforms.normal_inverse))
    plt.xscale('log')
    plt.grid(b=True, which='major', color='k', alpha=0.3, linestyle='-')
github MatthewReid854 / reliability / reliability / Probability_plotting.py View on Github external
fit_gamma = True

    if fit_gamma is False:
        if __fitted_dist_params is not None:
            mu = __fitted_dist_params.mu
            sigma = __fitted_dist_params.sigma
        else:
            from reliability.Fitters import Fit_Lognormal_2P
            fit = Fit_Lognormal_2P(failures=failures, right_censored=right_censored, show_probability_plot=False, print_results=False)
            mu = fit.mu
            sigma = fit.sigma
        lnf = Lognormal_Distribution(mu=mu, sigma=sigma).CDF(show_plot=False, xvals=xvals)
        if 'label' in kwargs:
            label = kwargs.pop('label')
        else:
            label = str('Fitted Lognormal_2P (μ=' + str(round_to_decimals(mu, dec)) + ', σ=' + str(round_to_decimals(sigma, dec)) + ')')
        if 'color' in kwargs:
            color = kwargs.pop('color')
            data_color = color
        else:
            color = 'red'
            data_color = 'k'
        plt.xlabel('Time')
    elif fit_gamma is True:
        if __fitted_dist_params is not None:
            mu = __fitted_dist_params.mu
            sigma = __fitted_dist_params.sigma
            gamma = __fitted_dist_params.gamma
        else:
            from reliability.Fitters import Fit_Lognormal_3P
            fit = Fit_Lognormal_3P(failures=failures, right_censored=right_censored, show_probability_plot=False, print_results=False)
            mu = fit.mu
github MatthewReid854 / reliability / reliability / Probability_plotting.py View on Github external
beta_SE = __fitted_dist_params.beta_SE
            Cov_alpha_beta = __fitted_dist_params.Cov_alpha_beta
        else:
            from reliability.Fitters import Fit_Weibull_3P
            fit = Fit_Weibull_3P(failures=failures, right_censored=right_censored, CI=CI, show_probability_plot=False, print_results=False)
            alpha = fit.alpha
            beta = fit.beta
            gamma = fit.gamma
            alpha_SE = fit.alpha_SE
            beta_SE = fit.beta_SE
            Cov_alpha_beta = fit.Cov_alpha_beta

        if 'label' in kwargs:
            label = kwargs.pop('label')
        else:
            label = str('Fitted Weibull_3P\n(α=' + str(round_to_decimals(alpha, dec)) + ', β=' + str(round_to_decimals(beta, dec)) + ', γ=' + str(round_to_decimals(gamma, dec)) + ')')
        if 'color' in kwargs:
            data_color = kwargs.get('color')
        else:
            data_color = 'k'
        xlabel = 'Time - gamma'
        failures = failures - gamma
        if right_censored is not None:
            right_censored = right_censored - gamma
    wbf = Weibull_Distribution(alpha=alpha, beta=beta, alpha_SE=alpha_SE, beta_SE=beta_SE, Cov_alpha_beta=Cov_alpha_beta, CI=CI, CI_type=CI_type)

    # plot the failure points and format the scale and axes
    x, y = plotting_positions(failures=failures, right_censored=right_censored, h1=h1, h2=h2)
    plt.scatter(x, y, marker='.', linewidth=2, c=data_color)
    plt.gca().set_yscale('function', functions=(axes_transforms.weibull_forward, axes_transforms.weibull_inverse))
    plt.xscale('log')
    plt.grid(b=True, which='major', color='k', alpha=0.3, linestyle='-')
github MatthewReid854 / reliability / reliability / Probability_plotting.py View on Github external
xlabel = 'Time'
    elif fit_gamma is True:
        if __fitted_dist_params is not None:
            Lambda = __fitted_dist_params.Lambda
            Lambda_SE = __fitted_dist_params.Lambda_SE
            gamma = __fitted_dist_params.gamma
        else:
            from reliability.Fitters import Fit_Expon_2P
            fit = Fit_Expon_2P(failures=failures, right_censored=right_censored, CI=CI, show_probability_plot=False, print_results=False)
            Lambda = fit.Lambda
            Lambda_SE = fit.Lambda_SE
            gamma = fit.gamma
        if 'label' in kwargs:
            label = kwargs.pop('label')
        else:
            label = str('Fitted Exponential_2P\n(λ=' + str(round_to_decimals(Lambda, dec)) + ', γ=' + str(round_to_decimals(gamma, dec)) + ')')
        if 'color' in kwargs:
            data_color = kwargs.get('color')
        else:
            data_color = 'k'
        xlabel = 'Time - gamma'
        failures = failures - gamma
        if right_censored is not None:
            right_censored = right_censored - gamma

        # recalculate the xvals for the plotting range when gamma>0
        if max(failures) - gamma < 1:
            xvals = np.logspace(-5, 2, 1000)
        else:
            xvals = np.logspace(-4, np.ceil(np.log10(max(failures) - gamma)) + 1, 1000)
    ef = Exponential_Distribution(Lambda=Lambda, Lambda_SE=Lambda_SE, CI=CI)
github MatthewReid854 / reliability / reliability / Probability_plotting.py View on Github external
elif fit_gamma is True:
        if __fitted_dist_params is not None:
            alpha = __fitted_dist_params.alpha
            beta = __fitted_dist_params.beta
            gamma = __fitted_dist_params.gamma
        else:
            from reliability.Fitters import Fit_Gamma_3P
            fit = Fit_Gamma_3P(failures=failures, right_censored=right_censored, show_probability_plot=False, print_results=False)
            alpha = fit.alpha
            beta = fit.beta
            gamma = fit.gamma
        gf = Gamma_Distribution(alpha=alpha, beta=beta).CDF(show_plot=False, xvals=xvals)
        if 'label' in kwargs:
            label = kwargs.pop('label')
        else:
            label = str('Fitted Gamma_3P\n(α=' + str(round_to_decimals(alpha, dec)) + ', β=' + str(round_to_decimals(beta, dec)) + ', γ=' + str(round_to_decimals(gamma, dec)) + ')')
        if 'color' in kwargs:
            color = kwargs.pop('color')
            data_color = color
        else:
            color = 'red'
            data_color = 'k'
        plt.xlabel('Time - gamma')
        failures = failures - gamma
        if right_censored is not None:
            right_censored = right_censored - gamma
    # plot the failure points and format the scale and axes
    x, y = plotting_positions(failures=failures, right_censored=right_censored, h1=h1, h2=h2)
    plt.scatter(x, y, marker='.', linewidth=2, c=data_color)
    f_gamma = lambda x: axes_transforms.gamma_forward(x, beta)
    fi_gamma = lambda x: axes_transforms.gamma_inverse(x, beta)
    plt.gca().set_yscale('function', functions=(f_gamma, fi_gamma))