Skip to content

Commit 5709795

Browse files
authored
Merge pull request #358 from ahmedfgad/github-actions
Prepare PyGAD 3.7.0 release
2 parents 4ded7c5 + f3414aa commit 5709795

105 files changed

Lines changed: 9584 additions & 1310 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,14 @@ __pycache__/
1515
# =============================================================================
1616
docs/build/
1717
.venv-docs/
18+
19+
# =============================================================================
20+
# Local virtual environment (setup_venv.sh).
21+
# =============================================================================
22+
.venv/
23+
24+
# =============================================================================
25+
# IDE settings: JetBrains (PyCharm, IntelliJ, etc.) workspace files.
26+
# These are personal to each developer and should not be committed.
27+
# =============================================================================
28+
.idea/

README.md

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
[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

5-
> Try the [Optimization Gadget](https://optimgadget.com), a free cloud-based tool powered by PyGAD. It makes optimization easier by reducing or removing the need for coding, and it shows helpful visualizations.
5+
> Try [Vilvik](https://vilvik.com), a free cloud-based tool powered by PyGAD. It makes optimization easier by reducing or removing the need for coding, and it shows helpful visualizations.
66
77
Read the [PyGAD documentation](https://pygad.readthedocs.io/en/latest).
88

99
[![PyPI Downloads](https://pepy.tech/badge/pygad)](https://pepy.tech/project/pygad) [![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/pygad.svg?label=Conda%20Downloads)](
10-
https://anaconda.org/conda-forge/PyGAD) [![PyPI version](https://badge.fury.io/py/pygad.svg)](https://badge.fury.io/py/pygad)![Docs](https://readthedocs.org/projects/pygad/badge)[![PyGAD PyTest / Python 3.13](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py313.yml/badge.svg)](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py313.yml) [![PyGAD PyTest / Python 3.12](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py312.yml/badge.svg)](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py312.yml) [![PyGAD PyTest / Python 3.11](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py311.yml/badge.svg)](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py311.yml) [![PyGAD PyTest / Python 3.10](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py310.yml/badge.svg)](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py310.yml) [![PyGAD PyTest / Python 3.9](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py39.yml/badge.svg)](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py39.yml) [![PyGAD PyTest / Python 3.8](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py38.yml/badge.svg)](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main_py38.yml) [![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) [![Translation](https://hosted.weblate.org/widgets/weblate/-/svg-badge.svg)](https://hosted.weblate.org/engage/weblate/) [![REUSE](https://api.reuse.software/badge/github.com/WeblateOrg/weblate)](https://api.reuse.software/info/github.com/WeblateOrg/weblate) [![Stack Overflow](https://img.shields.io/badge/stackoverflow-Ask%20questions-blue.svg)](
10+
https://anaconda.org/conda-forge/PyGAD) [![PyPI version](https://badge.fury.io/py/pygad.svg)](https://badge.fury.io/py/pygad)![Docs](https://readthedocs.org/projects/pygad/badge)[![PyGAD PyTest / Python 3.13](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main.yml/badge.svg)](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/main.yml) [![PyGAD PyTest / Python 3.12](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/release.yml/badge.svg)](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/release.yml) [![PyGAD PyTest / Python 3.11](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/scorecard.yml/badge.svg)](https://github.com/ahmedfgad/GeneticAlgorithmPython/actions/workflows/scorecard.yml) [![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) [![Translation](https://hosted.weblate.org/widgets/weblate/-/svg-badge.svg)](https://hosted.weblate.org/engage/weblate/) [![REUSE](https://api.reuse.software/badge/github.com/WeblateOrg/weblate)](https://api.reuse.software/info/github.com/WeblateOrg/weblate) [![Stack Overflow](https://img.shields.io/badge/stackoverflow-Ask%20questions-blue.svg)](
1111
https://stackoverflow.com/questions/tagged/pygad) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/ahmedfgad/GeneticAlgorithmPython/badge)](https://securityscorecards.dev/viewer/?uri=github.com/ahmedfgad/GeneticAlgorithmPython) [![DOI](https://zenodo.org/badge/DOI/10.1007/s11042-023-17167-y.svg)](https://doi.org/10.1007/s11042-023-17167-y)
1212

1313
![PYGAD-LOGO](https://user-images.githubusercontent.com/16560492/101267295-c74c0180-375f-11eb-9ad0-f8e37bd796ce.png)
@@ -18,7 +18,6 @@ The library is under active development and more features are added regularly. I
1818

1919
# Donation
2020

21-
* [Credit/Debit Card](https://donate.stripe.com/eVa5kO866elKgM0144): https://donate.stripe.com/eVa5kO866elKgM0144
2221
* [Open Collective](https://opencollective.com/pygad): [opencollective.com/pygad](https://opencollective.com/pygad)
2322
* PayPal: Use either this link: [paypal.me/ahmedfgad](https://paypal.me/ahmedfgad) or the e-mail address ahmed.f.gad@gmail.com
2423
* Interac e-Transfer: Use e-mail address ahmed.f.gad@gmail.com
@@ -45,18 +44,6 @@ pip install pygad[deep_learning]
4544

4645
To get started with PyGAD, read the documentation at [Read the Docs](https://pygad.readthedocs.io).
4746

48-
# PyGAD Source Code
49-
50-
The source code of the PyGAD modules is in the following GitHub projects:
51-
52-
- [pygad](https://github.com/ahmedfgad/GeneticAlgorithmPython): (https://github.com/ahmedfgad/GeneticAlgorithmPython)
53-
- [pygad.nn](https://github.com/ahmedfgad/NumPyANN): https://github.com/ahmedfgad/NumPyANN
54-
- [pygad.gann](https://github.com/ahmedfgad/NeuralGenetic): https://github.com/ahmedfgad/NeuralGenetic
55-
- [pygad.cnn](https://github.com/ahmedfgad/NumPyCNN): https://github.com/ahmedfgad/NumPyCNN
56-
- [pygad.gacnn](https://github.com/ahmedfgad/CNNGenetic): https://github.com/ahmedfgad/CNNGenetic
57-
- [pygad.kerasga](https://github.com/ahmedfgad/KerasGA): https://github.com/ahmedfgad/KerasGA
58-
- [pygad.torchga](https://github.com/ahmedfgad/TorchGA): https://github.com/ahmedfgad/TorchGA
59-
6047
# PyGAD Documentation
6148

6249
The PyGAD documentation is available at [Read the Docs](https://pygad.readthedocs.io) at this link: https://pygad.readthedocs.io. It explains the modules supported by PyGAD and all its classes, methods, attributes, and functions. For each module, several examples are given.
@@ -304,7 +291,4 @@ If you used PyGAD, please consider adding a citation to the following paper abou
304291

305292
* E-mail: ahmed.f.gad@gmail.com
306293
* [LinkedIn](https://www.linkedin.com/in/ahmedfgad)
307-
* [Paperspace](https://blog.paperspace.com/author/ahmed)
308-
* [KDnuggets](https://kdnuggets.com/author/ahmed-gad)
309-
* [TowardsDataScience](https://towardsdatascience.com/@ahmedfgad)
310294
* [GitHub](https://github.com/ahmedfgad)

docs/source/benchmarks.md

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# Benchmark Problems
2+
3+
PyGAD bundles common benchmark problems under `pygad.benchmarks`. Each problem is a class callable with `(ga, solution, sol_idx)` and returns a fitness in PyGAD's maximisation format. Minimisation values are negated.
4+
5+
Class attributes for setting up the GA:
6+
7+
- `num_genes`: number of decision variables.
8+
- `num_objectives`: number of objectives (`1` for single-objective).
9+
- `bounds`: `(low, high)` tuple of variable bounds.
10+
11+
ZDT classes also have a `pareto_front(num_points)` method that returns true-front reference points. Pass these to the IGD or GD indicators as `reference_front`.
12+
13+
A runnable example per benchmark lives under `examples/benchmarks/`.
14+
15+
## Single-Objective Problems
16+
17+
Available in `pygad.benchmarks.classic`:
18+
19+
| Class | Global minimum | Bounds |
20+
|---|---|---|
21+
| `Sphere` | f(0, ..., 0) = 0 | `(-5.12, 5.12)` |
22+
| `Rastrigin` | f(0, ..., 0) = 0 | `(-5.12, 5.12)` |
23+
| `Rosenbrock` | f(1, ..., 1) = 0 | `(-5.0, 10.0)` |
24+
| `Griewank` | f(0, ..., 0) = 0 | `(-600.0, 600.0)` |
25+
| `Schwefel` | f(420.97, ..., 420.97) ≈ 0 | `(-500.0, 500.0)` |
26+
| `Ackley` | f(0, ..., 0) = 0 | `(-32.768, 32.768)` |
27+
| `Himmelblau` | four equal minima at f = 0 (2D only) | `(-5.0, 5.0)` |
28+
29+
## Multi-Objective Problems (ZDT family)
30+
31+
In `pygad.benchmarks.zdt`. Two objectives, variables in `[0, 1]` (ZDT4 uses `[-5, 5]` for the rest).
32+
33+
| Class | Pareto front shape |
34+
|---|---|
35+
| `ZDT1` | convex |
36+
| `ZDT2` | non-convex |
37+
| `ZDT3` | disconnected (five pieces) |
38+
| `ZDT4` | convex, many local minima in the search space |
39+
| `ZDT6` | non-uniform |
40+
41+
## Many-Objective Problems (DTLZ family)
42+
43+
In `pygad.benchmarks.dtlz`. Any number of objectives `M`. Decision variables: `M + k - 1`, where `k` is the distance-variable count.
44+
45+
| Class | Default M | Pareto front shape |
46+
|---|---|---|
47+
| `DTLZ1` | 3 | linear hyperplane (`sum(f_i) = 0.5`) |
48+
| `DTLZ2` | 3 | unit sphere first orthant |
49+
| `DTLZ3` | 3 | unit sphere with hard multimodal g-function |
50+
| `DTLZ4` | 3 | unit sphere with strong bias toward one corner |
51+
52+
## Combinatorial Problems
53+
54+
Two combinatorial benchmarks: 0/1 `Knapsack` and `TSP`.
55+
56+
### Knapsack
57+
58+
In `pygad.benchmarks.knapsack`. `Knapsack` takes three arguments: 1D arrays of `weights` and `values`, and a numeric `capacity`. A solution is a binary vector (1 = pick the item). Fitness is the total value within capacity, or a negative penalty scaled by the overweight amount.
59+
60+
Class attributes `gene_space=[0, 1]` and `gene_type=int` plug into PyGAD as is:
61+
62+
```python
63+
import pygad
64+
from pygad.benchmarks.knapsack import Knapsack
65+
66+
problem = Knapsack(weights=[2, 3, 4, 5],
67+
values=[3, 4, 5, 6],
68+
capacity=5)
69+
70+
ga = pygad.GA(
71+
num_generations=50,
72+
num_parents_mating=10,
73+
fitness_func=problem,
74+
sol_per_pop=30,
75+
num_genes=problem.num_genes,
76+
gene_space=problem.gene_space,
77+
gene_type=problem.gene_type,
78+
)
79+
ga.run()
80+
```
81+
82+
### Travelling Salesman Problem
83+
84+
In `pygad.benchmarks.tsp`. Build `TSP` from either a 2D `coordinates` array or a square `distance_matrix`. A solution is a permutation of city indices and the fitness is the negative tour length (the tour closes back to the start). Non-permutation candidates get a large negative penalty.
85+
86+
Class attributes `gene_space=list(range(num_cities))`, `gene_type=int`, and `allow_duplicate_genes=False` keep the permutation constraint:
87+
88+
```python
89+
import pygad
90+
from pygad.benchmarks.tsp import TSP
91+
92+
problem = TSP(coordinates=[[0.0, 0.0],
93+
[1.0, 0.0],
94+
[1.0, 1.0],
95+
[0.0, 1.0]])
96+
97+
ga = pygad.GA(
98+
num_generations=200,
99+
num_parents_mating=10,
100+
fitness_func=problem,
101+
sol_per_pop=30,
102+
num_genes=problem.num_genes,
103+
gene_space=problem.gene_space,
104+
gene_type=problem.gene_type,
105+
allow_duplicate_genes=problem.allow_duplicate_genes,
106+
)
107+
ga.run()
108+
```
109+
110+
## Example: SOO
111+
112+
```python
113+
import pygad
114+
from pygad.benchmarks.classic import Sphere
115+
116+
problem = Sphere(num_genes=10)
117+
118+
ga = pygad.GA(
119+
num_generations=100,
120+
num_parents_mating=10,
121+
fitness_func=problem,
122+
sol_per_pop=20,
123+
num_genes=problem.num_genes,
124+
init_range_low=problem.bounds[0],
125+
init_range_high=problem.bounds[1],
126+
crossover_type='sbx',
127+
sbx_crossover_eta=30,
128+
mutation_type='polynomial',
129+
polynomial_mutation_eta=20,
130+
)
131+
ga.run()
132+
```
133+
134+
## Example: MOO
135+
136+
```python
137+
import pygad
138+
from pygad.benchmarks.zdt import ZDT1
139+
from pygad.utils.quality_indicators import inverted_generational_distance
140+
141+
problem = ZDT1(num_genes=10)
142+
143+
ga = pygad.GA(
144+
num_generations=200,
145+
num_parents_mating=20,
146+
fitness_func=problem,
147+
sol_per_pop=30,
148+
num_genes=problem.num_genes,
149+
init_range_low=problem.bounds[0],
150+
init_range_high=problem.bounds[1],
151+
parent_selection_type='nsga2',
152+
crossover_type='sbx',
153+
sbx_crossover_eta=30,
154+
mutation_type='polynomial',
155+
polynomial_mutation_eta=20,
156+
)
157+
ga.run()
158+
159+
# IGD against the true front.
160+
true_front = problem.pareto_front(num_points=100)
161+
igd = inverted_generational_distance(ga.last_generation_fitness, true_front)
162+
print(f'IGD = {igd}')
163+
```
20.1 KB
Loading
31.7 KB
Loading

docs/source/figures/plot_genes.png

31.8 KB
Loading
23.9 KB
Loading
27.4 KB
Loading
32 KB
Loading
65.1 KB
Loading

0 commit comments

Comments
 (0)