@File : map_elites.py @Time : 2026/03/25 12:21:11 @Author : Alejandro Marrero (amarrerd@ull.edu.es) @Version : 1.0 @Contact : amarrerd@ull.edu.es @License : (C)Copyright 2026, Alejandro Marrero @Desc : None
MapElites
Bases: BaseGenerator
Quality-Diversity instance generator based on the MAP-Elites algorithm.
MAP-Elites maintains a discretised archive (either a GridArchive or a
CVTArchive) where each occupied cell holds the single best instance
found so far for that region of descriptor space. At every generation, a
batch of parents is sampled uniformly from the currently filled cells,
mutated to produce offspring, evaluated against the solver portfolio, and
inserted back into the archive — each offspring either claims an empty
cell, replaces the current occupant of its cell if it scores higher, or
is discarded if it does not improve on the existing elite.
Unlike :class:Evolutionary, fitness in MAP-Elites is simply the
performance bias of the instance (there is no separate novelty term),
since diversity is enforced structurally by the archive's discretisation
rather than by a blended fitness score.
Source code in digneapy/generators/map_elites.py
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
archive
property
Return the archive backing this generator.
| Returns: |
|
|---|
__call__(verbose=False)
Run the full MAP-Elites process and return the generated instances.
The algorithm proceeds as follows:
1. The archive is seeded with an initial batch of instances via
:meth:_initialise_grid (recorded as generation 0).
2. For each of the self._generations subsequent generations,
:meth:_run_generation samples parents from the filled archive
cells, mutates them, evaluates the offspring, and updates the
archive in place.
3. After all generations, any infeasible instances that slipped into
the archive during initialisation or evolution are removed via
self._archive.purge_unfeasible().
4. The final archive contents are packaged into a
:class:GenerationResult together with the solver names and the
recorded evolutionary history.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in digneapy/generators/map_elites.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
__init__(domain, portfolio, pop_size, archive, mutation=BatchUMut(seed=None), repetitions=np.uint16(1), descriptor_pipe=DescriptorPipeline('features'), performance_function=maximise_perf_gap_easy, generations=np.uint32(1000), seed=None)
Creates a MAP-Elites instance generator. The generator uses a set of solvers to evaluate the instances and MAP-Elites to guide the evolution of the instances.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Note
Despite the docstring above, the actual implementation raises a
TypeError (not a ValueError) when archive is not a
GridArchive or CVTArchive instance.
Source code in digneapy/generators/map_elites.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
PlottedMapElites
Wraps a MapElites generator and injects live plotting after each generation.
It replaces the generator's internal loop with an equivalent one that calls
plotter.update() every refresh_every generations. Because it accesses
the generator's internals (all prefixed _), pin your digneapy version.
This class does not subclass BaseGenerator: it is a thin orchestration
wrapper that drives an already-constructed (but not yet called)
MapElites instance through the same initialisation and generation
steps it would normally run on its own, interleaving calls to an
ArchivePlotter so that progress can be visualised as a live heatmap
while the search is running.
| Parameters: |
|
|---|
Source code in digneapy/generators/map_elites.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
__call__(verbose=False)
Runs the full MAP-Elites loop and shows the live heatmap.
Mirrors the generation sequence performed by MapElites.__call__
(initial grid seeding followed by the configured number of
generations), but additionally creates an ArchivePlotter bound to
the wrapped generator's archive and refreshes it: once immediately
after initialisation, every refresh_every generations during the
loop, and once more after the final generation. After the loop
completes, infeasible instances are purged from the archive (as in
the plain MapElites), the final frame is optionally saved to
save_final, and the plot window is shown interactively.
Returns the same GenResult the underlying generator would return.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in digneapy/generators/map_elites.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
__init__(generator, feat_names=None, attr='p', cmap='viridis', vmin=None, vmax=None, refresh_every=1, save_final=None)
Store the wrapped generator and the plotting configuration.
No plotting or generation work happens here; everything is deferred
to :meth:__call__. refresh_every is clamped to a minimum of 1
to avoid division/modulo issues during the generation loop.
| Parameters: |
|
|---|
Source code in digneapy/generators/map_elites.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |