-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomGraphsForHostileGeneticAlgorithmAnalysisCreate.py
More file actions
115 lines (82 loc) · 3.81 KB
/
RandomGraphsForHostileGeneticAlgorithmAnalysisCreate.py
File metadata and controls
115 lines (82 loc) · 3.81 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import os
#Define CSV File Name for plotting
csv_genetic_aLgorithm_file="GeneticAlgorithmData/002_GeneticAlgorithm.csv"
raw_statistics = pd.read_csv(csv_genetic_aLgorithm_file)
#1 Traits by generation
generation_groups_mean = raw_statistics.groupby("Gen").mean()
plt.figure(figsize=(10,5))
plt.plot(generation_groups_mean.index, generation_groups_mean['Reflex'], label='Mean Reflex', marker='x',markeredgewidth=2)
plt.plot(generation_groups_mean.index, generation_groups_mean['Endurance'], label='Mean Endurance', marker='o')
plt.plot(generation_groups_mean.index, generation_groups_mean['Resilience'], label='Mean Resilience', marker='s',color='darkgreen')
plt.plot(generation_groups_mean.index, generation_groups_mean['Aggression'], label='Mean Aggression', marker='d',color='red')
plt.xticks(range(0, int(generation_groups_mean.index.max()) + 1))
plt.yticks(range(0, 11))
plt.title('Trait Averages by Generation')
plt.xlabel('Generation')
plt.ylabel('Trait Value')
plt.legend(loc='upper center',bbox_to_anchor=(0.5,1.15),ncol=4,frameon=False,fontsize='small')
plt.grid(True, linestyle='--')
plt.show()
#2 Average Score, Max Score, Top 20 Score Average
plt.figure(figsize=(10,5))
avg_score_top_20 = []
number_of_gens= raw_statistics['Gen'].unique()
for ind_generation in number_of_gens:
ind_generation_stats=raw_statistics[raw_statistics['Gen']==ind_generation]
sort_ind_generation_stats=ind_generation_stats.sort_values('Fitness Score', ascending=False)
ind_generation_top_20_mean=sort_ind_generation_stats['Fitness Score'].head(20).mean()
avg_score_top_20.append(ind_generation_top_20_mean)
avg_score=raw_statistics.groupby('Gen')['Fitness Score'].mean()
max_score=raw_statistics.groupby('Gen')['Fitness Score'].max()
plt.yticks(np.arange(4000, 5551, 250))
plt.ylim(4000,5550)
plt.plot(max_score.index, max_score, label='Top Score', color='black',marker='x',markeredgewidth=2)
plt.plot(avg_score.index, avg_score, label='Mean Score', color='green', linestyle='--',marker='o')
plt.plot(number_of_gens, avg_score_top_20, label='Mean of Top 20 Scores', color='blue', linestyle='--',marker='s')
plt.xticks(range(0, int(generation_groups_mean.index.max()) + 1))
plt.grid(axis='y', linestyle='--', alpha=1)
plt.grid(axis='x', linestyle=':', alpha=0.7)
plt.title('Fitness Score by Generation')
plt.xlabel('Generation')
plt.ylabel('Fitness Score')
plt.legend()
plt.show()
#3 Ghosts Eaten
plt.figure(figsize=(10,5))
plt.xticks(range(0, int(generation_groups_mean.index.max()) + 1))
plt.title('Mean Ghosts Eaten by Generation')
plt.plot(generation_groups_mean.index, generation_groups_mean['Ghosts Eaten'], label='Ghosts Eaten', color='red',marker='x',markeredgewidth=2)
plt.xlabel('Generation')
plt.ylabel('Ghosts Eaten')
plt.grid(True, linestyle='--', alpha=1)
plt.legend()
plt.yticks(np.arange(4, 12, 1))
plt.yticks(np.arange(4, 12))
plt.show()
#4 Turns Taken
plt.figure(figsize=(10,4))
plt.yticks(np.arange(350, 601, 25))
plt.ylim(350, 600)
plt.xticks(range(0, int(generation_groups_mean.index.max()) + 1))
plt.plot(generation_groups_mean.index, generation_groups_mean['Turns_Taken'], label='Mean Turns', color='black',marker='x',markeredgewidth=2)
plt.grid(True, linestyle='--', alpha=1)
plt.title('Mean Turns Taken by Generation')
plt.xlabel('Generation')
plt.ylabel('Mean Turns Taken')
plt.legend()
plt.show()
#5 Lives Remaining
plt.figure(figsize=(10,4))
plt.yticks(np.arange(0, 16, 1))
plt.ylim(0, 12)
plt.xticks(range(0, int(generation_groups_mean.index.max()) + 1))
plt.plot(generation_groups_mean.index, generation_groups_mean['Lives'], label='Lives Remaining', color='black',marker='x',markeredgewidth=2)
plt.grid(True, linestyle='--', alpha=1)
plt.title('Mean Lives Remaining by Generation')
plt.xlabel('Generation')
plt.ylabel('Mean Lives Remaining')
plt.legend()
plt.show()