Skip to content
Snippets Groups Projects
Commit 1ef40c00 authored by hui's avatar hui
Browse files

plot the figure after the simualtion

parent 13402343
No related branches found
No related tags found
No related merge requests found
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
.*.js .*.js
.*/*.js .*/*.js
.*/*/*.js .*/*/*.js
bike/__pycache__/* src/__pycache__/*
debug.log debug.log
data/* data/*
src/__pycache__/gen.cpython-38.pyc
src/__pycache__/genetic_algo.cpython-38.pyc
src/__pycache__/simu_bike.cpython-38.pyc
images/popu* images/popu*
No preview for this file type
No preview for this file type
No preview for this file type
import src.gen as g import gen as g
import numpy as np import numpy as np
import sys import sys
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
......
...@@ -324,6 +324,7 @@ random.randint(start_point[1], start_point[1]+side_length)), ...@@ -324,6 +324,7 @@ random.randint(start_point[1], start_point[1]+side_length)),
# REPEAT # REPEAT
last_ten_average = [0]*10 last_ten_average = [0]*10
file_counter=0 file_counter=0
score_list=[]
while abs(average_fitness_score- np.mean(last_ten_average[-10:])) > 0.1: while abs(average_fitness_score- np.mean(last_ten_average[-10:])) > 0.1:
last_ten_average.append(self.p.average_fitness_score()) last_ten_average.append(self.p.average_fitness_score())
self.p.save_population_to_file("data/population_"+str(file_counter)+".json") self.p.save_population_to_file("data/population_"+str(file_counter)+".json")
...@@ -341,7 +342,7 @@ random.randint(start_point[1], start_point[1]+side_length)), ...@@ -341,7 +342,7 @@ random.randint(start_point[1], start_point[1]+side_length)),
# UNTIL population has converged # UNTIL population has converged
# STOP # STOP
score_list.append(average_fitness_score) score_list.append(average_fitness_score)
if len(score_list)>50: if len(score_list)>100:
break break
return score_list return score_list
#return the fittest child among the last siblings #return the fittest child among the last siblings
......
...@@ -2,4 +2,6 @@ import matplotlib.pyplot as plt ...@@ -2,4 +2,6 @@ import matplotlib.pyplot as plt
def plot(scores): def plot(scores):
plt.plot(range( len(scores)),scores,'--b') plt.plot(range( len(scores)),scores,'--b')
plt.xlabel('Generation')
plt.ylabel('Ave. score')
plt.show() plt.show()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment