Records¶
deap_er.records
¶
ArchiveStats(num_elites, num_cells, coverage, qd_score)
dataclass
¶
Summary statistics for a MAP-Elites archive.
Attributes:
| Name | Type | Description |
|---|---|---|
num_elites |
int
|
Number of stored elites. |
num_cells |
int
|
Capacity of the tessellation, or the current elite count when the archive has no fixed cell budget. |
coverage |
float
|
|
qd_score |
float
|
Sum of the first weighted objective over elites. Requires single-objective fitness on every stored elite. |
CaseExam(ranges=None, mask=None, *, length=None)
¶
A case subset stored as ranges or a 1-D bool mask.
This is data, not a genome. The same shapes feed case_errors
(series segments) and sel_lexicase(..., cases=) (catalog indices
via :meth:as_cases).
Store exactly one of ranges or mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ranges
|
CaseRanges | None
|
Half-open |
None
|
mask
|
ndarray | None
|
One-dimensional |
None
|
length
|
int | None
|
Optional series span. When set and different from
the fitness-case count, :meth: |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If both or neither form is given, or |
Source code in deap_er/private/records/case_exam.py
ranges
property
¶
Live range list, or None when the exam stores a mask.
mask
property
¶
Live boolean mask, or None when the exam stores ranges.
length
property
¶
Optional series span, or None when unset.
from_cases(cases, n_cases)
classmethod
¶
Build a catalog-index exam from selected case indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cases
|
Sequence[int]
|
Fitness-case indices to mark |
required |
n_cases
|
int
|
Length of the catalog mask. |
required |
Returns:
| Type | Description |
|---|---|
CaseExam
|
An exam whose mask has length |
Raises:
| Type | Description |
|---|---|
IndexError
|
If an index is not a valid case index. |
ValueError
|
If |
Source code in deap_er/private/records/case_exam.py
as_ranges(length)
¶
Return validated [start, stop) intervals against length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
Exclusive upper bound for endpoints, or the mask length. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[int, int]]
|
Half-open intervals in stored order. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If stored bounds or the mask do not match |
Source code in deap_er/private/records/case_exam.py
as_mask(length)
¶
Return a boolean mask of length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
Length of the painted mask, or the stored mask length. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
A 1-D |
Raises:
| Type | Description |
|---|---|
ValueError
|
If stored bounds or the mask do not match |
Source code in deap_er/private/records/case_exam.py
as_cases(n_cases)
¶
Interpret the exam as catalog indices or series segments.
A stored mask must have length n_cases. Catalog ranges
(every stop <= n_cases) expand to those indices. Series
ranges — any stop > n_cases, or an explicit length
different from n_cases — return 0 .. n_segments-1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_cases
|
int
|
Number of fitness cases in the current pack. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
Distinct case or segment indices in first-occurrence order. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If stored catalog bounds or the mask do not
match |
Source code in deap_er/private/records/case_exam.py
mutation_bound(n_cases)
¶
Exclusive endpoint bound for range mutation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_cases
|
int
|
Fitness-case count from the current pack. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The series span when this exam is a series, otherwise |
int
|
|
Source code in deap_er/private/records/case_exam.py
copy()
¶
Return a copy of the stored ranges or mask.
Returns:
| Type | Description |
|---|---|
CaseExam
|
A new exam with the same subset. |
Source code in deap_er/private/records/case_exam.py
assign(other)
¶
Replace this exam's storage with a copy of other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
CaseExam
|
Exam whose ranges or mask become this exam's data. |
required |
Source code in deap_er/private/records/case_exam.py
CaseExamPool(exams, *, held_out=None, min_cases=1)
¶
Cheap second population of :class:CaseExam subsets.
Stores exams and an optional caller-marked held-out exam. Scoring, mutation, and lexicase feed stay on the operators.
Create a pool of exams.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exams
|
Sequence[CaseExam]
|
Initial case subsets. |
required |
held_out
|
CaseExam | None
|
Optional exam injected on empty or all-solved collapse. |
None
|
min_cases
|
int
|
Minimum catalog size after a guard repair. |
1
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/records/case_exam_pool.py
CvtArchive(centroids)
¶
MAP-Elites archive that assigns descriptors to CVT centroids.
Each individual is stored in the Voronoi cell of the nearest
centroid. Fitness stays on ind.fitness; the caller supplies
the behavior descriptor. fitness must be single-objective.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
centroids
|
Sequence[Sequence[float]] | ndarray
|
|
required |
See the class docstring.
Source code in deap_er/private/records/cvt_archive.py
centroids
property
¶
Copy of the (k, dims) centroid array.
dimensions
property
¶
Number of behavior dimensions.
stats
property
¶
Coverage and quality-diversity score of the archive.
num_cells is the number of centroids. qd_score is the
sum of fitness.wvalues[0] over elites.
from_samples(samples, k, *, n_iter=20)
classmethod
¶
Build an archive from k-means centroids of samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples
|
Sequence[Sequence[float]] | ndarray
|
Behavior descriptors with shape |
required |
k
|
int
|
Number of centroids. |
required |
n_iter
|
int
|
Independent k-means runs passed to
:func: |
20
|
Returns:
| Type | Description |
|---|---|
CvtArchive
|
An empty archive whose cells are the computed centroids. |
Source code in deap_er/private/records/cvt_archive.py
nearest_centroid(descriptor)
¶
Return the index of the centroid nearest to descriptor.
Archives with fewer than 512 centroids break ties by
lowest index. Larger archives follow
scipy.spatial.KDTree.query order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
descriptor
|
Sequence[float]
|
Continuous behavior coordinates. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Centroid index in |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/records/cvt_archive.py
add(individual, descriptor)
¶
Insert individual when it improves its Voronoi cell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Any
|
Candidate with a valid fitness attribute. |
required |
descriptor
|
Sequence[float] | ndarray
|
Continuous behavior coordinates. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when the archive stores |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/records/cvt_archive.py
elite_at(descriptor)
¶
Return the elite in the cell for descriptor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
descriptor
|
Sequence[float]
|
Continuous behavior coordinates. |
required |
Returns:
| Type | Description |
|---|---|
Individual | None
|
The stored elite, or None when the cell is empty or |
Individual | None
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/records/cvt_archive.py
get(index)
¶
Return the elite stored at centroid index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Centroid index in |
required |
Returns:
| Type | Description |
|---|---|
Individual | None
|
The stored elite, or None when the cell is empty. |
Source code in deap_er/private/records/cvt_archive.py
random_elites(n, *, replace=True)
¶
Sample elites uniformly from filled cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of elites to return. |
required |
replace
|
bool
|
Sample with replacement when True. |
True
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
Stored elites from distinct or repeated cells. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If the archive is empty. |
ValueError
|
If |
Source code in deap_er/private/records/cvt_archive.py
clear()
¶
__len__()
¶
__contains__(index)
¶
GridArchive(ranges, bins, key=None)
¶
MAP-Elites grid archive indexed by a behavior descriptor.
The caller supplies a continuous behavior descriptor for each
individual. The archive bins descriptors into a uniform grid and
keeps the best individual per cell according to fitness.
Without key, fitness must be single-objective (one
weight). Multi-objective fitness types are rejected by :meth:add.
stats.qd_score sums the first weighted objective
(:attr:~deap_er.base.Fitness.wvalues element zero) across filled
cells. With key, any number of objectives is accepted, the cell
elite is the one with the largest key value, and qd_score
sums key over the elites.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ranges
|
Sequence[tuple[float, float]]
|
|
required |
bins
|
Sequence[int] | int
|
Resolution per dimension, or one integer for every dimension. |
required |
key
|
Callable[[Any], float] | None
|
Optional scalariser mapping an individual to a float where
larger is better (negate a cost to minimise it). A
candidate replaces the cell elite only when its key value is
strictly larger; candidates with a non-finite key value are
not stored. The individual still needs a comparable fitness.
Defaults to None. A lambda key needs dill (as used by
|
None
|
See the class docstring.
Source code in deap_er/private/records/grid_archive.py
dimensions
property
¶
Number of behavior dimensions.
bins
property
¶
Resolution of the grid along each behavior dimension.
ranges
property
¶
(low, high) bounds per behavior dimension.
stats
property
¶
Coverage and quality-diversity score of the archive.
qd_score is the sum of fitness.wvalues[0] over elites,
or of key when one is set. It is a MAP-Elites-style scalar
quality total, not a sum across multiple objectives.
descriptor_to_index(descriptor)
¶
Map a behavior descriptor to its grid cell.
Coordinates outside ranges are clipped before binning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
descriptor
|
Sequence[float]
|
Continuous behavior coordinates. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, ...]
|
Integer grid index per dimension. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/records/grid_archive.py
index_to_descriptor_center(index)
¶
Return the center of a grid cell in behavior space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
tuple[int, ...]
|
Integer grid index per dimension. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, ...]
|
Center coordinate per behavior dimension. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/records/grid_archive.py
add(individual, descriptor)
¶
Insert individual when it improves its behavior cell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Any
|
Candidate with a valid fitness attribute. |
required |
descriptor
|
Sequence[float]
|
Continuous behavior coordinates. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when the archive stores |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/records/grid_archive.py
elite_at(descriptor)
¶
Return the elite in the cell for descriptor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
descriptor
|
Sequence[float]
|
Continuous behavior coordinates. |
required |
Returns:
| Type | Description |
|---|---|
Individual | None
|
The stored elite, or None when the cell is empty or |
Individual | None
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/records/grid_archive.py
get(index)
¶
Return the elite stored at index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
tuple[int, ...]
|
Integer grid index per dimension. |
required |
Returns:
| Type | Description |
|---|---|
Individual | None
|
The stored elite, or None when the cell is empty. |
Source code in deap_er/private/records/grid_archive.py
random_elites(n, *, replace=True)
¶
Sample elites uniformly from filled cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of elites to return. |
required |
replace
|
bool
|
Sample with replacement when True. |
True
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
Stored elites from distinct or repeated cells. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If the archive is empty. |
ValueError
|
If |
Source code in deap_er/private/records/grid_archive.py
clear()
¶
__len__()
¶
__contains__(index)
¶
HallOfFame(maxsize, similar=eq, key=None)
¶
Bases: BaseRecordStorage
Archive of the best individuals seen during evolution.
Members stay sorted by fitness so the first item is the best
individual seen so far, according to the fitness weights. With
key, members are ranked by key(individual) instead, which
lets a multi-objective individual be ranked by one scalar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
maxsize
|
int
|
Maximum number of individuals to keep. |
required |
similar
|
Callable[..., Any]
|
Equality test used to skip duplicates. Defaults to
|
eq
|
key
|
Callable[[Any], float] | None
|
Optional scalariser mapping an individual to a float where
larger is better (negate a cost to minimise it). The
individual still needs a comparable fitness; individuals
whose key value is non-finite are ignored. Defaults to
None, which ranks by the fitness weights. A lambda key needs
dill (as used by |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
See the class docstring.
Source code in deap_er/private/records/hall_of_fame.py
update(population)
¶
Update the archive from population.
Better individuals replace the worst members. The archive stays
at most maxsize and skips individuals already present
according to similar. Individuals without a comparable
fitness (missing, invalid, or non-finite) are ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
population
|
Sequence[Any]
|
Individuals that may have a fitness attribute. |
required |
Source code in deap_er/private/records/hall_of_fame.py
to_json()
¶
from_json(text, ind_cls=None, key=None)
classmethod
¶
Rebuild a hall of fame from :meth:to_json output.
key is not serialized; pass it again to restore a keyed
archive.
Source code in deap_er/private/records/hall_of_fame.py
History()
¶
Genealogy of individuals produced during evolution.
Call update on the initial population and after each variation,
or wrap variation operators with decorator.
Create an empty genealogy.
Source code in deap_er/private/records/history.py
decorator
property
¶
Decorator that records a variation operator's returned individuals.
update(individuals)
¶
Record individuals in the genealogy.
Call this on the initial population and after each variation.
Individuals that already have history_index become the
parents of the newly recorded entries; otherwise the entries
are roots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
Individuals to add to the genealogy. |
required |
Source code in deap_er/private/records/history.py
get_genealogy(individual, max_depth=float('inf'))
¶
Return the ancestor graph of an individual.
The individual must have a history_index set by update.
The graph includes parents up to max_depth variation steps.
The default max_depth walks back to the start of the
evolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
Individual at the root of the genealogy tree. |
required |
max_depth
|
float
|
Maximum number of variation steps to walk. |
float('inf')
|
Returns:
| Type | Description |
|---|---|
dict[int, Any]
|
Mapping of individual index to a tuple of parent indices. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the individual has no |
Source code in deap_er/private/records/history.py
Logbook()
¶
Bases: LogbookRows
Chronological evolution records as a list of dictionaries.
Retrieve columns with select. Nested dictionaries passed to
record become named chapters. Set header to control column
order when printing.
Create an empty logbook.
Source code in deap_er/private/records/logbook.py
stream
property
¶
Formatted text of entries recorded since the last stream read.
record(**data)
¶
Append one chronological entry.
Nested dict values are recorded into named chapters. Remaining keys form the entry on this logbook. Non-dict keys are also copied into each chapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**data
|
Any
|
Fields for the new entry. Dict values become chapters. |
{}
|
Source code in deap_er/private/records/logbook.py
select(*names)
¶
Return recorded values for one or more field names.
A missing name yields None in that column. One name
returns a flat list; several names return a list of lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*names
|
str
|
Field names to retrieve. |
()
|
Returns:
| Type | Description |
|---|---|
list[Any]
|
Values for the requested names, in chronological order. |
Source code in deap_er/private/records/logbook.py
__txt__(start_index)
¶
Format rows from start_index as aligned column strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_index
|
int
|
First entry to include. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
One formatted line per row, including a header when |
list[str]
|
|
Source code in deap_er/private/records/logbook.py
__str__()
¶
to_json()
¶
Serialize entries, chapters, and the header to JSON.
NumPy scalars become Python numbers. Other non-JSON values become strings.
Returns:
| Type | Description |
|---|---|
str
|
A JSON document. |
Source code in deap_er/private/records/logbook.py
from_json(text)
classmethod
¶
Rebuild a logbook from :meth:to_json output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
JSON document produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
Logbook
|
A logbook with restored entries, chapters, and header. |
Source code in deap_er/private/records/logbook.py
ParetoFront(similar=eq)
¶
Bases: BaseRecordStorage
Archive of every non-dominated individual seen during evolution.
The front is unbounded: every unique non-dominated individual is kept.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
similar
|
Callable[..., Any]
|
Equality test used to skip duplicates. Defaults to
|
eq
|
See the class docstring.
Source code in deap_er/private/records/pareto_front.py
update(population)
¶
Add non-dominated individuals from population.
Members dominated by a new individual are removed. Similar individuals with equal fitness are not added again. Individuals without a comparable fitness (missing, invalid, or non-finite) are ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
population
|
Sequence[Any]
|
Individuals that may have a fitness attribute. |
required |
Source code in deap_er/private/records/pareto_front.py
PolicyObservation(solve_bits, unsolved_count, train_score, held_out_score, archive_coverage, qd_score, nevals, rows_seen, promoted_library_size, fitness_invalid, last_action_rejected)
dataclass
¶
Fixed Push policy observation record.
This is not a genome and not a domain metric. It is the only
typed layout a private policy may read: summaries from case
errors, exams, archives, promoted-library size, and eval budget
counters. Raw column packs and matrix[t] never appear here.
Attributes:
| Name | Type | Description |
|---|---|---|
solve_bits |
tuple[int, ...]
|
Per-case |
unsolved_count |
int
|
Number of cases in |
train_score |
float
|
Sum of train-exam difficulty scores from
:func: |
held_out_score |
float | None
|
Held-out exam difficulty, or |
archive_coverage |
float
|
MAP-Elites coverage from
:class: |
qd_score |
float
|
MAP-Elites quality-diversity total from
:class: |
nevals |
int
|
Evaluations consumed this generation or step. |
rows_seen |
int
|
Rows in the evaluation matrix seen so far. |
promoted_library_size |
int
|
Count of promoted primitive names. |
fitness_invalid |
bool
|
|
last_action_rejected |
bool
|
|
as_tuple()
¶
Return fields in fixed schema order for Push or linear policies.
Source code in deap_er/private/records/policy_observation.py
SemanticSurrogate(*, metric='euclidean')
¶
Last-generation semantic store for nearest and linear lookup.
update replaces the stored pack and scalar targets. It does not
write ind.fitness. predict is a stand-in for last-generation
semantics, not a learned quality-diversity model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
SemanticMetric
|
Default finite-mask distance for nearest lookup. |
'euclidean'
|
See the class docstring.
Source code in deap_er/private/records/semantic_surrogate.py
metric
property
¶
Default nearest-neighbor metric.
update(matrix, values, *, valid=None, individuals=None, trust_matrix=False)
¶
Replace the stored last-generation pack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
ndarray | Sequence[Sequence[float]]
|
Semantic pack of shape |
required |
values
|
ndarray | Sequence[float]
|
Scalar target per row, typically |
required |
valid
|
ndarray | None
|
Optional per-row warmup mask stored with the pack. |
None
|
individuals
|
Sequence[Any] | None
|
Optional population used by |
None
|
trust_matrix
|
bool
|
When |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/records/semantic_surrogate.py
nearest(query, k=1, *, metric=None, valid=None)
¶
Return stored-row indices nearest to query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
ndarray | Sequence[float]
|
Semantic row of length |
required |
k
|
int
|
Maximum number of neighbors to return. |
1
|
metric
|
SemanticMetric | None
|
Distance used for this call. Defaults to the constructor metric. |
None
|
valid
|
ndarray | None
|
Warmup mask. Defaults to the mask from |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Neighbor indices in increasing distance order. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the store is empty. |
Source code in deap_er/private/records/semantic_surrogate.py
predict(query, *, kind='nearest', k=1, metric=None, valid=None)
¶
Predict a scalar from last-generation semantics.
nearest returns the stored value of the nearest row, or the
mean of k neighbors, among rows whose stored value is
finite. linear fits least squares on finite stored rows.
Fallback to nearest happens only when the design is empty or
rank < 1, not when rank < min(shape).
Underdetermined packs (more columns than rows) keep the
minimum-norm solution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
ndarray | Sequence[float]
|
Semantic row of length |
required |
kind
|
SurrogateKind
|
|
'nearest'
|
k
|
int
|
Neighbor count for |
1
|
metric
|
SemanticMetric | None
|
Distance used for nearest lookup. |
None
|
valid
|
ndarray | None
|
Warmup mask. Defaults to the mask from |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Predicted scalar, or |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the store is empty or |
Source code in deap_er/private/records/semantic_surrogate.py
MultiStatistics
¶
Bases: dict[str, Any]
Compile several named Statistics objects in one call.
Construct with keyword arguments that map a chapter name to a
Statistics instance, for example
MultiStatistics(fitness=stats_fit, size=stats_size).
register forwards the same function to every chapter unless
chapters names a subset.
fields
property
¶
Sorted names of the contained Statistics objects.
register(name, func, *args, chapters=None, **kwargs)
¶
Register func on contained Statistics objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Key used for this statistic in each chapter record. |
required |
func
|
Callable[..., Any]
|
Function applied to each chapter's key values. |
required |
*args
|
Any
|
Positional arguments bound into |
()
|
chapters
|
str | Iterable[str] | None
|
Chapter name or names to update. |
None
|
**kwargs
|
Any
|
Keyword arguments bound into |
{}
|
Source code in deap_er/private/records/statistics.py
compile(data)
¶
Compile every contained Statistics object on data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Iterable[Any]
|
Iterable of elements passed to each chapter. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Mapping of chapter name to that chapter's compiled record. |
Source code in deap_er/private/records/statistics.py
Statistics(key=None)
¶
Compile named statistics on a sequence of objects.
key selects the value scored on each element. The default key
is the identity function. The key may return a sequence when the
registered functions accept one, for example a multi-objective
fitness passed to a NumPy statistic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Callable[..., Any] | None
|
Extracts the value to score from each element. Defaults to the identity function. |
None
|
See the class docstring.
Source code in deap_er/private/records/statistics.py
register(name, func, *args, **kwargs)
¶
Register a statistic computed by compile.
Extra positional and keyword arguments are bound into func.
Registering an existing name again replaces its function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Key used for this statistic in the compiled record. |
required |
func
|
Callable[..., Any]
|
Function applied to the sequence of key values. |
required |
*args
|
Any
|
Positional arguments bound into |
()
|
**kwargs
|
Any
|
Keyword arguments bound into |
{}
|
Source code in deap_er/private/records/statistics.py
compile(data)
¶
Compute every registered statistic on data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Iterable[Any]
|
Iterable of elements passed through |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Mapping of registered names to computed values. |
Source code in deap_er/private/records/statistics.py
UnstructuredArchive(dimensions, min_distance, *, max_elites=None)
¶
MAP-Elites archive that keeps elites by descriptor distance.
A candidate is added when it is at least min_distance from
every stored elite and the archive is under capacity. Otherwise it
replaces the nearest neighbor if it is strictly fitter. Scale
descriptor axes yourself when units differ (for example turnover
versus win rate).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimensions
|
int
|
Length of each behavior descriptor. |
required |
min_distance
|
float
|
Euclidean threshold that opens a new niche. |
required |
max_elites
|
int | None
|
Optional cap. When full, a far candidate competes with the nearest elite instead of growing the archive. |
None
|
See the class docstring.
Source code in deap_er/private/records/unstructured_archive.py
dimensions
property
¶
Number of behavior dimensions.
min_distance
property
¶
Euclidean threshold that opens a new niche.
max_elites
property
¶
Elite cap, or None when the archive may grow without bound.
descriptors
property
¶
Copy of stored descriptors with shape (n, dimensions).
stats
property
¶
Coverage and quality-diversity score of the archive.
num_cells is max_elites when a cap is set, otherwise
the current elite count (so uncapped coverage is 1.0 when the
archive is non-empty). qd_score is the sum of
fitness.wvalues[0] over elites.
add(individual, descriptor)
¶
Insert individual when it opens a niche or beats a neighbor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Any
|
Candidate with a valid fitness attribute. |
required |
descriptor
|
Sequence[float] | ndarray
|
Continuous behavior coordinates. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when the archive stores |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/records/unstructured_archive.py
elite_at(descriptor)
¶
Return the nearest stored elite to descriptor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
descriptor
|
Sequence[float]
|
Continuous behavior coordinates. |
required |
Returns:
| Type | Description |
|---|---|
Individual | None
|
The nearest elite, or None when the archive is empty or |
Individual | None
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/records/unstructured_archive.py
random_elites(n, *, replace=True)
¶
Sample elites uniformly from stored members.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of elites to return. |
required |
replace
|
bool
|
Sample with replacement when True. |
True
|
Returns:
| Type | Description |
|---|---|
list[Individual]
|
Stored elites from distinct or repeated members. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If the archive is empty. |
ValueError
|
If |
Source code in deap_er/private/records/unstructured_archive.py
clear()
¶
__len__()
¶
coerce_case_exam(exam, n_cases=None)
¶
Wrap ranges, a mask, or catalog indices as a :class:CaseExam.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exam
|
CaseExam | CaseRanges | Sequence[int]
|
An exam, a range table, a 1-D |
required |
n_cases
|
int | None
|
Required when |
None
|
Returns:
| Type | Description |
|---|---|
CaseExam
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If case indices are given without |
Source code in deap_er/private/records/case_exam_pool.py
cvt_centroids(samples, k, *, n_iter=20)
¶
Compute k centroids by k-means on a behavior sample.
Seeding uses the process-wide tools.rng generator so
checkpointed runs stay reproducible. Callers who already have
centroids can pass them straight to
:class:~deap_er.records.CvtArchive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples
|
Sequence[Sequence[float]] | ndarray
|
Behavior descriptors with shape |
required |
k
|
int
|
Number of centroids. Must be at least 1 and at most |
required |
n_iter
|
int
|
Independent k-means runs; the lowest-distortion result is kept. |
20
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Contiguous |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deap_er/private/records/cvt_centroids.py
policy_generalization_gap(train_score, held_out_score)
¶
Build the generalization-gap Logbook chapter payload.
Train-exam quality is logged for comparison only. Policy fitness
stays on held_out_score via
:func:~deap_er.tools.policy_held_out_fitness.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_score
|
float
|
Sum of train-exam difficulties from
:func: |
required |
held_out_score
|
float | None
|
Held-out exam difficulty, or |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float | None]
|
Chapter fields |
dict[str, float | None]
|
|
Source code in deap_er/private/records/policy_generalization.py
record_policy_generalization_gap(logbook, *, gen, train_score, held_out_score, **extra)
¶
Append one generation row with a generalization-gap chapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logbook
|
Logbook
|
Evolution logbook to update. |
required |
gen
|
int
|
Generation index shared with the parent row. |
required |
train_score
|
float
|
Train-exam difficulty sum for observation. |
required |
held_out_score
|
float | None
|
Held-out difficulty used for policy fitness. |
required |
**extra
|
Any
|
Additional parent-row fields such as |
{}
|