Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

Commit

Permalink
Add hybrid fitness evaluation mode
Browse files Browse the repository at this point in the history
  • Loading branch information
iver56 committed May 8, 2016
1 parent f225d69 commit 94021b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
15 changes: 15 additions & 0 deletions fitness_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,18 @@ def evaluate_multiple(individuals, target_sound):
for ind in fronts[rank]:
fitness = 1.0 / (rank + (0.5 / (1.0 + ind.crowding_distance)))
ind.set_fitness(fitness)


class HybridFitnessEvaluator(object):
# Fitness is relative, i.e. it depends on the fitness of other individuals and may
# change from generation to generation
IS_FITNESS_RELATIVE = True

@staticmethod
def evaluate_multiple(individuals, target_sound):
MultiObjectiveFitnessEvaluator.evaluate_multiple(individuals, target_sound)
for ind in individuals:
fitness = FitnessEvaluator.evaluate(target_sound, ind.output_sound)
ind.set_fitness(
(ind.genotype.GetFitness() + fitness) / 2
)
8 changes: 5 additions & 3 deletions neuroevolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def __init__(self):
type=str,
help='Multi-Objective (mo) fitness optimizes for a diverse'
' population that consists of various non-dominated trade-offs between similarity'
' in different features',
choices=['default', 'mo'],
' in different features. Hybrid fitness is the sum of default and mo.',
choices=['default', 'mo', 'hybrid'],
required=False,
default="default"
)
Expand Down Expand Up @@ -178,6 +178,8 @@ def __init__(self):
self.fitness_evaluator_class = fitness_evaluator.FitnessEvaluator
elif self.args.fitness == 'mo':
self.fitness_evaluator_class = fitness_evaluator.MultiObjectiveFitnessEvaluator
elif self.args.fitness == 'hybrid':
self.fitness_evaluator_class = fitness_evaluator.HybridFitnessEvaluator

self.num_frames = min(
self.target_sound.get_num_frames(),
Expand Down Expand Up @@ -334,7 +336,7 @@ def run(self):
for individual_id in duplicates:
for ind in duplicates[individual_id]:
ind.set_output_sound(unique_individuals[individual_id].output_sound)
if self.args.fitness == 'mo':
if self.fitness_evaluator_class.IS_FITNESS_RELATIVE:
# Discourage clusters of duplicates
ind.set_fitness(
0.5 * unique_individuals[individual_id].genotype.GetFitness()
Expand Down

0 comments on commit 94021b3

Please sign in to comment.