You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
185 lines
5.6 KiB
Python
185 lines
5.6 KiB
Python
import sys
|
|
import os
|
|
import yaml
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
|
|
|
|
def total_boxplot(DATA, creator = 'any', tester = 'any', simulation = "dummy simulation"):
|
|
|
|
fig, ax = plt.subplots()
|
|
|
|
data_to_plot = []
|
|
labels = []
|
|
title = f'Boxplot of scores in {simulation},'
|
|
xlabel = ""
|
|
|
|
colors_list = plt.colormaps['tab10'].colors
|
|
|
|
if creator == tester == 'any':
|
|
print(f"Warning: setting both creator and tester as 'any' plots only self testing!")
|
|
title += f" self testing"
|
|
xlabel = "self tester"
|
|
for creator_name, data in DATA.items():
|
|
if creator_name in data:
|
|
data_to_plot.append(data[creator_name])
|
|
labels.append(creator_name)
|
|
|
|
elif creator == 'any':
|
|
title += f" tester: {tester}"
|
|
xlabel = "creator"
|
|
for creator_name, data in DATA.items():
|
|
if tester in data:
|
|
data_to_plot.append(data[tester])
|
|
#labels.append(f"{creator_name}-{tester}")
|
|
labels.append(creator_name)
|
|
|
|
elif tester == 'any':
|
|
title += f" creator: {creator}"
|
|
xlabel = "tester"
|
|
if creator in DATA:
|
|
for tester_name, data in DATA[creator].items():
|
|
data_to_plot.append(data)
|
|
#labels.append(f"{creator}-{tester}")
|
|
labels.append(tester_name)
|
|
|
|
|
|
if len(data_to_plot) == 0:
|
|
print("No appropriate data!")
|
|
return
|
|
|
|
|
|
#print(len(data_to_plot), len(labels))
|
|
median_styling = {'color': 'black', 'linewidth': 2}
|
|
elements = ax.boxplot(data_to_plot, patch_artist=True, tick_labels=labels, medianprops=median_styling)
|
|
for i, patch in enumerate(elements['boxes']):
|
|
patch.set_facecolor(colors_list[(i)%10])
|
|
|
|
ax.grid()
|
|
#ax.legend()
|
|
ax.set(xlabel=xlabel, ylabel='Score')
|
|
ax.set_title(title)
|
|
|
|
|
|
def heat_map(DATA, criteria = np.median):
|
|
|
|
names_to_nums = {name: num for num, name in enumerate(list(DATA.keys()))}
|
|
values = np.zeros( (len(names_to_nums)+1, len(names_to_nums)+1) )
|
|
|
|
testers = {}
|
|
for creator, Data in DATA.items():
|
|
total_creator = []
|
|
for tester, data in Data.items():
|
|
if not tester in testers:
|
|
testers[tester] = []
|
|
if creator in names_to_nums and tester in names_to_nums:
|
|
creator_idx = names_to_nums[creator]
|
|
tester_idx = names_to_nums[tester]
|
|
values[creator_idx, tester_idx] = criteria(data)
|
|
total_creator += data
|
|
testers[tester] +=data
|
|
values[creator_idx, len(names_to_nums)] = criteria(total_creator)
|
|
|
|
for tester, data in testers.items():
|
|
tester_idx = names_to_nums[tester]
|
|
values[len(names_to_nums), tester_idx] = criteria(data)
|
|
|
|
fig, ax = plt.subplots()
|
|
im = ax.imshow(values, cmap='coolwarm')
|
|
|
|
for i in range(values.shape[0]):
|
|
for j in range(values.shape[1]):
|
|
text = ax.text(j, i, round(values[i, j],1), ha="center", va="center", color="k")
|
|
|
|
ax.set_xticks(range(len(DATA.keys())+1), labels=list(DATA.keys())+['mean'] )
|
|
ax.set_yticks(range(len(DATA.keys())+1), labels=list(DATA.keys())+['mean'] )
|
|
|
|
ax.set(xlabel='tester', ylabel='creator')
|
|
ax.set_title("Cross-validation heatmap")
|
|
|
|
|
|
def convert_score(data):
|
|
|
|
score = data['score']
|
|
Nsof = len(data['exted_sofs'])
|
|
Ncol = len(data['collisions'])
|
|
Ksof = data['k_params']['_k_sof']
|
|
Khp = data['k_params']['_k_hp']
|
|
Kch = data['k_params']['_k_charge']
|
|
Khp_max = 100
|
|
Kch_max = 100
|
|
|
|
Kch_r = (score - Ksof*Nsof-Khp*(Khp_max-Ncol)/Khp_max) * Kch_max/Kch
|
|
|
|
score_new = Ksof*Nsof*(Kch*Kch_r/Khp_max+Khp*(Khp_max-Ncol)/Khp_max)
|
|
#print(type(score_new))
|
|
|
|
return score_new
|
|
|
|
# DATA[name] = {name: [scores]}
|
|
def no_interface_plot(DATA):
|
|
|
|
species = list(DATA.keys())
|
|
penguin_means = {
|
|
'Int': [],
|
|
'Not Int': []}
|
|
|
|
for creator, Data in DATA.items():
|
|
for tester, data in Data.items():
|
|
pass
|
|
|
|
fig, ax = plt.subplots()
|
|
print(DATA.keys())
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
global_path = "/home/gestures/Easy_sim/dummy_simulation/stats/"
|
|
# 1. Name (Dima)
|
|
# 2. Name-Name (Dima-Elisey)
|
|
|
|
DATA = {} # Name of creator - {} - Name of tester
|
|
|
|
for dirname in sorted(os.listdir(global_path)):
|
|
dirpath = os.path.join(global_path, dirname)
|
|
if os.path.isdir(dirpath) and not dirname.startswith('!'):
|
|
data = []
|
|
if not '-' in dirname:
|
|
name = dirname
|
|
if not name in DATA:
|
|
DATA[name] = {}
|
|
DATA[name][name] = data
|
|
else:
|
|
names = dirname.split('-')
|
|
name1 = names[0]
|
|
name2 = names[1]
|
|
if not name1 in DATA:
|
|
DATA[name1] = {}
|
|
DATA[name1][name2] = data
|
|
for filename in sorted(os.listdir(dirpath)):
|
|
file_path = os.path.join(dirpath, filename)
|
|
if file_path.endswith('.yaml'):
|
|
with open(file_path, 'r', encoding='utf-8') as file:
|
|
datafile = yaml.load(file, Loader = yaml.Loader)
|
|
data.append(convert_score(datafile)) # TODO change score to new formula
|
|
#data.append(datafile['score'])
|
|
|
|
|
|
#for cr, data in DATA.items():
|
|
#print(f"{cr}: {data}")
|
|
|
|
total_boxplot(DATA, creator = 'any', tester = 'any')
|
|
|
|
no_interface_plot(DATA)
|
|
|
|
#for name in DATA.keys():
|
|
|
|
#total_boxplot(DATA, creator = name, tester = 'any')
|
|
#total_boxplot(DATA, creator = 'any', tester = name)
|
|
|
|
#heat_map(DATA)
|
|
|
|
plt.show()
|
|
|