Elite Archive (CPU)¶
The MAP-Elites survey over tree space. run_archive fills the archive niche by
niche and halts on discovery saturation. EliteArchive holds the elites and
renders coordinates, surfaces, and dataframes.
run_archive
¶
run_archive(r1: HifukuTree, r2: HifukuTree, r3: HifukuTree, alignment, model, start_trees, triangle: AnchorTriangle, taxon_table: TaxonTable, cell: float = ARCHIVE_CELL, origin: float = 0.0, n_iters: int = ARCHIVE_N_ITERS, seed: int = 0, sigma_slide: float = DEFAULT_SIGMA_SLIDE, scale_width: float = DEFAULT_SCALE_WIDTH, batch: int = ARCHIVE_BATCH, converge: bool = True, force_full_run: bool = False, gate_window: int = ARCHIVE_GATE_WINDOW, coverage_eps: float = ARCHIVE_COVERAGE_EPS, precision_eps: float = ARCHIVE_PRECISION_EPS, logl_margin: float | None = ARCHIVE_LOGL_MARGIN, logl_floor: float | None = None) -> ArchiveResult
Run a CPU elite-archive survey for one alignment.
The three anchor trees fix the chart. The archive is seeded with the anchors and the start trees, then the survey iterates: select a random occupied niche, vary its elite, evaluate the offspring fitness and niche, and place it. Fitness is the alignment log-likelihood.
The survey runs in batches of batch variations up to n_iters. When
converge is set, it halts on discovery saturation: the trailing-window
coverage rate (new niches per batch) and precision rate (elite gain per batch
as a fraction of the elite range) both fall below their thresholds. Coverage
is the crisp signal; precision uses a loose threshold because within-niche
refinement never fully stops. force_full_run disables the halt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r1
|
HifukuTree
|
Anchor trees that fix the chart. Used only for CV distances. |
required |
r2
|
HifukuTree
|
Anchor trees that fix the chart. Used only for CV distances. |
required |
r3
|
HifukuTree
|
Anchor trees that fix the chart. Used only for CV distances. |
required |
alignment
|
The alignment surveyed and its substitution model. |
required | |
model
|
The alignment surveyed and its substitution model. |
required | |
start_trees
|
list[HifukuTree]
|
Extra seed trees, typically the anchors for the surveyed gene. |
required |
triangle
|
AnchorTriangle
|
Precomputed anchor geometry, carrying the chart's metric. |
required |
taxon_table
|
TaxonTable
|
Shared namespace. |
required |
cell
|
float
|
Niche side in barycentric units (the grid is unbounded). |
ARCHIVE_CELL
|
origin
|
float
|
Grid origin on both axes. |
0.0
|
n_iters
|
int
|
The survey budget cap in variations. |
ARCHIVE_N_ITERS
|
seed
|
int
|
RNG seed. |
0
|
sigma_slide
|
float
|
Proposal widths for the branch moves. |
DEFAULT_SIGMA_SLIDE
|
scale_width
|
float
|
Proposal widths for the branch moves. |
DEFAULT_SIGMA_SLIDE
|
batch
|
int
|
Variations per convergence batch. |
ARCHIVE_BATCH
|
converge
|
bool
|
Halt on discovery saturation when set. |
True
|
force_full_run
|
bool
|
Run the full budget regardless of the halt. |
False
|
gate_window
|
int
|
Trailing window (batches) for the halt rates. |
ARCHIVE_GATE_WINDOW
|
coverage_eps
|
float
|
Halt thresholds on the windowed coverage and precision rates. |
ARCHIVE_COVERAGE_EPS
|
precision_eps
|
float
|
Halt thresholds on the windowed coverage and precision rates. |
ARCHIVE_COVERAGE_EPS
|
logl_margin
|
float
|
Relative log-likelihood gate: a variation creates a niche only when its
tree is within this many nats of the best tree found. The floor follows
the best. Defaults to |
ARCHIVE_LOGL_MARGIN
|
logl_floor
|
float
|
Absolute log-likelihood gate: a variation creates a niche only when its
tree scores at least this value. Useful for a common domain across
genes. Mutually exclusive with |
None
|
Returns:
| Type | Description |
|---|---|
ArchiveResult
|
The archive, its per-batch history, and the halt state. |
Source code in src/hifuku/archive.py
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 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
EliteArchive
dataclass
¶
A map from niche to elite over an unbounded 2D chart grid.
A niche is a square cell of side cell, indexed by integer coordinates
(i, j) from origin. The grid has no window: any chart point has a
niche. Exploration is bounded by the log-likelihood gate in the survey, not
by the grid, and the filled niches form the map's footprint.
anchors (an AnchorTriangle), taxon_table, and metric hold the
context the archive was built against. The accessors fall back to anchors
when their argument is omitted. :meth:locate uses all three to place a new
tree in the same frame as the map. A later re-anchoring step can use the
anchors to stitch archives on different anchor planes into one frame.
Source code in src/hifuku/archive.py
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 | |
tree_at
¶
Return the elite tree at niche key, parsing its stored newick on
first access. For a live archive the tree is already present; for a
loaded archive it is materialized from tree_source and cached.
Source code in src/hifuku/archive.py
trees
¶
niche_of
¶
Return the (i, j) niche of a chart point. Unbounded: never None.
niche_center
¶
place
¶
Store the elite when its niche is empty or the elite is better.
Source code in src/hifuku/archive.py
index_bounds
¶
(i_min, i_max, j_min, j_max) over filled niches, or None if empty.
Source code in src/hifuku/archive.py
filled_bounds
¶
Chart bounding box (lam1_lo, lam1_hi, lam2_lo, lam2_hi) of the
filled niches, or None if empty.
Source code in src/hifuku/archive.py
elevation_grid
¶
Elite log-likelihood over the filled bounding box, a masked array.
Source code in src/hifuku/archive.py
points
¶
Scattered elite points as (x, y, logL, z) arrays.
coords="barycentric" returns the niche centers (lam1, lam2);
coords="cartesian" maps them through the anchor triangle into the
Euclidean CBS plane. anchors defaults to the archive's stored
anchors; a cartesian request with neither is an error.
Source code in src/hifuku/archive.py
records
¶
Scattered elevation records as an (N, 3) array.
Each row is one elite (coord1, coord2, logL), in barycentric
(lam1, lam2, logL) or Cartesian (x, y, logL) coordinates per
coords. Unlike :meth:surface, this does no interpolation; it hands
the raw scattered records to a plotting utility that triangulates them,
for example ax.tricontourf(*archive.records(coords="cartesian",
anchors=tri).T).
Source code in src/hifuku/archive.py
locate
¶
Return the chart coordinates of a tree as (x, y, z).
This method places tree in the same frame as the map. It uses the
archive's own anchors, taxon table, and metric. A feature tree, such as
the maximum-likelihood tree or a ufboot replicate, lands where it belongs
on the map. coords is "barycentric" or "cartesian". z is the
out-of-plane residual.
Source code in src/hifuku/archive.py
frame
¶
Tidy dataframe of the elites (niche indices, coordinates, logL, z).
Includes Cartesian x, y columns when anchors is given or the
archive has stored anchors.
Source code in src/hifuku/archive.py
surface
¶
Interpolated elevation surface as (X, Y, Z) meshgrids.
Shepard-interpolates the elite log-likelihoods over a regular n by
n grid spanning the filled region, in barycentric or Cartesian
coordinates. Z is masked beyond the support radius. The result is a
plain gridded field: it drops into ax.contourf(X, Y, Z),
ax.pcolormesh(X, Y, Z), ax.plot_surface(X, Y, Z), and the like.
Source code in src/hifuku/archive.py
locate_tree
¶
Return the chart coordinates of a tree as (x, y, z).
This function aligns the leaves of the tree to taxon_table. It measures
the distance from the tree to each anchor of triangle with the chart's
own metric, then solves for the chart position.
coords="barycentric" returns (lambda1, lambda2, z).
coords="cartesian" returns the point in the Euclidean metric plane.
z is the out-of-plane residual. It measures how far the tree sits off
the anchor plane.
triangle provides the anchor trees, their embedded geometry, and the
metric. The chart owns its metric so a tree cannot be placed under a metric
inconsistent with the chart it lands on.