Populate results with mean and std deviation

This commit is contained in:
coolneng 2021-04-20 11:58:24 +02:00
parent 9ab8ec3d8a
commit 3e0dbb9168
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 41 additions and 15 deletions

View File

@ -12,41 +12,67 @@ def file_list(path):
return file_list return file_list
def create_dataframes(datasets): def create_dataframes():
greedy = DataFrame(columns=["dataset", "distancia"]) greedy = DataFrame(columns=["dataset", "distancia", "desviacion"])
local = DataFrame(columns=["dataset", "distancia"]) local = DataFrame(columns=["dataset", "distancia", "desviacion"])
greedy["dataset"] = datasets
local["dataset"] = datasets
return greedy, local return greedy, local
def process_output(results): def process_output(results):
for line in results: distances = []
for element in results:
for line in element:
if line.startswith(bytes("Total distance:", encoding="utf-8")): if line.startswith(bytes("Total distance:", encoding="utf-8")):
line_elements = line.split(sep=bytes(":", encoding="utf-8")) line_elements = line.split(sep=bytes(":", encoding="utf-8"))
distance = float(line_elements[1]) distances.append(float(line_elements[1]))
return distance return distances
def populate_dataframes(greedy, local, greedy_list, local_list, dataset):
greedy_results = process_output(greedy_list)
local_results = process_output(local_list)
greedy_dict = {
"dataset": dataset,
"distancia": mean(greedy_results),
"desviacion": std(greedy_results),
}
local_dict = {
"dataset": dataset,
"distancia": mean(local_results),
"desviacion": std(local_results),
}
greedy = greedy.append(greedy_dict, ignore_index=True)
local = local.append(local_dict, ignore_index=True)
return greedy, local
def script_execution(filenames, greedy, local, iterations=3): def script_execution(filenames, greedy, local, iterations=3):
script = "src/main.py" script = "src/main.py"
for dataset in filenames: for dataset in filenames:
print(f"Running on dataset {dataset}")
greedy_list = [] greedy_list = []
local_list = [] local_list = []
for _ in range(iterations): for _ in range(iterations):
greedy_cmd = run( greedy_cmd = run(
[executable, script, dataset, "greedy"], capture_output=True [executable, script, dataset, "greedy"], capture_output=True
).stdout.splitlines() ).stdout.splitlines()
greedy_list.append(greedy_cmd)
local_cmd = run( local_cmd = run(
[executable, script, dataset, "local"], capture_output=True [executable, script, dataset, "local"], capture_output=True
).stdout.splitlines() ).stdout.splitlines()
greedy_list.append(greedy_cmd)
local_list.append(local_cmd) local_list.append(local_cmd)
greedy.loc[greedy["dataset"] == dataset, ["distancia"]] = mean(greedy_list) greedy, local = populate_dataframes(
local.loc[local["dataset"] == dataset, ["distancia"]] = mean(local_list) greedy, local, greedy_list, local_list, dataset
)
return greedy, local
def export_results(greedy, local):
greedy.to_excel()
local.to_excel()
if __name__ == "__main__": if __name__ == "__main__":
datasets = file_list(path="data/*.txt") datasets = file_list(path="data/*.txt")
greedy, local = create_dataframes(datasets) greedy, local = create_dataframes()
script_execution(filenames=datasets, greedy=greedy, local=local) populated_greedy, populated_local = script_execution(datasets, greedy, local)