<jupyter_start><jupyter_text>Reliability calculations module  Plotting reliabilityReliability formula: $\begin{equation} \mathrm{R} = e^{(\frac{-t}{\eta})^{\beta}} \end{equation}$<jupyter_code>import numpy as np
from math import exp, log, ceil, factorial
import matplotlib.pyplot as plt
%matplotlib inline
# characteristic life
eta = 448.3

# beta
beta = [1.5, 1.0, 2.0, 0.5]

# operations
t = np.linspace(0, 1000, 100)

def plotReliability(eta, beta, t):
    '''Plots reliability based on formula
    
    R = exp(-t/eta)**beta
    
    Inputs:
    -------------
    eta : float (mandatory)
        characteristic life
    beta : list (mandatory)
        exponent in the equation
    t : list or 1d array (mandatory) 
        number of cycles or operations
        
    Returns:
    -------------
    Plot of reliability as a function of operations/cycles
    '''
    # reliability
    R = np.empty([len(t), len(beta)])
    for i in range(len(beta)):
        for k in range(len(t)):
            R[k,i] = exp(-(t[k]/eta)**beta[i])
    
    # plotting
    for m in range(len(beta)):
        plt.plot(t, R[:,m], label = "beta = %s" %beta[m])
    plt.xlabel("Number of operations")
    plt.ylabel("Reliability")
    plt.grid(True)
    plt.legend();

plotReliability(eta, beta, t)<jupyter_output><empty_output><jupyter_text>Non-parametric binomial calculations Reliability and number of samples calculation<jupyter_code># functions definitions

def calculateReliabilityNPB (samples, CL, fails = 0):
    '''Calculate reliability based on confidence limits and number of samples.
    This version takes into account non-parametric binomial distribution
    
    Inputs:
    ------------
    samples: float
        number of tested samples
    CL: float
        confidence limits
    fails: float (optional)
        number of failed samples (by default none)
        
    Returns:
    ------------
    reliability: foat
        reliability number
    
    '''
    return (1-CL)**(1/samples)

def calculateSamplesNPB(rel, CL, fails=0):
    '''
    Calculate number of samples to prove required reliability @ given confidence limits.
    This version takes into account non-parametric binomial distribution
    
    Inputs:
    ------------
    rel: float
        target reliability
    CL: float
        confidence limits
    fails: float (optional)
        number of failed samples (by default none)
        
    Returns:
    ------------
    samples: foat
        number of samples for the test
    '''
    # math.ceil is used to round up to the next full int number
    return ceil(log(1-CL, rel))
# Reliability
R1 = calculateReliabilityNPB(3, 0.5)

# number of samples
n1 = calculateSamplesNPB(0.9, 0.5)

(R1, n1)
# trying to solve for reliability with one failure

from scipy import optimize

def f(x, n, CL):
    n = int(n)
    return (1-factorial(n)/factorial(n-1))*x**n + factorial(n)/factorial(n-1)*x**(n-1) + CL -1


def main(x0, n, CL):
    res = optimize.newton(f, x0, args=(n, CL))
    return res

p = main(0.7, 9, 0.5)

p<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1308472358521426, 'fraction_numerical': 0.01602878639188747, 'mean_word_length': 2.606132075471698, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '241017', 'license': 'MIT', 'n_tokens_mistral': 1002, 'n_tokens_neox': 952, 'n_words': 298, 'path': 'ReliabilityCalculations.ipynb', 'repo_name': 'rafburzy/ReliabilityModule', 'size': '3057'}