From 0040920a570abb5acd0cb799667ca7b9b621d2d2 Mon Sep 17 00:00:00 2001 From: Vladimir Filipovic Date: Tue, 7 Feb 2023 20:17:21 +0100 Subject: [PATCH 1/9] Update selection.py --- deap/tools/selection.py | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/deap/tools/selection.py b/deap/tools/selection.py index e6fdcaf5e..e57958e70 100644 --- a/deap/tools/selection.py +++ b/deap/tools/selection.py @@ -67,6 +67,49 @@ def selTournament(individuals, k, tournsize, fit_attr="fitness"): chosen.append(max(aspirants, key=attrgetter(fit_attr))) return chosen +def selTournamentFineGrained(individuals, k, fgtournsize, fit_attr="fitness"): + """The ratio between exploration and exploitation governs the search process. + Level of exploration(looking for new solutions) and exploitation (using previously + acquired knowledge) is determined by the tournament size. + Very often, the search process converges too slow with smaller tournament size and too fast with bigger tournament size. + Fine Grained Tournament Selection (denoted as FGTS) preserves good features of the tournament selection and + (at the same time) allows that setting of the ratio between exploration and exploitation becomes more precise. + FGTS is controlled by real value parameter *fgtournsize* (the desired average tournament size) instead of + the integer parameter. + Similarly to the tournament selection, an individual is chosen if it is the best individual on the tournament. + However, unlike tournament selection, size of the tournament is not unique in the whole population, i.e., tournaments + with different number of competitors can be held within one step of the selection. (see [Filipovic2003fgts]_) + + Procedure selects the best individual among (in average) *fgtournsize* randomly + chosen individuals, *k* times. The list returned contains + references to the input *individuals*. + + :param individuals: A list of individuals to select from. + :param k: The number of individuals to select. + :param fgtournsize: The average number of individuals participating in each + tournament. + :param fit_attr: The attribute of individuals to use as selection criterion + :returns: A list of selected individuals. + + This function uses the :func:`~random.choice` function from the python base + :mod:`random` module. + + .. [Filipovic2003fgts] Filipovic, 2003, Fine-grained Tournament Selection Operator in Genetic Algorithms. + Available from: https://www.cai.sk/ojs/index.php/cai/article/view/452 """ + chosen = [] + tournsizeminus = int(floor(fgtournsize)) + tournsizeplus = tournsizeminus + 1 + kminus = int(ceil(k*(tournsizeplus - fgtournsize)) ) + kplus = k - kminus + for i in xrange(kminus): + aspirants = selRandom(individuals, tournsizeminus) + chosen.append(max(aspirants, key=attrgetter(fit_attr))) + for i in xrange(kplus): + aspirants = selRandom(individuals, tournsizeplus) + chosen.append(max(aspirants, key=attrgetter(fit_attr))) + return chosen + + def selRoulette(individuals, k, fit_attr="fitness"): """Select *k* individuals from the input *individuals* using *k* spins of a roulette. The selection is made by looking only at the first From a23dad56fdfdcb6444f4c9e0597bec4f028c8cbd Mon Sep 17 00:00:00 2001 From: Vladimir Filipovic Date: Wed, 8 Feb 2023 19:13:34 +0100 Subject: [PATCH 2/9] zakrpio mutation --- deap/tools/mutation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deap/tools/mutation.py b/deap/tools/mutation.py index 1f0fefced..2016ec57c 100644 --- a/deap/tools/mutation.py +++ b/deap/tools/mutation.py @@ -2,7 +2,7 @@ import random from itertools import repeat -from past.builtins import xrange +#from past.builtins import xrange try: from collections.abc import Sequence From d29ac18b84814091b8fbbade1b280beba43c5da7 Mon Sep 17 00:00:00 2001 From: Vladimir Filipovic Date: Thu, 9 Feb 2023 10:25:20 +0100 Subject: [PATCH 3/9] registrovao FGTS --- deap/tools/selection.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deap/tools/selection.py b/deap/tools/selection.py index e57958e70..d0d60cbf5 100644 --- a/deap/tools/selection.py +++ b/deap/tools/selection.py @@ -360,6 +360,7 @@ def selAutomaticEpsilonLexicase(individuals, k): __all__ = ['selRandom', 'selBest', 'selWorst', 'selRoulette', - 'selTournament', 'selDoubleTournament', 'selStochasticUniversalSampling', + 'selTournament', 'selTournamentFineGrained', + 'selDoubleTournament', 'selStochasticUniversalSampling', 'selLexicase', 'selEpsilonLexicase', 'selAutomaticEpsilonLexicase'] From 81009337c986bdfd60a121a0ba073a1d99aa3428 Mon Sep 17 00:00:00 2001 From: Vladimir Filipovic Date: Thu, 9 Feb 2023 10:31:55 +0100 Subject: [PATCH 4/9] popravio --- deap/tools/selection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deap/tools/selection.py b/deap/tools/selection.py index d0d60cbf5..33b62ca4e 100644 --- a/deap/tools/selection.py +++ b/deap/tools/selection.py @@ -97,9 +97,9 @@ def selTournamentFineGrained(individuals, k, fgtournsize, fit_attr="fitness"): .. [Filipovic2003fgts] Filipovic, 2003, Fine-grained Tournament Selection Operator in Genetic Algorithms. Available from: https://www.cai.sk/ojs/index.php/cai/article/view/452 """ chosen = [] - tournsizeminus = int(floor(fgtournsize)) + tournsizeminus = int(math.floor(fgtournsize)) tournsizeplus = tournsizeminus + 1 - kminus = int(ceil(k*(tournsizeplus - fgtournsize)) ) + kminus = int(math.ceil(k*(tournsizeplus - fgtournsize)) ) kplus = k - kminus for i in xrange(kminus): aspirants = selRandom(individuals, tournsizeminus) From 08114a843af1c73a22de5f02aaf4d00fdbb0178c Mon Sep 17 00:00:00 2001 From: Vladimir Filipovic Date: Thu, 9 Feb 2023 10:38:00 +0100 Subject: [PATCH 5/9] import math for fgts --- deap/tools/selection.py | 1 + 1 file changed, 1 insertion(+) diff --git a/deap/tools/selection.py b/deap/tools/selection.py index 33b62ca4e..3e3290f38 100644 --- a/deap/tools/selection.py +++ b/deap/tools/selection.py @@ -1,3 +1,4 @@ +import math import random import numpy as np From 005120ec54ceaef30e69a8f45775ee9617ffb01a Mon Sep 17 00:00:00 2001 From: Vladimir Filipovic Date: Thu, 9 Feb 2023 10:56:21 +0100 Subject: [PATCH 6/9] xrange -> range --- deap/tools/selection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deap/tools/selection.py b/deap/tools/selection.py index 3e3290f38..b826757e8 100644 --- a/deap/tools/selection.py +++ b/deap/tools/selection.py @@ -102,10 +102,10 @@ def selTournamentFineGrained(individuals, k, fgtournsize, fit_attr="fitness"): tournsizeplus = tournsizeminus + 1 kminus = int(math.ceil(k*(tournsizeplus - fgtournsize)) ) kplus = k - kminus - for i in xrange(kminus): + for i in range(kminus): aspirants = selRandom(individuals, tournsizeminus) chosen.append(max(aspirants, key=attrgetter(fit_attr))) - for i in xrange(kplus): + for i in range(kplus): aspirants = selRandom(individuals, tournsizeplus) chosen.append(max(aspirants, key=attrgetter(fit_attr))) return chosen From 0ebb9c892fcb208a9abe5bf896df09a7140964f2 Mon Sep 17 00:00:00 2001 From: Vladimir Filipovic Date: Thu, 9 Feb 2023 11:52:39 +0100 Subject: [PATCH 7/9] Update selection.py --- deap/tools/selection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deap/tools/selection.py b/deap/tools/selection.py index b826757e8..8e9147a20 100644 --- a/deap/tools/selection.py +++ b/deap/tools/selection.py @@ -94,7 +94,7 @@ def selTournamentFineGrained(individuals, k, fgtournsize, fit_attr="fitness"): This function uses the :func:`~random.choice` function from the python base :mod:`random` module. - + .. [Filipovic2003fgts] Filipovic, 2003, Fine-grained Tournament Selection Operator in Genetic Algorithms. Available from: https://www.cai.sk/ojs/index.php/cai/article/view/452 """ chosen = [] From 38d97a9f135d05b17bbd7004c39f7923d41c2e61 Mon Sep 17 00:00:00 2001 From: Vladimir Filipovic Date: Mon, 5 Jun 2023 21:39:20 +0200 Subject: [PATCH 8/9] dodao poetry --- pyproject.toml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..677f1afce --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,14 @@ +[tool.poetry] +name = "deap" +version = "0.2.0" +description = "forked DEAP" +authors = ["Vladimir Filipovic "] +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.10" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" From 686381d9b193ea3b824fa252fbf4c808a47078a0 Mon Sep 17 00:00:00 2001 From: Vladimir Filipovic Date: Tue, 6 Jun 2023 18:54:27 +0200 Subject: [PATCH 9/9] Update pyproject.toml --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 677f1afce..9d85672ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,6 @@ readme = "README.md" [tool.poetry.dependencies] python = "^3.10" - [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api"