Skip to content

Commit f7bb39a

Browse files
authored
Update Example_GeneticAlgorithm.py
1 parent bffbe17 commit f7bb39a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Example_GeneticAlgorithm.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy
2-
import GA
2+
import ga
33

44
"""
55
The y=target is to maximize this equation ASAP:
@@ -43,7 +43,7 @@
4343
for generation in range(num_generations):
4444
print("Generation : ", generation)
4545
# Measuring the fitness of each chromosome in the population.
46-
fitness = GA.cal_pop_fitness(equation_inputs, new_population)
46+
fitness = ga.cal_pop_fitness(equation_inputs, new_population)
4747
print("Fitness")
4848
print(fitness)
4949

@@ -52,19 +52,19 @@
5252
print("Best result : ", numpy.max(numpy.sum(new_population*equation_inputs, axis=1)))
5353

5454
# Selecting the best parents in the population for mating.
55-
parents = GA.select_mating_pool(new_population, fitness,
55+
parents = ga.select_mating_pool(new_population, fitness,
5656
num_parents_mating)
5757
print("Parents")
5858
print(parents)
5959

6060
# Generating next generation using crossover.
61-
offspring_crossover = GA.crossover(parents,
61+
offspring_crossover = ga.crossover(parents,
6262
offspring_size=(pop_size[0]-parents.shape[0], num_weights))
6363
print("Crossover")
6464
print(offspring_crossover)
6565

6666
# Adding some variations to the offspring using mutation.
67-
offspring_mutation = GA.mutation(offspring_crossover, num_mutations=2)
67+
offspring_mutation = ga.mutation(offspring_crossover, num_mutations=2)
6868
print("Mutation")
6969
print(offspring_mutation)
7070

@@ -74,7 +74,7 @@
7474

7575
# Getting the best solution after iterating finishing all generations.
7676
#At first, the fitness is calculated for each solution in the final generation.
77-
fitness = GA.cal_pop_fitness(equation_inputs, new_population)
77+
fitness = ga.cal_pop_fitness(equation_inputs, new_population)
7878
# Then return the index of that solution corresponding to the best fitness.
7979
best_match_idx = numpy.where(fitness == numpy.max(fitness))
8080

0 commit comments

Comments
 (0)