Skip to content

Commit 759ed4e

Browse files
authored
Merge pull request #230 from ahmedfgad/github-actions
PyGAD 3.2.0
2 parents 5bb342e + d50f118 commit 759ed4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+5045
-3818
lines changed

NSGA-II/non_dominant_sorting.py

-62
This file was deleted.

README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PyGAD: Genetic Algorithm in Python
22

3-
[PyGAD](https://pypi.org/project/pygad) is an open-source easy-to-use Python 3 library for building the genetic algorithm and optimizing machine learning algorithms. It supports Keras and PyTorch.
3+
[PyGAD](https://pypi.org/project/pygad) is an open-source easy-to-use Python 3 library for building the genetic algorithm and optimizing machine learning algorithms. It supports Keras and PyTorch. PyGAD supports optimizing both single-objective and multi-objective problems.
44

55
Check documentation of the [PyGAD](https://pygad.readthedocs.io/en/latest).
66

@@ -146,7 +146,7 @@ on_stop()
146146

147147
# Example
148148

149-
Check the [PyGAD's documentation](https://pygad.readthedocs.io/en/latest/pygad.html) for information about the implementation of this example.
149+
Check the [PyGAD's documentation](https://pygad.readthedocs.io/en/latest/pygad.html) for information about the implementation of this example. It solves a single-objective problem.
150150

151151
```python
152152
import pygad
@@ -183,9 +183,9 @@ num_genes = len(function_inputs)
183183
last_fitness = 0
184184
def callback_generation(ga_instance):
185185
global last_fitness
186-
print("Generation = {generation}".format(generation=ga_instance.generations_completed))
187-
print("Fitness = {fitness}".format(fitness=ga_instance.best_solution()[1]))
188-
print("Change = {change}".format(change=ga_instance.best_solution()[1] - last_fitness))
186+
print(f"Generation = {ga_instance.generations_completed}")
187+
print(f"Fitness = {ga_instance.best_solution()[1]}")
188+
print(f"Change = {ga_instance.best_solution()[1] - last_fitness}")
189189
last_fitness = ga_instance.best_solution()[1]
190190

191191
# Creating an instance of the GA class inside the ga module. Some parameters are initialized within the constructor.
@@ -204,15 +204,15 @@ ga_instance.plot_fitness()
204204

205205
# Returning the details of the best solution.
206206
solution, solution_fitness, solution_idx = ga_instance.best_solution()
207-
print("Parameters of the best solution : {solution}".format(solution=solution))
208-
print("Fitness value of the best solution = {solution_fitness}".format(solution_fitness=solution_fitness))
209-
print("Index of the best solution : {solution_idx}".format(solution_idx=solution_idx))
207+
print(f"Parameters of the best solution : {solution}")
208+
print(f"Fitness value of the best solution = {solution_fitness}")
209+
print(f"Index of the best solution : {solution_idx}")
210210

211211
prediction = numpy.sum(numpy.array(function_inputs)*solution)
212-
print("Predicted output based on the best solution : {prediction}".format(prediction=prediction))
212+
print(f"Predicted output based on the best solution : {prediction}")
213213

214214
if ga_instance.best_solution_generation != -1:
215-
print("Best fitness value reached after {best_solution_generation} generations.".format(best_solution_generation=ga_instance.best_solution_generation))
215+
print(g"Best fitness value reached after {ga_instance.best_solution_generation} generations.")
216216

217217
# Saving the GA instance.
218218
filename = 'genetic' # The filename to which the instance is saved. The name is without extension.

docs/source/cnn.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,9 @@ addition to the classification accuracy.
644644
num_wrong = numpy.where(predictions != train_outputs)[0]
645645
num_correct = train_outputs.size - num_wrong.size
646646
accuracy = 100 * (num_correct/train_outputs.size)
647-
print("Number of correct classifications : {num_correct}.".format(num_correct=num_correct))
648-
print("Number of wrong classifications : {num_wrong}.".format(num_wrong=num_wrong.size))
649-
print("Classification accuracy : {accuracy}.".format(accuracy=accuracy))
647+
print(f"Number of correct classifications : {num_correct}.")
648+
print(f"Number of wrong classifications : {num_wrong.size}.")
649+
print(f"Classification accuracy : {accuracy}.")
650650
651651
It is very important to note that it is not expected that the
652652
classification accuracy is high because no training algorithm is used.
@@ -743,6 +743,6 @@ files before running this code.
743743
num_wrong = numpy.where(predictions != train_outputs)[0]
744744
num_correct = train_outputs.size - num_wrong.size
745745
accuracy = 100 * (num_correct/train_outputs.size)
746-
print("Number of correct classifications : {num_correct}.".format(num_correct=num_correct))
747-
print("Number of wrong classifications : {num_wrong}.".format(num_wrong=num_wrong.size))
748-
print("Classification accuracy : {accuracy}.".format(accuracy=accuracy))
746+
print(f"Number of correct classifications : {num_correct}.")
747+
print(f"Number of wrong classifications : {num_wrong.size}.")
748+
print(f"Classification accuracy : {accuracy}.")

docs/source/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
author = 'Ahmed Fawzy Gad'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = '3.1.0'
25+
release = '3.2.0'
2626

2727
master_doc = 'index'
2828

docs/source/gacnn.rst

+19-19
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ solutions within the population.
405405
population_matrices = gacnn.population_as_matrices(population_networks=GACNN_instance.population_networks, population_vectors=ga_instance.population)
406406
GACNN_instance.update_population_trained_weights(population_trained_weights=population_matrices)
407407
408-
print("Generation = {generation}".format(generation=ga_instance.generations_completed))
408+
print(f"Generation = {ga_instance.generations_completed}")
409409
410410
After preparing the fitness and callback function, next is to create an
411411
instance of the ``pygad.GA`` class.
@@ -462,7 +462,7 @@ be called to show how the fitness values evolve by generation.
462462
463463
ga_instance.plot_fitness()
464464
465-
.. figure:: https://user-images.githubusercontent.com/16560492/83429675-ab744580-a434-11ea-8f21-9d3804b50d15.png
465+
.. image:: https://user-images.githubusercontent.com/16560492/83429675-ab744580-a434-11ea-8f21-9d3804b50d15.png
466466
:alt:
467467

468468
Information about the Best Solution
@@ -483,9 +483,9 @@ Here is how such information is returned.
483483
.. code:: python
484484
485485
solution, solution_fitness, solution_idx = ga_instance.best_solution()
486-
print("Parameters of the best solution : {solution}".format(solution=solution))
487-
print("Fitness value of the best solution = {solution_fitness}".format(solution_fitness=solution_fitness))
488-
print("Index of the best solution : {solution_idx}".format(solution_idx=solution_idx))
486+
print(f"Parameters of the best solution : {solution}")
487+
print(f"Fitness value of the best solution = {solution_fitness}")
488+
print(f"Index of the best solution : {solution_idx}")
489489
490490
.. code::
491491
@@ -504,7 +504,7 @@ the labels correctly.
504504
.. code:: python
505505
506506
predictions = pygad.cnn.predict(last_layer=GANN_instance.population_networks[solution_idx], data_inputs=data_inputs)
507-
print("Predictions of the trained network : {predictions}".format(predictions=predictions))
507+
print(f"Predictions of the trained network : {predictions}")
508508
509509
Calculating Some Statistics
510510
---------------------------
@@ -518,9 +518,9 @@ addition to the classification accuracy.
518518
num_wrong = numpy.where(predictions != data_outputs)[0]
519519
num_correct = data_outputs.size - num_wrong.size
520520
accuracy = 100 * (num_correct/data_outputs.size)
521-
print("Number of correct classifications : {num_correct}.".format(num_correct=num_correct))
522-
print("Number of wrong classifications : {num_wrong}.".format(num_wrong=num_wrong.size))
523-
print("Classification accuracy : {accuracy}.".format(accuracy=accuracy))
521+
print(f"Number of correct classifications : {num_correct}.")
522+
print(f"Number of wrong classifications : {num_wrong.size}.")
523+
print(f"Classification accuracy : {accuracy}.")
524524
525525
.. code::
526526
@@ -575,8 +575,8 @@ complete code is listed below.
575575
576576
GACNN_instance.update_population_trained_weights(population_trained_weights=population_matrices)
577577
578-
print("Generation = {generation}".format(generation=ga_instance.generations_completed))
579-
print("Fitness = {fitness}".format(fitness=ga_instance.best_solutions_fitness))
578+
print(f"Generation = {ga_instance.generations_completed}")
579+
print(f"Fitness = {ga_instance.best_solutions_fitness}")
580580
581581
data_inputs = numpy.load("dataset_inputs.npy")
582582
data_outputs = numpy.load("dataset_outputs.npy")
@@ -642,21 +642,21 @@ complete code is listed below.
642642
643643
# Returning the details of the best solution.
644644
solution, solution_fitness, solution_idx = ga_instance.best_solution()
645-
print("Parameters of the best solution : {solution}".format(solution=solution))
646-
print("Fitness value of the best solution = {solution_fitness}".format(solution_fitness=solution_fitness))
647-
print("Index of the best solution : {solution_idx}".format(solution_idx=solution_idx))
645+
print(f"Parameters of the best solution : {solution}")
646+
print(f"Fitness value of the best solution = {solution_fitness}")
647+
print(f"Index of the best solution : {solution_idx}")
648648
649649
if ga_instance.best_solution_generation != -1:
650-
print("Best fitness value reached after {best_solution_generation} generations.".format(best_solution_generation=ga_instance.best_solution_generation))
650+
print(f"Best fitness value reached after {ga_instance.best_solution_generation} generations.")
651651
652652
# Predicting the outputs of the data using the best solution.
653653
predictions = GACNN_instance.population_networks[solution_idx].predict(data_inputs=data_inputs)
654-
print("Predictions of the trained network : {predictions}".format(predictions=predictions))
654+
print(f"Predictions of the trained network : {predictions}")
655655
656656
# Calculating some statistics
657657
num_wrong = numpy.where(predictions != data_outputs)[0]
658658
num_correct = data_outputs.size - num_wrong.size
659659
accuracy = 100 * (num_correct/data_outputs.size)
660-
print("Number of correct classifications : {num_correct}.".format(num_correct=num_correct))
661-
print("Number of wrong classifications : {num_wrong}.".format(num_wrong=num_wrong.size))
662-
print("Classification accuracy : {accuracy}.".format(accuracy=accuracy))
660+
print(f"Number of correct classifications : {num_correct}.")
661+
print(f"Number of wrong classifications : {num_wrong.size}.")
662+
print(f"Classification accuracy : {accuracy}.")

0 commit comments

Comments
 (0)