<jupyter_start><jupyter_text>Data Analysis GCRM This statistical work aims to make a statistical analysis of the data generated by the GCRM code with the value generated by the code made by *Mathematica*. Import libraries<jupyter_code>import pandas as pd
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from scipy import stats<jupyter_output><empty_output><jupyter_text>Define function that return object files using the name of particle<jupyter_code>def read_particles_file(particle_name):
    path_particle = 'data/' + particle_name
    path_particle_GCRM = path_particle + '/' + particle_name + '_NBL.dat'
    path_particle_Mathematica = path_particle + '/Geant4_Spetrum' + particle_name + '.dat'
    
    file_particle_GCRM = open(path_particle_GCRM, 'r')
    file_particle_Mathematica = open(path_particle_Mathematica, 'r')
    
    return file_particle_GCRM, file_particle_Mathematica<jupyter_output><empty_output><jupyter_text>Define function that get a file object and return a data frame<jupyter_code>def transform_files_objects_at_data_frames(file_object):
    # Transform lines in array objects
    lines = file_object.readlines()
    
    # Pop header elements
    lines.pop(0)
    lines.pop(0)
    lines.pop(0)
    lines.pop(0)
    
    bin_cent = []
    bin_width = []
    weight = []
    
    for line in lines:
        data_line = line.split()
        bin_cent.append(data_line[0])
        bin_width.append(data_line[1])
        weight.append(data_line[2])
    
    return pd.DataFrame({
        'bin_cent':bin_cent, 
        'bin_width':bin_width, 
        'weight':weight
    })<jupyter_output><empty_output><jupyter_text>Function that drawer a chart of quantities that each experiment<jupyter_code>def bar_chart(df_1, df_2):
    fig, ax = plt.subplots()
    
    labels = ['bin_cent', 'bin_width', 'weight']
    width = 0.35  # the width of the bars
    x = np.arange(len(labels))  # the label locations
    
    scores_1 = [len(df_1['bin_cent']), len(df_1['bin_width']), len(df_1['weight'])]
    scores_2 = [len(df_2['bin_cent']), len(df_2['bin_width']), len(df_2['weight'])]
    
    rects1 = ax.bar(x - width/2, scores_1, width, label='GCRM')
    rects2 = ax.bar(x + width/2, scores_2, width, label='Mathematica')
    
    ax.set_ylabel('Scores')
    ax.set_title('Comparison between GCRM and Mathematics')
    ax.set_xticks(x)
    ax.set_xticklabels(labels)
    ax.legend()
    
    def autolabel(rects):
        """Attach a text label above each bar in *rects*, displaying its height."""
        for rect in rects:
            height = rect.get_height()
            ax.annotate('{}'.format(height),
                        xy=(rect.get_x() + rect.get_width() / 2, height),
                        xytext=(0, 3),  # 3 points vertical offset
                        textcoords="offset points",
                        ha='center', va='bottom')
        
    autolabel(rects1)
    autolabel(rects2)<jupyter_output><empty_output><jupyter_text>Function that analyses GCRM and Mathematica dataframes<jupyter_code>def data_analysis_using_bar_charts(df_GCRM, df_Mathematica):
    bar_chart(df_GCRM, df_Mathematica)
    
    print('The bar graph shows that we are working with samples of different sizes.')<jupyter_output><empty_output><jupyter_text>Function that analyse a initial dataframes creates and return data frames<jupyter_code>def data_analysis_particle(particle_name):
    print("---------------------")
    print(particle_name)
    print("---------------------")
    print("\n")
    
    file_particle_GCRM, file_particle_Mathematica = read_particles_file(particle_name)
    
    df_GCRM, df_Mathematica = map(
        transform_files_objects_at_data_frames,
        (file_particle_GCRM, file_particle_Mathematica)
    )
    
    data_analysis_using_bar_charts(df_GCRM, df_Mathematica)
    
    file_particle_GCRM.close()
    file_particle_Mathematica.close()
    
    return df_GCRM, df_Mathematica<jupyter_output><empty_output><jupyter_text>Function that return the type of correlation<jupyter_code>def resp_corr(corr):
    corr = abs(corr)
    if(corr>0.9 and corr <=1):
        return 'very strong correlation'
    elif(corr>0.7 and corr <=0.9):
        return 'strong correlation'
    elif(corr>0.5 and corr<=0.7):
        return 'moderate correlation'
    elif(corr>0.3 and corr<=0.5):
        return 'weak correlation'
    elif(corr>=0 and corr<=0.3):
        return 'negligible correlation'
    else:
        return 'value not is a number'<jupyter_output><empty_output><jupyter_text>Function that analysis the normality test<jupyter_code>def data_analysis_for_mean(parm_name, df_GCRM, df_Mathematica):
    print("--------")
    print(parm_name)
    print("--------")
    print("\n")
    parm_GCRM = pd.DataFrame(list(map(float, (df_GCRM[parm_name]))))
    parm_Mathematica = pd.DataFrame(list(map(float, (df_Mathematica[parm_name]))))
    
    mu_GCRM = float(parm_GCRM.mean())
    sigma_GCRM = float(parm_GCRM.var())
    
    mu_Mathematica = float(parm_Mathematica.mean())
    sigma_Mathematica = float(parm_Mathematica.var())
    
    print('GCRM')
    print('mu = ' + str(mu_GCRM))
    print('sigma = ' + str(sigma_GCRM))
    
    print("\n")
    
    print('Mathematica')
    print('mu = ' + str(mu_Mathematica))
    print('sigma = ' + str(sigma_Mathematica))
    
    print("\n")
    
    parms = pd.DataFrame({
        "GCRM":parm_GCRM[0],
        "Mathematica":parm_Mathematica[0]
    })
        
    corr = parms['GCRM'].corr(parms['Mathematica'])

    x = parms["GCRM"]
    y = parms["Mathematica"]

    fig, ax = plt.subplots()
    
    plt.title('Correlation chart for '+str(parm_name))

    ax.plot(x, y, 'o')
        
    print(resp_corr(corr))
    
    print('corr = ' + str(corr))
    
    print("\n")
    
    w_GCRM, p_value_GCRM = stats.shapiro(parms['GCRM'])
    w_Mathematica, p_value_Mathematica = stats.shapiro(parms['Mathematica'])
    
    print("GCRM")
    print("\n")
    print("W = "+str(w_GCRM))
    print("p-value = "+str(p_value_GCRM))
    
    print("\n")
    
    
    print("Mathematica")
    print("\n")
    print("W = "+str(w_Mathematica))
    print("p-value = "+str(p_value_Mathematica))<jupyter_output><empty_output><jupyter_text>Function that test all params that data frame object<jupyter_code>def test_normality(particle_name):
    df_particle_GCRM, df_particle_Mathematica = data_analysis_particle(particle_name)
    
    data_analysis_for_mean('weight', df_particle_GCRM, df_particle_Mathematica)
    data_analysis_for_mean('bin_cent', df_particle_GCRM, df_particle_Mathematica)
    data_analysis_for_mean('bin_width', df_particle_GCRM, df_particle_Mathematica)
test_normality('Alpha')
test_normality('Proton')<jupyter_output>---------------------
Proton
---------------------


The bar graph shows that we are working with samples of different sizes.
--------
weight
--------


GCRM
mu = 0.00216805098791
sigma = 8.11705108916e-05


Mathematica
mu = 0.0046209237665
sigma = 0.00058716955425


moderate correlation
corr = 0.5145726593810792


GCRM


W = 0.25424849987
p-value = 0.0


Mathematica


W = nan
p-value = 1.0
--------
bin_cent
--------


GCRM
mu = 311902.409668
sigma = 86262869500.4


Mathematica
mu = 412403.353659
sigma = 1.01516657421e+11


very strong correlation
corr = 0.958493693898467


GCRM


W = 0.884399592876
p-value = 5.93953867436e-27


Mathematica


W = nan
p-value = 1.0
--------
bin_width
--------


GCRM
mu = 978.081054688
sigma = 453177.472407


Mathematica
mu = 2032.5203252
sigma = 701772.250095


moderate correlation
corr = 0.5588390350344079


GCRM


W = 0.845185160637
p-value = 1.87001515758e-30


Mathematica


W = nan
p-value = 1.0
{'fraction_non_alphanumeric': 0.12896075107575955, 'fraction_numerical': 0.043291172251923325, 'mean_word_length': 3.2753623188405796, 'pattern_counts': {'":': 2, '<': 41, '<?xml version=': 0, '>': 41, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '589154', 'license': 'MIT', 'n_tokens_mistral': 3004, 'n_tokens_neox': 2726, 'n_words': 518, 'path': 'DataAnalysis/Results_Simulation_GCRM.ipynb', 'repo_name': 'Matheus1714/GCRM', 'size': '7669'}