You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Reuse the fitness of previously explored solutions rather than recalculating them. This feature only works if `save_solutions=True`.
2. The user can use the `tqdm` library to show a progress bar. #50
```python
import pygad
import numpy
import tqdm
equation_inputs = [4,-2,3.5]
desired_output = 44
def fitness_func(solution, solution_idx):
output = numpy.sum(solution * equation_inputs)
fitness = 1.0 / (numpy.abs(output - desired_output) + 0.000001)
return fitness
num_generations = 10000
with tqdm.tqdm(total=num_generations) as pbar:
ga_instance = pygad.GA(num_generations=num_generations,
sol_per_pop=5,
num_parents_mating=2,
num_genes=len(equation_inputs),
fitness_func=fitness_func,
on_generation=lambda _: pbar.update(1))
ga_instance.run()
ga_instance.plot_result()
```
3. Solved the issue of unequal length between the `solutions` and `solutions_fitness` when the `save_solutions` parameter is set to `True`. Now, the fitness of the last population is appended to the `solutions_fitness` array. #64
4. There was an issue of getting the length of these 4 variables (`solutions`, `solutions_fitness`, `best_solutions`, and `best_solutions_fitness`) doubled after each call of the `run()` method. This is solved by resetting these variables at the beginning of the `run()` method. #62
5. Bug fixes when adaptive mutation is used (`mutation_type="adaptive"`). #65
Copy file name to clipboardExpand all lines: pygad.py
+29-9
Original file line number
Diff line number
Diff line change
@@ -1169,7 +1169,14 @@ def run(self):
1169
1169
"""
1170
1170
1171
1171
ifself.valid_parameters==False:
1172
-
raiseValueError("ERROR calling the run() method: \nThe run() method cannot be executed with invalid parameters. Please check the parameters passed while creating an instance of the GA class.\n")
1172
+
raiseValueError("Error calling the run() method: \nThe run() method cannot be executed with invalid parameters. Please check the parameters passed while creating an instance of the GA class.\n")
1173
+
1174
+
# Reset the variables that store the solutions and their fitness after each generation. If not reset, then for each call to the run() method the new solutions and their fitness values will be appended to the old variables and their length double. Some errors arise if not reset.
1175
+
# If, in the future, new variables are created that get appended after each generation, please consider resetting them here.
1176
+
self.best_solutions= [] # Holds the best solution in each generation.
1177
+
self.best_solutions_fitness= [] # A list holding the fitness value of the best solution for each generation.
1178
+
self.solutions= [] # Holds the solutions in each generation.
1179
+
self.solutions_fitness= [] # Holds the fitness of the solutions in each generation.
0 commit comments