Skip to content

Commit

Permalink
Remove verobosity parameter in BinaryIndividual.
Browse files Browse the repository at this point in the history
  • Loading branch information
PytLab committed Dec 15, 2017
1 parent 42d1256 commit b0af27e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
18 changes: 2 additions & 16 deletions gaft/components/binary_individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,29 @@


class BinaryIndividual(IndividualBase):
def __init__(self, ranges, eps=0.001, verbosity=1):
def __init__(self, ranges, eps=0.001):
'''
Class for individual in population. Random solution will be initialized
by default.
NOTE: The decrete precisions for different components in varants may be
adjusted automatically (possible precision loss) if eps and ranges
are not appropriate.
Please check it before you put it into GA engine. If you don't want
to see the warning info, set verbosity to 0 :)
:param ranges: value ranges for all entries in solution.
:type ranges: list of range tuples. e.g. [(0, 1), (-1, 1)]
:param eps: decrete precisions for binary encoding, default is 0.001.
:type eps: float or float list with the same length with ranges.
:param verbosity: The verbosity level of info output.
:param verbosity: int, 0 or 1(default)
'''
super(self.__class__, self).__init__(ranges, eps)

self.verbosity = verbosity

# Lengths for all binary sequence in chromsome and adjusted decrete precisions.
self.lengths = []

for i, ((a, b), eps) in enumerate(zip(self.ranges, self.eps)):
length = int(log2((b - a)/eps))
precision = (b - a)/(2**length)

if precision != eps and mpi.is_master and self.verbosity:
print('Precision loss {} -> {}'.format(eps, precision))

self.lengths.append(length)
self.precisions[i] = precision

Expand All @@ -60,9 +48,7 @@ def clone(self):
'''
Clone a new individual from current one.
'''
indv = self.__class__(self.ranges,
eps=self.eps,
verbosity=self.verbosity)
indv = self.__class__(self.ranges, eps=self.eps)
indv.init(chromsome=self.chromsome)
return indv

Expand Down
3 changes: 1 addition & 2 deletions gaft/components/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ def init(self, indvs=None):
if indvs is None:
for _ in range(self.size):
indv = IndvType(ranges=self.indv_template.ranges,
eps=self.indv_template.eps,
verbosity=self.indv_template.verbosity)
eps=self.indv_template.eps)
self.individuals.append(indv)
else:
# Check individuals.
Expand Down

0 comments on commit b0af27e

Please sign in to comment.