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