Skip to content

Commit

Permalink
feat: add generation plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
suhdonghwi committed Jun 5, 2021
1 parent ab099d8 commit a153843
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1,309 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
output*
18 changes: 9 additions & 9 deletions analysis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, data):
data = data.strip()

pat = re.compile(
r"""\[Generation (\d+)\]\n# Evaluation result\n - fitness max: (\d+\.\d+) \((\d+) nodes, (\d+) edges\)\n - fitness mean: (\d+\.\d+) .+\n\n# Speciation result:\n.+\n.+\n([\s\S]+)"""
r"""\[Generation (\d+)\]\n# Evaluation result\n - fitness max: (\d+\.?\d*) \((\d+) nodes, (\d+) edges\)\n - fitness mean: (\d+\.?\d*) .+\n\n# Speciation result:\n.+\n.+\n([\s\S]+)"""
)
(
generation_num,
Expand All @@ -39,18 +39,18 @@ def __init__(self, data):
self.fitness_mean = float(fitness_mean)

self.species = [Specie(l) for l in species_data.split("\n")]
print(self.species)


def parse_generations(path):
file = open(path, "r")
return [
Generation(g)
for g in re.compile("[-]+\n").split(file.read())
if g.strip() != ""
]
content = file.read()
splited = re.compile("[-]+\n").split(content)

return [Generation(g) for g in splited if g.strip() != ""]


for i in range(1, 11):
generations = parse_generations("./analysis/output%d.txt" % i)
plt.plot([g.fitness_max for g in generations])

generations = parse_generations("./analysis/output.txt")
plt.plot([g.fitness_max for g in generations])
plt.show()
Loading

0 comments on commit a153843

Please sign in to comment.