Last active
November 27, 2017 17:49
-
-
Save NicolleLouis/02bae76554a4245290540d23c8a91cc4 to your computer and use it in GitHub Desktop.
Print graphe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def evolve_several_generation_with_limited_time(item_set, size_of_population, number_of_child, time_limit, | |
mutationRate): | |
temps_init = time.time() | |
value0 = 0 | |
result = [] | |
population = generate_first_population(item_set, size_of_population) | |
value0 = max(value0, value(get_best_individual_in_population(population), item_set)) | |
result.append(value0) | |
while (time.time() - temps_init < time_limit): | |
population_sorted = sort_population_by_fitness(population, item_set) | |
breeders = select_breeders(population_sorted, size_of_population) | |
population = create_children(breeders, number_of_child) | |
population = mutate_population(population, mutationRate) | |
population = sort_population_by_fitness(population, item_set) | |
value0 = max(value0, value(get_best_individual_in_population(population), item_set)) | |
return value0def mean_result_evolve(item_set, size_of_population, number_of_child, number_of_sample, mutationRate, time_limit): | |
meanResult = 0 | |
for i in range(number_of_sample): | |
meanResult += evolve_several_generation_with_limited_time(item_set, size_of_population, number_of_child, | |
time_limit, mutationRate) | |
return (meanResult / number_of_sample) | |
def mean_result_evolve(item_set, size_of_population, number_of_child, number_of_sample, mutationRate, time_limit): | |
meanResult = 0 | |
for i in range(number_of_sample): | |
meanResult += evolve_several_generation_with_limited_time(item_set, size_of_population, number_of_child, | |
time_limit, mutationRate) | |
return (meanResult / number_of_sample) | |
def print_graph(number_of_child, number_of_sample, mutationRate, size_of_population, time_limit, item_set): | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection='3d') | |
ax.set_xlabel('Population size') | |
ax.set_ylabel('Mutation rate') | |
ax.set_zlabel('Efficiency') | |
graphSize = [] | |
graphMutation = [] | |
graphResult = [] | |
for i in range(20): | |
mutationRate = 5*i | |
for j in range(19): | |
size_of_population = 5*(j+1) | |
graphSize.append(size_of_population) | |
graphMutation.append(mutationRate) | |
graphResult.append(mean_result_evolve(item_set, size_of_population, number_of_child, number_of_sample, mutationRate, time_limit)) | |
ax.scatter(graphSize, graphMutation, graphResult) | |
plt.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment