From 87535553814f3950d331a6feb40c9c530d83e77f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E4=BE=83?= Date: Thu, 4 Jan 2024 12:53:42 +0800 Subject: [PATCH 1/4] fix IndexError: The gp.generate function tried to add a primitive of type '' --- deap/gp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deap/gp.py b/deap/gp.py index ccc47b6b..dca882b3 100644 --- a/deap/gp.py +++ b/deap/gp.py @@ -631,7 +631,7 @@ def generate(pset, min_, max_, condition, type_=None): stack = [(0, type_)] while len(stack) != 0: depth, type_ = stack.pop() - if condition(height, depth): + if condition(height, depth) or len(pset.primitives[type_]) == 0: try: term = random.choice(pset.terminals[type_]) except IndexError: From 725ba670d6273c7ceb0a4cd6e750f9c895ec078a Mon Sep 17 00:00:00 2001 From: wukan Date: Thu, 4 Jan 2024 18:55:41 +0800 Subject: [PATCH 2/4] support evaluate function return nan fix #440 --- deap/base.py | 4 ++-- deap/tools/support.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/deap/base.py b/deap/base.py index f9d84ba6..3fd2a518 100644 --- a/deap/base.py +++ b/deap/base.py @@ -232,10 +232,10 @@ def __hash__(self): return hash(self.wvalues) def __gt__(self, other): - return not self.__le__(other) + return self.wvalues > other.wvalues def __ge__(self, other): - return not self.__lt__(other) + return self.wvalues >= other.wvalues def __le__(self, other): return self.wvalues <= other.wvalues diff --git a/deap/tools/support.py b/deap/tools/support.py index 2f7433bd..95948f70 100644 --- a/deap/tools/support.py +++ b/deap/tools/support.py @@ -522,10 +522,12 @@ def update(self, population): update the hall of fame with. """ for ind in population: + if ind.fitness.values[0] != ind.fitness.values[0]: + continue if len(self) == 0 and self.maxsize != 0: # Working on an empty hall of fame is problematic for the # "for else" - self.insert(population[0]) + self.insert(ind) continue if ind.fitness > self[-1].fitness or len(self) < self.maxsize: for hofer in self: From d7cf32446843f112c8e9a84b78f039f1986762e4 Mon Sep 17 00:00:00 2001 From: wukan Date: Thu, 4 Jan 2024 19:20:10 +0800 Subject: [PATCH 3/4] support evaluate function return nan --- deap/base.py | 4 ++-- deap/tools/support.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/deap/base.py b/deap/base.py index f9d84ba6..3fd2a518 100644 --- a/deap/base.py +++ b/deap/base.py @@ -232,10 +232,10 @@ def __hash__(self): return hash(self.wvalues) def __gt__(self, other): - return not self.__le__(other) + return self.wvalues > other.wvalues def __ge__(self, other): - return not self.__lt__(other) + return self.wvalues >= other.wvalues def __le__(self, other): return self.wvalues <= other.wvalues diff --git a/deap/tools/support.py b/deap/tools/support.py index 2f7433bd..95948f70 100644 --- a/deap/tools/support.py +++ b/deap/tools/support.py @@ -522,10 +522,12 @@ def update(self, population): update the hall of fame with. """ for ind in population: + if ind.fitness.values[0] != ind.fitness.values[0]: + continue if len(self) == 0 and self.maxsize != 0: # Working on an empty hall of fame is problematic for the # "for else" - self.insert(population[0]) + self.insert(ind) continue if ind.fitness > self[-1].fitness or len(self) < self.maxsize: for hofer in self: From de9b154ceb379341a609d0201e07d2de0a4817a9 Mon Sep 17 00:00:00 2001 From: wukan Date: Fri, 5 Jan 2024 11:36:29 +0800 Subject: [PATCH 4/4] Revert "support evaluate function return nan" This reverts commit 725ba670d6273c7ceb0a4cd6e750f9c895ec078a. --- deap/base.py | 4 ++-- deap/tools/support.py | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/deap/base.py b/deap/base.py index 3fd2a518..f9d84ba6 100644 --- a/deap/base.py +++ b/deap/base.py @@ -232,10 +232,10 @@ def __hash__(self): return hash(self.wvalues) def __gt__(self, other): - return self.wvalues > other.wvalues + return not self.__le__(other) def __ge__(self, other): - return self.wvalues >= other.wvalues + return not self.__lt__(other) def __le__(self, other): return self.wvalues <= other.wvalues diff --git a/deap/tools/support.py b/deap/tools/support.py index 95948f70..2f7433bd 100644 --- a/deap/tools/support.py +++ b/deap/tools/support.py @@ -522,12 +522,10 @@ def update(self, population): update the hall of fame with. """ for ind in population: - if ind.fitness.values[0] != ind.fitness.values[0]: - continue if len(self) == 0 and self.maxsize != 0: # Working on an empty hall of fame is problematic for the # "for else" - self.insert(ind) + self.insert(population[0]) continue if ind.fitness > self[-1].fitness or len(self) < self.maxsize: for hofer in self: