QDpy
Loading...
Searching...
No Matches
qdpy.containers.base.Container Class Reference
Inheritance diagram for qdpy.containers.base.Container:
qdpy.containers.base.ContainerLike qdpy.base.Summarisable qdpy.base.Copyable qdpy.base.CreatableFromConfig qdpy.algorithms.aurora_xcon._AuroraRepertoire qdpy.containers.archives.NoveltyArchive qdpy.containers.grids.Grid qdpy.containers.pareto.LocalParetoArchive qdpy.containers.populations.Population qdpy.containers.voronoi.VoronoiArchive qdpy.containers.archives.SelfAdaptiveNoveltyArchive qdpy.containers.grids.AutoScalingGrid qdpy.containers.grids.CVTGrid qdpy.containers.pareto.ParetoGrid qdpy.containers.sliding.SlidingBoundariesGrid qdpy.containers.t_domino.TDominOGrid

Public Member Functions

float capacity (self)
float free (self)
int size (self)
Any best (self)
Optional[FitnessLike] best_fitness (self)
Optional[FeaturesLike] best_features (self)
int nb_discarded (self)
int nb_added (self)
int nb_rejected (self)
int nb_operations (self)
Optional[Sequence[DomainLike]] fitness_extrema (self)
Optional[Sequence[DomainLike]] features_extrema (self)
Sequence[IndividualLike] all_parents_inds (self)
str size_str (self)
bool in_bounds (self, Any val, Any domain)
FeaturesLike get_ind_features (self, IndividualLike individual, *args, **kwargs)
FitnessLike get_ind_fitness (self, IndividualLike individual, *args, **kwargs)
 set_ind_fitness (self, IndividualLike individual, FitnessLike fitness, *args, **kwargs)
Optional[int] add (self, IndividualLike individual, bool raise_if_not_added_to_parents=False)
None discard (self, IndividualLike individual, bool also_from_parents=False)
int update (self, Iterable iterable, bool ignore_exceptions=True, bool issue_warning=False)
None clear (self, bool also_from_parents=False)
None clear_all (self)
 novelty (self, IndividualLike individual, **kwargs)
 novelty_local_competition (self, IndividualLike individual, **kwargs)
Any to_grid (self, Union[ShapeLike, int] shape, int max_items_per_bin=1, Optional[float] capacity=None, **Any kwargs)
float qd_score (self, bool normalized=True)
Public Member Functions inherited from qdpy.base.Summarisable
Mapping[str, Any] __get_summary_state__ (self)
str summary (self, Optional[int] max_depth=None, Optional[int] max_entry_length=250)
Public Member Functions inherited from qdpy.base.CreatableFromConfig
Any from_config (cls, Mapping[str, Any] config, **Any kwargs)

Protected Member Functions

Optional[Sequence[DomainLike]] _float_feature_extrema (self)
Tuple[bool, int] _add_to_collection (self, BackendLike[IndividualLike] collection, IndividualLike individual)
None _check_if_can_be_added (self, IndividualLike individual)
Optional[int] _add_internal (self, IndividualLike individual, bool raise_if_not_added_to_parents, bool only_to_parents, Optional[int] replace_index=None)
 Commit local storage and eviction after required parent admission.
None _add_to_parents (self, IndividualLike individual, bool require_admission)
 Forward a candidate to each immediate parent in order.
 _can_undo_parent_appends (self, individual)
 _add_to_append_only_parents (self, individual)
 Take a short pre-admission record and rebuild a snapshot only after rejection.
 _snapshot_parents (self)
None _discard_by_index (self, IndividualLike individual, Optional[int] idx=None, bool also_from_parents=False)

Detailed Description

Store evaluated candidates subject to capacity and domain bounds.

Each declared objective and descriptor coordinate has a closed
interval. Omit a domain to leave its vector unbounded. An evaluated
candidate needs nonempty fitness without NaN values.

:param iterable: Initial candidates, admitted in order by update.
:param storage_type: Storage implementation or supported storage name.
    The default list compares genomes for duplicates. Use ``"orderedset"``
    for indexed lookup when candidates are hashable and their genomes
    stay unchanged while stored.
:param parents: Archives offered candidates for evaluation history.
:param fitness_domain: One closed interval per objective.
:param features_domain: One closed interval per behaviour descriptor.
:param fitness_score_names: Named scores used as objectives, in order.
:param features_score_names: Named scores used as descriptors, in order.
:param fitness_weights: Comparison weights to apply in this container.
:param capacity: Total local capacity. None allows unbounded storage.
:param name: Display name used by loggers and configuration.
:param only_add_accepted_inds_to_parents: Forward local admissions
    only. Otherwise a rejected local candidate can reach the parents.
:param disable_parents_pickling: Omit parent links from result files
    by default. Set false to keep the immediate links.

The archive stores candidate objects. Mutate a copy during variation,
and serialise archive updates through the controlling process.

Definition at line 212 of file base.py.

Member Function Documentation

◆ _add_internal()

Optional[int] qdpy.containers.base.Container._add_internal ( self,
IndividualLike individual,
bool raise_if_not_added_to_parents,
bool only_to_parents,
Optional[int] replace_index = None )
protected

Commit local storage and eviction after required parent admission.

Parameters
individualCandidate passed by the admission policy.
raise_if_not_added_to_parentsWhether parent errors must propagate.
only_to_parentsForward the candidate without a local insertion.
replace_indexOptional local storage index of the incumbent.
Returns
The reported storage index, or None for a parent-only offer.

Stage a new entry before contacting the parents, then update local counters and evict the incumbent after those calls succeed. Restore the prior local best and remove the staged entry on failure. An equal reevaluation needs its incumbent removed before insertion.

Store a candidate and commit any local eviction after parent admission.

Reimplemented in qdpy.algorithms.aurora_xcon._AuroraRepertoire, qdpy.containers.archives.NoveltyArchive, qdpy.containers.grids.Grid, qdpy.containers.pareto.LocalParetoArchive, qdpy.containers.pareto.ParetoGrid, qdpy.containers.populations.Population, qdpy.containers.sliding.SlidingBoundariesGrid, and qdpy.containers.voronoi.VoronoiArchive.

Definition at line 603 of file base.py.

◆ _add_to_collection()

Tuple[bool,int] qdpy.containers.base.Container._add_to_collection ( self,
BackendLike[IndividualLike] collection,
IndividualLike individual )
protected
Add ``individual`` to ``collection``.
Return a tuple containing (added, index), with ``added`` a bool saying whether ``individual`` was added or not to ``collection``, and ``index`` the index in the ``collection``.
``collection`` can be a MutableSequence or an ordered set implementing Sequence and MutableSet.

Definition at line 494 of file base.py.

◆ _add_to_parents()

None qdpy.containers.base.Container._add_to_parents ( self,
IndividualLike individual,
bool require_admission )
protected

Forward a candidate to each immediate parent in order.

Parameters
individualCandidate to offer.
require_admissionWhether to raise when a parent insertion fails.

Restore built-in archives after a failure in a parent graph with multiple branches. Custom parents can have external effects.

Definition at line 651 of file base.py.

◆ _can_undo_parent_appends()

qdpy.containers.base.Container._can_undo_parent_appends ( self,
individual )
protected
Restrict the short undo record to plain append-only parent storage.

Definition at line 683 of file base.py.

◆ _check_if_can_be_added()

None qdpy.containers.base.Container._check_if_can_be_added ( self,
IndividualLike individual )
protected
Validate the resolved objective and descriptor vectors.

Reject invalid fitness and vectors outside declared coordinate
bounds. This step runs before storage or parent forwarding.

Reimplemented in qdpy.containers.pareto.LocalParetoArchive, qdpy.containers.pareto.ParetoGrid, qdpy.containers.sliding.SlidingBoundariesGrid, qdpy.containers.t_domino.TDominOGrid, and qdpy.containers.voronoi.VoronoiArchive.

Definition at line 568 of file base.py.

◆ _discard_by_index()

None qdpy.containers.base.Container._discard_by_index ( self,
IndividualLike individual,
Optional[int] idx = None,
bool also_from_parents = False )
protected
Remove ``individual`` of the container. If ``also_from_parents`` is True, discard it also from the parents, if they exist. Use the indexes ``idx`` if it is provided.

Definition at line 792 of file base.py.

◆ _float_feature_extrema()

Optional[Sequence[DomainLike]] qdpy.containers.base.Container._float_feature_extrema ( self)
protected
Reduce built-in float descriptors in column order.

Definition at line 425 of file base.py.

◆ _snapshot_parents()

qdpy.containers.base.Container._snapshot_parents ( self)
protected
Copy built-in archive bookkeeping while retaining archive and elite identities.

Definition at line 730 of file base.py.

◆ add()

Optional[int] qdpy.containers.base.Container.add ( self,
IndividualLike individual,
bool raise_if_not_added_to_parents = False )
Validate one candidate and return its local storage index.

An equal entry can return its existing index. Grid and novelty
subclasses can decline a candidate locally and return None.
Pass ``raise_if_not_added_to_parents=True`` to propagate parent
insertion failures and preserve the current local entry. A failure
across built-in parents restores the earlier branch contents.
Custom parents are responsible for their own external side effects.

Reimplemented from qdpy.containers.base.ContainerLike.

Reimplemented in qdpy.containers.grids.AutoScalingGrid.

Definition at line 776 of file base.py.

◆ all_parents_inds()

Sequence[IndividualLike] qdpy.containers.base.Container.all_parents_inds ( self)
Return immediate parent entries in parent order, including repeated entries.

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 453 of file base.py.

◆ best()

Any qdpy.containers.base.Container.best ( self)
Return the best individual. 

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 351 of file base.py.

◆ best_features()

Optional[FeaturesLike] qdpy.containers.base.Container.best_features ( self)
Return the features values of the individual with the best quality, or None. 

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 361 of file base.py.

◆ best_fitness()

Optional[FitnessLike] qdpy.containers.base.Container.best_fitness ( self)
Return the fitness values of the individual with the best quality, or None. 

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 356 of file base.py.

◆ capacity()

float qdpy.containers.base.Container.capacity ( self)
Return the capacity of the container (i.e. maximal number of items/spots/bins/etc). Can be math.inf.

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 336 of file base.py.

◆ clear()

None qdpy.containers.base.Container.clear ( self,
bool also_from_parents = False )
Remove all local entries and refresh the cached best.

With ``also_from_parents=True``, remove matching local entries from
the parents as well. Parent-only entries may remain.

Reimplemented from qdpy.containers.base.ContainerLike.

Reimplemented in qdpy.containers.sliding.SlidingBoundariesGrid, and qdpy.containers.t_domino.TDominOGrid.

Definition at line 865 of file base.py.

◆ clear_all()

None qdpy.containers.base.Container.clear_all ( self)
Clear all individual in the collection, and clear also those individuals in the parent containers.

Definition at line 882 of file base.py.

◆ discard()

None qdpy.containers.base.Container.discard ( self,
IndividualLike individual,
bool also_from_parents = False )
Remove the matching entry if present.

Use ``also_from_parents`` to request removal from parent history
as well. Removing the cached best triggers recomputation from the
remaining entries.

Reimplemented from qdpy.containers.base.ContainerLike.

Reimplemented in qdpy.containers.grids.Grid, and qdpy.containers.sliding.SlidingBoundariesGrid.

Definition at line 817 of file base.py.

◆ features_extrema()

Optional[Sequence[DomainLike]] qdpy.containers.base.Container.features_extrema ( self)
Return the extrema values of the features of the stored individuals.

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 405 of file base.py.

◆ fitness_extrema()

Optional[Sequence[DomainLike]] qdpy.containers.base.Container.fitness_extrema ( self)
Return the extrema values of the fitnesses of the stored individuals.

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 387 of file base.py.

◆ free()

float qdpy.containers.base.Container.free ( self)
Return the number of free spots in the container. Can be math.inf.

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 341 of file base.py.

◆ get_ind_features()

FeaturesLike qdpy.containers.base.Container.get_ind_features ( self,
IndividualLike individual,
* args,
** kwargs )
Resolve the descriptor vector used by this container.

Select configured named scores in descriptor order when names are
supplied. Otherwise use the candidate's feature object.

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 524 of file base.py.

◆ get_ind_fitness()

FitnessLike qdpy.containers.base.Container.get_ind_fitness ( self,
IndividualLike individual,
* args,
** kwargs )
Resolve the fitness used by this container for admission and ranking.

Select named scores in objective order or use the candidate's fitness.
When the container applies different weights, return a weighted copy
so other archives sharing the same candidate keep their own semantics.

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 535 of file base.py.

◆ in_bounds()

bool qdpy.containers.base.Container.in_bounds ( self,
Any val,
Any domain )
Check inclusive bounds. An empty or omitted domain allows any value.

Definition at line 518 of file base.py.

◆ nb_added()

int qdpy.containers.base.Container.nb_added ( self)
Return the number of individuals added into the container since its creation. 

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 371 of file base.py.

◆ nb_discarded()

int qdpy.containers.base.Container.nb_discarded ( self)
Return the number of individuals discarded by the container since its creation. 

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 366 of file base.py.

◆ nb_operations()

int qdpy.containers.base.Container.nb_operations ( self)
Return the number of adds, modifications and discards since the creation of this container. 

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 381 of file base.py.

◆ nb_rejected()

int qdpy.containers.base.Container.nb_rejected ( self)
Return the number of individuals rejected (when added) by the container since its creation. 

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 376 of file base.py.

◆ novelty()

qdpy.containers.base.Container.novelty ( self,
IndividualLike individual,
** kwargs )
Score novelty against immediate parent entries.

The metric uses the candidates' feature attributes. At least one
parent is required.

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 887 of file base.py.

◆ novelty_local_competition()

qdpy.containers.base.Container.novelty_local_competition ( self,
IndividualLike individual,
** kwargs )
Score novelty and local competition against immediate parents.

Metric options such as ``k`` and ``ignore_first`` are forwarded.
At least one parent is required.

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 897 of file base.py.

◆ qd_score()

float qdpy.containers.base.Container.qd_score ( self,
bool normalized = True )
Sum quality over all locally stored individuals.

With normalisation, measure each objective's improvement from the
worst domain endpoint and divide by the interval width. Use the
lower endpoint for maximisation and the upper for minimisation.
A collapsed interval uses a divisor of one. A populated archive
with an infinite fitness bound returns NaN when normalised. An
empty archive with a fitness domain has a score of zero. Use
``normalized=False`` to sum raw values without applying weights.

Reimplemented from qdpy.containers.base.ContainerLike.

Reimplemented in qdpy.containers.grids.Grid.

Definition at line 944 of file base.py.

◆ set_ind_fitness()

qdpy.containers.base.Container.set_ind_fitness ( self,
IndividualLike individual,
FitnessLike fitness,
* args,
** kwargs )
Store the raw fitness in the configured location.

Write named objective scores when configured. Otherwise replace the
candidate's fitness object, applying the container's weights if set.

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 556 of file base.py.

◆ size()

int qdpy.containers.base.Container.size ( self)
Return the size of the container (i.e. number of items, spots, bins, etc).

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 346 of file base.py.

◆ size_str()

str qdpy.containers.base.Container.size_str ( self)
Return a string describing the fullness of the container.

Definition at line 458 of file base.py.

◆ to_grid()

Any qdpy.containers.base.Container.to_grid ( self,
Union[ShapeLike, int] shape,
int max_items_per_bin = 1,
Optional[float] capacity = None,
**Any kwargs )
Re-admit the stored entries to a new descriptor grid.

Reuse declared domains by default. If absent, use the archive's
observed extrema. Supply explicit domains when converting an empty
archive. Named score selection and fitness weights are inherited
unless overridden.

:param shape: Number of cells per descriptor coordinate.
:param max_items_per_bin: Maximum number of local entries in one cell.
:param capacity: Total capacity override. None leaves it unbounded.
:param kwargs: Other Grid options such as domains or storage type.
:returns: A new grid containing the entries it admitted.

Reimplemented from qdpy.containers.base.ContainerLike.

Definition at line 908 of file base.py.

◆ update()

int qdpy.containers.base.Container.update ( self,
Iterable iterable,
bool ignore_exceptions = True,
bool issue_warning = False )
Offer each candidate for insertion and count reported local indexes.

The count can include an existing equal entry. Use the change in
``nb_added`` to count actual insertions. With ``ignore_exceptions=True``,
validation failures can be offered to parents instead. Set
``issue_warning=True`` to report them. Capacity and parent storage
errors can still propagate.

Reimplemented from qdpy.containers.base.ContainerLike.

Reimplemented in qdpy.containers.grids.AutoScalingGrid.

Definition at line 827 of file base.py.


The documentation for this class was generated from the following file: