<jupyter_start><jupyter_text>Table of Contents1&nbsp;&nbsp;Empirical Input Modelling1.1&nbsp;&nbsp;Non-Parametric Modelling1.2&nbsp;&nbsp;Empirical Modelling1.3&nbsp;&nbsp;Empirical Modelling of Grouped Data2&nbsp;&nbsp;Fitting of a Theoretical Distribution for Service Time2.1&nbsp;&nbsp;Check Independence of Data2.2&nbsp;&nbsp;Select Suitable Distribution Function2.3&nbsp;&nbsp;Parameter Estimation2.3.1&nbsp;&nbsp;Plotting Routine (same as before)2.3.2&nbsp;&nbsp;Plot2.4&nbsp;&nbsp;Goodness-of-Fit-Test (χ²)3&nbsp;&nbsp;Fitting of a Theoretical Distribution for Inter Arrival Time3.1&nbsp;&nbsp;Check Independence of Data3.2&nbsp;&nbsp;Select Suitable Distribution Function3.3&nbsp;&nbsp;Parameter Estimation3.3.1&nbsp;&nbsp;Plotting Routine (same as before)3.3.2&nbsp;&nbsp;Plot3.4&nbsp;&nbsp;Goodness-of-Fit-Test<jupyter_code>import matplotlib as mpl
import matplotlib.pyplot as plt
import scipy.stats as stats
import numpy as np
import pandas as pd
import random
import math
dt=pd.read_csv('ATM.csv')
dt
random.seed(0)<jupyter_output><empty_output><jupyter_text>Empirical Input Modelling  Non-Parametric Modelling Picks with constant probability one of the empirical values obtained<jupyter_code>def st():
    u=random.random()*len(dt)
    return dt['ST'][math.floor(u)]
data=pd.DataFrame([st() for i in range(100000)])
data.hist(bins=40, density=True)
plt.grid(True)<jupyter_output><empty_output><jupyter_text>Empirical Modelling<jupyter_code>dts=pd.DataFrame(dt.sort_values(by=['ST']))
dts['U']=np.arange(len(dts))/(len(dts)-1)
dts=dts.set_index(np.arange(len(dts)))
dts['DST']=dts['ST']-dts['ST'].shift(1)
dts.loc[0, 'DST']=0
dts['DU/DST']=1/(len(dts)-1)/dts['DST']
dts.loc[0, 'DU/DST']=0
dts<jupyter_output><empty_output><jupyter_text>Plot corresponds to Fig.3.1. Choi/Kang p.47<jupyter_code>ax=dts.plot(x='ST',y='U', marker='o', ylim=(0,1))
ax=dts.plot(x='ST',y='DU/DST', marker='o', ax=ax)
ax.hlines(y=0.369881,xmin=0, xmax=59.316, colors='red')
ax.vlines(x=59.316, ymin=0, ymax=0.369881, colors='red')
plt.grid(True)
def est():
    u=random.random()
    s=u*(len(dt)-1)
    i=math.floor(s)+1
    x0=dts['ST'][i-1]
    x1=dts['ST'][i]
    return x0+(s-i+1)*(x1-x0)
edata=pd.DataFrame([est() for i in range(100000)])
edata.hist(bins=100, density=True)
plt.grid(True)<jupyter_output><empty_output><jupyter_text>Empirical Modelling of Grouped Data<jupyter_code>bins=[40,50,60,70,80,90]
dt.hist('ST', bins=bins)
plt.grid(True)
hist, _ = np.histogram(dt['ST'], bins=bins)
G = [0] + (np.cumsum(hist)/np.sum(hist)).tolist()
G
def gst():
    u=random.random()
    for i in range(len(G)-1):
        if G[i]<=u and u<G[i+1]:
            return bins[i]+(u-G[i])*(bins[i+1]-bins[i])/(G[i+1]-G[i])
    else:
        return bins[-1]
gdata=pd.DataFrame([gst() for i in range(100000)])
gdata.hist(bins=50, density=True)
plt.grid(True)<jupyter_output><empty_output><jupyter_text>Fitting of a Theoretical Distribution for Service Time  Check Independence of Data<jupyter_code>dt['STS']=dt['ST'].shift(-1)
dt<jupyter_output><empty_output><jupyter_text>If it looks scattered randomly, it is probably independent.<jupyter_code>plt.plot(dt['ST'], dt['STS'], 'bo')
plt.grid(True)<jupyter_output><empty_output><jupyter_text>Select Suitable Distribution Function For service time, a normal distribution is a reasonable approach.  Parameter Estimation<jupyter_code>μ=dts['ST'].mean()
σ=dts['ST'].std()<jupyter_output><empty_output><jupyter_text>Plotting Routine (same as before)<jupyter_code>def plot(data, hist=None, pdf=None, bins=None, 
         μ=None, σ=None,
         xmin=None, xmax=None, ymax=None, 
         title=None, fig=None, ax=None, xlabel=None, ylabel=None):
    
    if fig==None:
        fig = plt.figure()
        fig.set_figwidth(10)
        fig.set_figheight(5)
    
    if ax==None:
        ax = fig.gca()
        
     
    # set the range on the x-axis
    if hist!=None:
        # ignore data
        xmin=-0.5
        xmax=len(hist)+0.5
        bins=len(hist)
        if ymax==None:
            ymax=1.1*max(hist)/sum(hist)
        if μ==None:
            μ = hist_mean(hist)
    else: 
        if xmin==None:
            xmin = math.floor(np.min(data)*10)/10
        if xmax==None:
            xmax = math.ceil(np.max(data)*11)/10
        if bins==None:
            bins=int(4*math.log(len(data)))
        if μ==None:
            μ = np.mean(data)
        if σ==None:
            σ = np.std(data)  
        
    ax.set_xlim(xmin, xmax)
    
    if ymax!=None:
        ax.set_ylim(0, ymax)
    
    if title!=None:
        plt.title(title)
        
    if hist!=None:  
        # ignore data
        for x in range(len(hist)):
            ax.axvline(x=x, ymin=0, ymax=(hist[x]/sum(hist))/ymax, lw=10)
    else:
        plt.hist(data, bins=bins, density=True)
    
    # calculate parameter for text positioning
    dx=(xmax-xmin)*0.02
    ymin, ymax=plt.ylim()
    ypos=ymin+0.9*(ymax-ymin)
     
    # plot the probability density function if one is given
    if pdf!=None:
        X = [ i/1000 for i in range(int(xmin*1000), int(xmax*1000)) ]
        Y = [ pdf(x) for x in X]
        plt.plot(X, Y, lw=2, color='red')
 
    ax.axvline(x=μ, color='red', linestyle='dashed', lw=2)
    plt.text(μ+dx, ypos, f"μ={μ:3.2f}", color='red', fontsize=14)
    
    if xlabel!=None:
        ax.set_xlabel(xlabel)
    if ylabel!=None:
        ax.set_ylabel(ylabel)
        
    plt.grid(True)<jupyter_output><empty_output><jupyter_text>Plot<jupyter_code>norm=stats.norm(loc=μ, scale=σ)
plot(dts['ST'], pdf=norm.pdf, xmin=40, xmax=85, bins=5)<jupyter_output><empty_output><jupyter_text>Goodness-of-Fit-Test (χ²)<jupyter_code>stats.normaltest(dt['ST'])
stats.shapiro(dt['ST'])
stats.kstest(dt['ST'], norm.cdf)
tdata=pd.DataFrame(norm.rvs(1000000))
tdata.hist(bins=50, density=True)
plt.grid(True)<jupyter_output><empty_output><jupyter_text>Fitting of a Theoretical Distribution for Inter Arrival Time  Check Independence of Data<jupyter_code>dt['IATS']=dt['IAT'].shift(-1)
dt<jupyter_output><empty_output><jupyter_text>If it looks scattered randomly, it is probably independent.<jupyter_code>plt.plot(dt['IAT'], dt['IATS'], 'bo')
plt.grid(True)<jupyter_output><empty_output><jupyter_text>Select Suitable Distribution Function For inter-arrival time an exponential distribution is a reasonable approach.  Parameter Estimation<jupyter_code>μ=dts['IAT'].mean()<jupyter_output><empty_output><jupyter_text>Plotting Routine (same as before)<jupyter_code>def plot(data, hist=None, pdf=None, bins=None, 
         μ=None, σ=None,
         xmin=None, xmax=None, ymax=None, 
         title=None, fig=None, ax=None, xlabel=None, ylabel=None):
    
    if fig==None:
        fig = plt.figure()
        fig.set_figwidth(10)
        fig.set_figheight(5)
    
    if ax==None:
        ax = fig.gca()
        
     
    # set the range on the x-axis
    if hist!=None:
        # ignore data
        xmin=-0.5
        xmax=len(hist)+0.5
        bins=len(hist)
        if ymax==None:
            ymax=1.1*max(hist)/sum(hist)
        if μ==None:
            μ = hist_mean(hist)
    else: 
        if xmin==None:
            xmin = math.floor(np.min(data)*10)/10
        if xmax==None:
            xmax = math.ceil(np.max(data)*11)/10
        if bins==None:
            bins=int(4*math.log(len(data)))
        if μ==None:
            μ = np.mean(data)
        if σ==None:
            σ = np.std(data)  
        
    ax.set_xlim(xmin, xmax)
    
    if ymax!=None:
        ax.set_ylim(0, ymax)
    
    if title!=None:
        plt.title(title)
        
    if hist!=None:  
        # ignore data
        for x in range(len(hist)):
            ax.axvline(x=x, ymin=0, ymax=(hist[x]/sum(hist))/ymax, lw=10)
    else:
        plt.hist(data, bins=bins, density=True)
    
    # calculate parameter for text positioning
    dx=(xmax-xmin)*0.02
    ymin, ymax=plt.ylim()
    ypos=ymin+0.9*(ymax-ymin)
     
    # plot the probability density function if one is given
    if pdf!=None:
        X = [ i/1000 for i in range(int(xmin*1000), int(xmax*1000)) ]
        Y = [ pdf(x) for x in X]
        plt.plot(X, Y, lw=2, color='red')
 
    ax.axvline(x=μ, color='red', linestyle='dashed', lw=2)
    plt.text(μ+dx, ypos, f"μ={μ:3.2f}", color='red', fontsize=14)
    
    if xlabel!=None:
        ax.set_xlabel(xlabel)
    if ylabel!=None:
        ax.set_ylabel(ylabel)
        
    plt.grid(True)<jupyter_output><empty_output><jupyter_text>Plot<jupyter_code>exp=stats.expon(scale=μ)
plot(dts['IAT'], pdf=exp.pdf, xmin=0, xmax=250, bins=[0,50,100,150,200,250])<jupyter_output><empty_output><jupyter_text>Goodness-of-Fit-Test<jupyter_code>stats.kstest(dt['IAT'], exp.cdf)
tdata=pd.DataFrame(exp.rvs(1000000))
tdata.hist(bins=50, density=True)
plt.grid(True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16221156042951793, 'fraction_numerical': 0.03015764222069911, 'mean_word_length': 3.6249339672477547, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 69, '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': '17', 'dir': 'jupyter-structured-clean-dedup', 'id': '454220', 'license': 'MIT', 'n_tokens_mistral': 3610, 'n_tokens_neox': 3395, 'n_words': 578, 'path': '8_SingleServerSystems/Modelling of Input Data.ipynb', 'repo_name': 'sobil-dalal/Model-Simulation-Optimization', 'size': '8754'}