-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_objective_history.py
More file actions
35 lines (28 loc) · 1.32 KB
/
plot_objective_history.py
File metadata and controls
35 lines (28 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import argparse
import matplotlib.pyplot as plt
import numpy as np
def plot(test_id, language, particle_histories, path):
plt.figure(figsize=(8, 5))
i = 1
for particle_history in particle_histories:
plt.plot([i for i in range(len(particle_history))], particle_history, linewidth=1.0, label=f"Particle {i}")
i += 1
plt.title(f"{language.capitalize()} Test {test_id}: PSO Objective History")
plt.xlabel("Iteration Number")
plt.ylabel("Local Best Objective Value")
plt.legend(bbox_to_anchor = (1.25, 0.5), loc='center right')
plt.tight_layout()
plt.savefig(path)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--test", "-t", required=True, help="ID number of the test that was run")
parser.add_argument("--lang", "-l", required=True, help="The language of algorithm: java || rust")
parser.add_argument("--data_path", default="output_data/objective_history.csv", help="Path of PSO swarm objective history csv file")
args = parser.parse_args()
print(f"Plotting objective history data from {args.data_path}... ", end="")
csvData = open(args.data_path, 'rb')
data = np.loadtxt(csvData, delimiter='\t')
fname = f"./plots/{args.lang}_test_{args.test}_objective_history.jpg"
plot(args.test, args.lang, data, fname)
print(f"Completed")
print(f"Plot saved at {fname}")