Skip to content

Commit

Permalink
Fix bug in redundant fitness function calling.
Browse files Browse the repository at this point in the history
  • Loading branch information
PytLab committed Jan 15, 2018
1 parent edde585 commit ecb653a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions gaft/analysis/console_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def setup(self, ng, engine):
def register_step(self, g, population, engine):
best_indv = population.best_indv(engine.fitness)
ng_info = 'Generation: {}, '.format(g+1)
fit_info = 'best fitness: {:.3f}, '.format(engine.ori_fitness(best_indv))
scaled_info = 'scaled fitness: {:.3f}'.format(engine.fitness(best_indv))
fit_info = 'best fitness: {:.3f}, '.format(engine.ori_fmax)
scaled_info = 'scaled fitness: {:.3f}'.format(engine.fmax)
msg = ng_info + fit_info + scaled_info
self.logger.info(msg)

def finalize(self, population, engine):
best_indv = population.best_indv(engine.fitness)
x = best_indv.solution
y = engine.fitness(best_indv)
y = engine.ori_fmax
msg = 'Optimal solution: ({}, {})'.format(x, y)
self.logger.info(msg)

2 changes: 1 addition & 1 deletion gaft/analysis/fitness_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setup(self, ng, engine):
def register_step(self, g, population, engine):
# Collect data.
best_indv = population.best_indv(engine.fitness)
best_fit = engine.ori_fitness(best_indv)
best_fit = engine.ori_fmax

self.ngs.append(g)
self.solution.append(best_indv.solution)
Expand Down
6 changes: 3 additions & 3 deletions gaft/components/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __get__(self, instance, cls):
return self

def __call__(self, fitness):
if ((not self.instance.updated) # population not changed
if ((not self.instance.updated) # population not changed
and (self.result is not None) # result already cached
and (fitness == self.fitness)): # fitness not changed
# Return cached result directly.
Expand Down Expand Up @@ -200,13 +200,13 @@ def max(self, fitness):
'''
Get the maximum fitness value in population.
'''
return fitness(self.best_indv(fitness))
return max(self.all_fits(fitness))

def min(self, fitness):
'''
Get the minimum value of fitness in population.
'''
return fitness(self.worst_indv(fitness))
return min(self.all_fits(fitness))

def mean(self, fitness):
'''
Expand Down

0 comments on commit ecb653a

Please sign in to comment.