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
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 | |
__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=None) -> list[Individual[G]]
¶
Sample N random individuals from the archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number to sample |
required |
rng
|
Random number generator |
None
|
Returns:
| Type | Description |
|---|---|
list[Individual[G]]
|
List of sampled individuals |
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.