Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(base.Fitness): fitness value contains np.nan is now invalid #445

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion deap/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class used as base class, for the fitness member of any individual. """
from copy import deepcopy
from functools import partial
from operator import mul, truediv
import numpy as np


class Toolbox(object):
Expand Down Expand Up @@ -225,7 +226,7 @@ def dominates(self, other, obj=slice(None)):
@property
def valid(self):
"""Assess if a fitness is valid or not."""
return len(self.wvalues) != 0
return len(self.wvalues) != 0 and all(not np.isnan(val) for val in self.wvalues)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

Suggested change
return len(self.wvalues) != 0 and all(not np.isnan(val) for val in self.wvalues)
return len(self.wvalues) != 0 and not np.isnan(self.wvalues).any()


def __hash__(self):
return hash(self.wvalues)
Expand Down