<jupyter_start><jupyter_text>A total of 2000 virtual trials are run to evaluate the performance of a static head component and a rotational head component. In order to test the obstacle avoidance algorithm is as many different scenerios as possible, each trial was run in a randomly generated labyrinth of changing size. The overall obstacle density was kept constant which means that the number of obstacles scalled quadratically with the size of the labyrinth. In consequence, the number of deadends in the larger labyrinths increased. Trials in which the robot is able to escape the labyrinth are considered a success. If it hits a deadend, the robot did not collide with anything but also cannot find a way out of the labyrinth. A time out occurs when the robot does not get stuck in a deadend but takes too long to escape the labyrinth. The successrate is the main metric in the comparision of the rotatinal to the static head design. Comparing the successrate of all trials, the rotational head design performs slightly better with escaping 48% of all trials. The static head version 42% of all trials. Noticeable is that this performance difference increases in larger Labyrinths. The rotational head design performce more than twice as well as the static head design for labyrithn radii above 10 simulation unit lenghts. The pie chart shows that the rotational head design takes the big majority of all escapes at the large scale labyrinth simulation for high obstacle density.<jupyter_code>series =[]
index = []
for i,df in enumerate([hd,sd]):
    blocks = df['Blocks'][1]
    radius = df['Radius'][1]
#     df = df[df['Radius'] <= 7]
    print(len(df))
#     df = df[df['Radius'] > 3]
    f = len(df[df['Deadend']==True])
    s = len(df[df['Deadend']==False])
    tot = s+f
    t_frac = round(len(df[df['Timeout']==True])/tot,3)
    s_frac = round(s/tot,3)
    f_frac = round(f/tot,3)
    series.append([s_frac-t_frac,f_frac,t_frac])
    if df['Turned Head'].mean() > 1:
        index.append('Turning Head '.format(radius,blocks))
    else:
        index.append('Static Head'.format(radius,blocks))
data = pd.DataFrame(series,columns=['Escaped','Hit Deadend','Timed Out'],index = index)
print(data.head())

plt.figure()
data.plot(kind='bar')
# plt.xlabel('Outcome')
plt.ylabel('Probability of Outcome')
plt.title('Labyrith Simulation: r = 7, obstacles = 98, n = 113')

plt.show()
hblocks = hd['Blocks'].copy()
hradius = hd['Radius'].copy()
sblocks = sd['Blocks'].copy()
sradius = sd['Radius'].copy()
hd_rb = hd.loc[:,['Radius','Blocks']].copy()
uni_radius = hd_rb['Radius'].unique().tolist()
uni_blocks = hd_rb['Blocks'].unique().tolist()
uni_radius.sort()
uni_blocks.sort()
print(uni_blocks)
print(uni_radius)
area = [(2*r)**2 - (2*1)**2 for r in uni_radius]
print(area)
obstacle_density = [b/a for b,a in zip(uni_blocks,area)]
print(obstacle_density)
hd['Turned Head'].mean()
hsuccess = hd[(hd['Deadend']==False) & (hd['Timeout']==False)]['Distance Travelled'].copy()
ssuccess = sd[(sd['Deadend']==False) & (sd['Timeout']==False)]['Distance Travelled'].copy()

print(hsuccess.min())
print(ssuccess.min())
print(hsuccess.mean())
print(ssuccess.mean())
print(hsuccess.max())
print(ssuccess.max())

# plt.figure()
# plt.hold(True)
# hsuccess.plot()
# # ssuccess.plot()
# # plt.legend("Rotational Head", "Static Head")
# plt.show()
hblocks.value_counts()
hr = hradius.value_counts(False)
sr = sradius.value_counts(False)
sr.name = 'Static Head Design'
hr.name = 'Rotational Head Design'
trails = pd.concat([hr,sr],axis=1)
plt.figure()
trails.plot(kind='bar')
plt.title("Destribution of Labyrinth Sizes")
plt.ylabel("Number of Trials")
plt.xlabel("Radius [Unit Length]")
plt.show()
trails.head(10)
hfailed = hd[hd['Deadend']==True]
sfailed = sd[sd['Deadend']==True]
# Progress before failure
hfailed['Radial Distance'].mean()/hfailed['Radius'].mean()
# Progress before failure
sfailed['Radial Distance'].mean()/sfailed['Radius'].mean()
hhard = hd[hd['Radius']>8]
shard = sd[sd['Radius']>8]
len(hhard[hhard['Deadend']==False])/len(hhard)
len(shard[shard['Deadend']==False])/len(shard)
sd['Radius'].value_counts().tolist()
sd['Radius'].value_counts()
sd['Radius'].unique()
sd_freq = sd['Radius'].value_counts()
hd_new = pd.DataFrame(columns=hd.columns.tolist())
for i in sd['Radius'].unique():
#     print(i,sd_freq[i])
#     print(sd_freq[i],temp)
    df = hd[hd['Radius']==i].copy()
    df.index = range(len(df.index))
    to_drop = np.arange(sd_freq[i],len(df)).tolist()
    print(len(df),len(to_drop))
    df = df.drop(df.index[to_drop])
    hd_new=pd.concat([hd_new,df],axis=0)
print(hd_new['Radius'].value_counts())
hd_new.head()
hd_new.shape
sd.shape
hd.index[3]
hr = hd_new['Radius'].value_counts(False)
sr = sradius.value_counts(False)
sr.name = 'Static Head Design'
hr.name = 'Rotational Head Design'
trails = pd.concat([hr,sr],axis=1)
plt.figure()
trails.plot(kind='bar')
plt.title("Destribution of Labyrinth Sizes")
plt.ylabel("Number of Trials")
plt.xlabel("Labyrinth Radius [Unit Length]")
plt.show()
series =[]
index = []
for i,df in enumerate([hd_new,sd]):
    blocks = df['Blocks'][1]
    radius = df['Radius'][1]
    df = df[df['Radius'] >= 10]
    print(len(df))
#     df = df[df['Radius'] > 3]
    f = len(df[df['Deadend']==True])
    s = len(df[df['Deadend']==False])
    tot = s+f
    t_frac = round(len(df[df['Timeout']==True])/tot,3)
    s_frac = round(s/tot,3)
    f_frac = round(f/tot,3)
    series.append([s_frac-t_frac,f_frac,t_frac])
    if df['Turned Head'].mean() > 1:
        index.append('Turning Head '.format(radius,blocks))
    else:
        index.append('Static Head'.format(radius,blocks))
        
data = pd.DataFrame(series,columns=['Escaped','Hit Deadend','Timed Out'],index = index)
print(data.head())

plt.figure()
data.plot(kind='bar')
# plt.xlabel('Outcome')
plt.ylabel('Probability of Outcome')
plt.title('Labyrith Simulation: Overall Performance')

plt.show()
pie_data = data['Escaped'].copy()
old_sum = pie_data.sum()
for i in range(len(pie_data)):
    pie_data[i]=pie_data[i]/old_sum

# pie_data['Static Head']=pie_data['Static Head']/pie_data.sum()
# pie_data['Turning Head']=pie_data['Turning Head']/pie_data.sum()
pie_data.name = ""
pie_data.head()

plt.figure()
pie_data.plot(kind='pie')
plt.title('Relative Successrate in large scale Labyrinth')
plt.show()
scoll.head()
scoll[scoll['Collided']==True].describe()
len(scoll[scoll['Collided']==True])/len(scoll)
series =[]
index = []
radii = scoll['Radius'].unique().tolist()
radii.sort()
for i in radii:
    print(i)
    scoll_s = scoll[scoll['Radius']==i]
    value = len(scoll_s[scoll_s['Collided']==True])/len(scoll_s)
    index.append(str(i))
    series.append((1-value,value))
print(index)
print(len(series))
total = len(scoll[scoll['Collided']==True])/len(scoll)
series.append((1-total,total))
index.append("Total")
scoll_data = pd.DataFrame(series,columns=['Collision Free','Collided'],index = index)
print(scoll_data.head())
plt.figure()
scoll_data.plot(kind='bar')
plt.ylabel("Probability of Event")
plt.xlabel("Labyrinth Radius [meter]")
plt.title("Collisions for Obstacle Density of 0.5 n = 1000")
plt.show()
scoll['Radius'].unique().tolist()
len(scoll[scoll['Collided']==True])/len(scoll)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17175625259085256, 'fraction_numerical': 0.007461655382064392, 'mean_word_length': 5.622140896614821, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 12, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '226036', 'license': 'MIT', 'n_tokens_mistral': 2611, 'n_tokens_neox': 2506, 'n_words': 600, 'path': '.ipynb_checkpoints/Data_analysis-checkpoint.ipynb', 'repo_name': 'IntelligentQuadruped/PyBullet_Simulation', 'size': '7237'}