Bases: GeneticAlgorithm
Implements main functions of the NSGA2 algorithm.
This class inherits most functions from GeneticAlgorithm.
The init function is overwritten in order to precise the type
of repertoire used in NSGA2.
Link to paper: https://ieeexplore.ieee.org/document/996017
Source code in qdax/baselines/nsga2.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 | class NSGA2(GeneticAlgorithm):
"""Implements main functions of the NSGA2 algorithm.
This class inherits most functions from GeneticAlgorithm.
The init function is overwritten in order to precise the type
of repertoire used in NSGA2.
Link to paper: https://ieeexplore.ieee.org/document/996017
"""
def init(
self, genotypes: Genotype, population_size: int, key: RNGKey
) -> Tuple[NSGA2Repertoire, Optional[EmitterState], Metrics]:
# score initial genotypes
key, subkey = jax.random.split(key)
fitnesses, extra_scores = self._scoring_function(genotypes, subkey)
# init the repertoire
repertoire = NSGA2Repertoire.init(
genotypes=genotypes,
fitnesses=fitnesses,
population_size=population_size,
)
# get initial state of the emitter
key, subkey = jax.random.split(key)
emitter_state = self._emitter.init(
key=subkey,
repertoire=repertoire,
genotypes=genotypes,
fitnesses=fitnesses,
descriptors=None,
extra_scores=extra_scores,
)
# update emitter state
emitter_state = self._emitter.state_update(
emitter_state=emitter_state,
repertoire=repertoire,
genotypes=genotypes,
fitnesses=fitnesses,
extra_scores=extra_scores,
)
# calculate the initial metrics
metrics = self._metrics_function(repertoire)
return repertoire, emitter_state, metrics
|