Archive¶
Quality-diversity archives for storing diverse solutions.
Archive¶
Bases: ABC, Generic[G]
Abstract base class for quality-diversity archives.
Source code in src/rotalabs_redqueen/core/archive.py
add(individual: Individual[G]) -> bool
abstractmethod
¶
Try to add an individual to the archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual[G]
|
Individual to add |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if added (new cell or better than existing) |
get_all() -> list[Individual[G]]
abstractmethod
¶
MapElitesArchive¶
Bases: Archive[G], Generic[G]
MAP-Elites quality-diversity archive.
Maintains a grid of cells in behavior space, keeping the best individual in each cell.
Source code in src/rotalabs_redqueen/core/archive.py
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 | |
__init__(dimensions: list[BehaviorDimension])
¶
Initialize MAP-Elites archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimensions
|
list[BehaviorDimension]
|
Configuration for each behavior dimension |
required |
Source code in src/rotalabs_redqueen/core/archive.py
add(individual: Individual[G]) -> bool
¶
Try to add an individual to the archive.
Adds if: - Cell is empty, or - Individual has higher fitness than current occupant
Source code in src/rotalabs_redqueen/core/archive.py
get(behavior: BehaviorDescriptor) -> Individual[G] | None
¶
Get individual at a behavior location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
behavior
|
BehaviorDescriptor
|
Behavior descriptor |
required |
Returns:
| Type | Description |
|---|---|
Individual[G] | None
|
Individual at that cell or None |
Source code in src/rotalabs_redqueen/core/archive.py
get_all() -> list[Individual[G]]
¶
best() -> Individual[G] | None
¶
coverage() -> ArchiveCoverage
¶
Get archive coverage statistics.
sample_random(n: int, rng: Rng | None = None) -> list[Individual[G]]
¶
Sample N random individuals from the archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number to sample |
required |
rng
|
Rng | None
|
Random number generator |
None
|
Returns:
| Type | Description |
|---|---|
list[Individual[G]]
|
List of sampled individuals |
Source code in src/rotalabs_redqueen/core/archive.py
seed(n: int, rng: Rng | None = None) -> list[G]
¶
Sample N genomes from current elites to warm-start a new run.
Empty archive -> empty list (redqueen-spec interfaces.md §5).
Source code in src/rotalabs_redqueen/core/archive.py
to_dict() -> dict
¶
Serialize to the Archive wire schema (redqueen-spec types.md).
Source code in src/rotalabs_redqueen/core/archive.py
save(uri: str) -> None
¶
Persist the archive to a file:// path (or a plain path).
load(uri: str, genome_class: type[G]) -> MapElitesArchive[G]
classmethod
¶
Load an archive written by :meth:save; genome_class rebuilds elites.
Source code in src/rotalabs_redqueen/core/archive.py
BehaviorDimension¶
Configuration for one dimension of the behavior space.
Source code in src/rotalabs_redqueen/core/archive.py
get_bin(value: float) -> int
¶
Map a value to a bin index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Value in this dimension |
required |
Returns:
| Type | Description |
|---|---|
int
|
Bin index (0 to bins-1) |
Source code in src/rotalabs_redqueen/core/archive.py
ArchiveCoverage¶
Statistics about archive coverage.
Source code in src/rotalabs_redqueen/core/archive.py
coverage_percent: float
property
¶
Percentage of cells filled.