Skip to content
Snippets Groups Projects
Commit 6a56aea4 authored by Pierre LOTTE's avatar Pierre LOTTE
Browse files

Add timer

parent 21f6db2e
Branches
Tags
No related merge requests found
...@@ -148,6 +148,9 @@ if __name__ == "__main__": ...@@ -148,6 +148,9 @@ if __name__ == "__main__":
with open("algorithm_params.json", "r", encoding="utf-8") as f: with open("algorithm_params.json", "r", encoding="utf-8") as f:
algo_params = json.load(f) algo_params = json.load(f)
with open(f"{INPUT_DIR}/{config_name}/time.csv", "a", encoding="utf-8") as f:
f.write("Algorithm,dataset,duration")
for algo in args.algorithms: for algo in args.algorithms:
params = algo_params[algo] params = algo_params[algo]
train = params.pop("training") train = params.pop("training")
......
...@@ -9,6 +9,8 @@ import numpy as np ...@@ -9,6 +9,8 @@ import numpy as np
import pandas as pd import pandas as pd
import seaborn as sns import seaborn as sns
from time import time
from sklearn.cluster import KMeans, HDBSCAN from sklearn.cluster import KMeans, HDBSCAN
from sklearn.exceptions import ConvergenceWarning from sklearn.exceptions import ConvergenceWarning
from sklearn.metrics import silhouette_score from sklearn.metrics import silhouette_score
...@@ -79,19 +81,26 @@ class BaseSplitter: ...@@ -79,19 +81,26 @@ class BaseSplitter:
""" """
Compute the vector of correlation coefficients for each of the variable of the dataset. Compute the vector of correlation coefficients for each of the variable of the dataset.
""" """
x = None with open(f"{self.data_path}/split_time.csv", "a", encoding="utf-8") as f:
for coeff in CORRELATION_CLASSES: f.write("Algorithm,duration")
coeff_name = coeff.__name__[:-11] x = None
correlation_matrix = coeff().compute(data) for coeff in CORRELATION_CLASSES:
correlation_matrix.to_csv(f"{self.data_path}/dataset_correlation_{coeff_name}.csv") coeff_name = coeff.__name__[:-11]
sns.heatmap(correlation_matrix, annot=True, cmap="coolwarm")\
.get_figure()\ start_time = time()
.savefig(f"{self.data_path}/dataset_correlation_matrix_{coeff_name}.png") correlation_matrix = coeff().compute(data)
plt.clf() duration = time() - start_time
f.write(f"{coeff_name},{duration}")
if x is not None:
x = np.concatenate([np.abs(correlation_matrix), x], axis=1) correlation_matrix.to_csv(f"{self.data_path}/dataset_correlation_{coeff_name}.csv")
else: sns.heatmap(correlation_matrix, annot=True, cmap="coolwarm")\
x = np.abs(correlation_matrix) .get_figure()\
.savefig(f"{self.data_path}/dataset_correlation_matrix_{coeff_name}.png")
plt.clf()
if x is not None:
x = np.concatenate([np.abs(correlation_matrix), x], axis=1)
else:
x = np.abs(correlation_matrix)
return x return x
...@@ -7,6 +7,7 @@ import pandas as pd ...@@ -7,6 +7,7 @@ import pandas as pd
import seaborn as sns import seaborn as sns
import subprocess import subprocess
from time import time
from .correlations import CORRELATION_CLASSES from .correlations import CORRELATION_CLASSES
...@@ -58,6 +59,11 @@ class BaseTrainer(): ...@@ -58,6 +59,11 @@ class BaseTrainer():
os.makedirs(f"{path}/results_{self.algorithm}", exist_ok=True) os.makedirs(f"{path}/results_{self.algorithm}", exist_ok=True)
start_time = time()
os.system( os.system(
f"python3 {pwd}/algorithms/{self.algorithm}/algorithm.py '{json.dumps(args)}' 1>/dev/null 2>/dev/null" f"python3 {pwd}/algorithms/{self.algorithm}/algorithm.py '{json.dumps(args)}' 1>/dev/null 2>/dev/null"
) )
duration = time() - start_time
with open(f"{path}/time.csv", "a", encoding="utf-8") as f:
f.write(f"{self.algorithm},{file_name},{duration}")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment