QDpy
Loading...
Searching...
No Matches
qdpy.containers.grids.Grid Class Reference
Inheritance diagram for qdpy.containers.grids.Grid:
qdpy.containers.base.Container qdpy.containers.base.ContainerLike qdpy.base.Summarisable qdpy.base.Copyable qdpy.base.CreatableFromConfig qdpy.containers.grids.AutoScalingGrid qdpy.containers.grids.CVTGrid qdpy.containers.pareto.ParetoGrid qdpy.containers.sliding.SlidingBoundariesGrid qdpy.containers.t_domino.TDominOGrid

Public Member Functions

ShapeLike shape (self)
int max_items_per_bin (self)
int filled_bins (self)
GridSolutionsLike solutions (self)
GridItemsPerBinLike nb_items_per_bin (self)
GridFitnessLike fitness (self)
GridFeaturesLike features (self)
GridQualityLike quality (self)
np.ndarray quality_array (self)
Optional[GridIndexLike] best_index (self)
str filled_str (self)
 index_grid (self, param)
None discard (self, IndividualLike individual, bool also_from_parents=False)
float qd_score (self, bool normalized=True)
Public Member Functions inherited from qdpy.containers.base.Container
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)
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)
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

None _init_grid (self)
GridIndexLike _index_grid_features (self, FeaturesLike features)
Generator[GridIndexLike, None, None] _index_grid_iterator (self)
None _update_quality (self, GridIndexLike ig)
Optional[int] _add_internal (self, IndividualLike individual, bool raise_if_not_added_to_parents, bool only_to_parents)
 Choose a cell and apply its admission policy.
Optional[int] _add_to_grid (self, IndividualLike individual, GridIndexLike ig, bool raise_if_not_added_to_parents, Optional[int] replacement=None)
 Apply a successful storage update to per-cell bookkeeping.
GridIndexLike _stored_cell (self, IndividualLike individual)
 Find the admitted cell by object identity.
Protected Member Functions inherited from qdpy.containers.base.Container
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)
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

Retain quality-diversity elites in a rectangular descriptor grid.

Each descriptor coordinate maps into a discrete bin, and the
coordinates together identify a cell. Both boundaries are included.
The upper boundary of an axis maps to its final bin.

An occupied cell with spare space can accept another genome. At
capacity the candidate must dominate the selected incumbent, unless
random replacement is configured. With multiple objectives the
incumbent comparisons use Pareto dominance and storage order.
This policy retains cell representatives without maintaining a full
Pareto front.

:param iterable: Initial candidate sequence.
:param shape: Number of cells along each descriptor axis.
:param max_items_per_bin: Local capacity of each cell.
:param fitness_domain: Closed intervals for the objective vector.
:param discard_random_on_bin_overload: Replace a random member when
    the selected cell is full.
:param kwargs: Container options. Provide ``features_domain`` with
    one interval per axis. The default total capacity is the number
    of cells times the per-cell capacity.

Definition at line 70 of file grids.py.

Member Function Documentation

◆ _add_internal()

Optional[int] qdpy.containers.grids.Grid._add_internal ( self,
IndividualLike individual,
bool raise_if_not_added_to_parents,
bool only_to_parents )
protected

Choose a cell and apply its admission policy.

Parameters
individualCandidate with validated local measurements.
raise_if_not_added_to_parentsWhether parent errors must propagate.
only_to_parentsBypass cell admission.
Returns
A storage index for locally admitted or existing entries.

Reimplemented from qdpy.containers.base.Container.

Reimplemented in qdpy.containers.pareto.ParetoGrid, and qdpy.containers.sliding.SlidingBoundariesGrid.

Definition at line 337 of file grids.py.

◆ _add_to_grid()

Optional[int] qdpy.containers.grids.Grid._add_to_grid ( self,
IndividualLike individual,
GridIndexLike ig,
bool raise_if_not_added_to_parents,
Optional[int] replacement = None )
protected

Apply a successful storage update to per-cell bookkeeping.

Parameters
individualCandidate proposed for local insertion.
igIndex of the candidate's destination cell.
raise_if_not_added_to_parentsWhether required parent errors propagate.
replacementThe incumbent's position within the cell, if any.
Returns
The storage index reported by the container.

Translate a cell-relative replacement to a storage index. Update the cell only when storage records a new insertion. This keeps occupancy, scores, and activity aligned on duplicate offers.

Reimplemented in qdpy.containers.t_domino.TDominOGrid.

Definition at line 381 of file grids.py.

◆ _index_grid_features()

GridIndexLike qdpy.containers.grids.Grid._index_grid_features ( self,
FeaturesLike features )
protected
Get the index in the grid of a given individual with features ``features``, raising an IndexError if it is outside the grid. 

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

Definition at line 238 of file grids.py.

◆ _index_grid_iterator()

Generator[GridIndexLike, None, None] qdpy.containers.grids.Grid._index_grid_iterator ( self)
protected
Return an iterator of the index of the grid, based on ``self.shape``.

Definition at line 287 of file grids.py.

◆ _init_grid()

None qdpy.containers.grids.Grid._init_grid ( self)
protected
Initialise the grid to correspond to the shape `self.shape`.

Definition at line 157 of file grids.py.

◆ _stored_cell()

GridIndexLike qdpy.containers.grids.Grid._stored_cell ( self,
IndividualLike individual )
protected

Find the admitted cell by object identity.

Parameters
individualStored individual whose cell is needed.
Returns
Cell containing the exact stored object.

Try its current descriptor index first. Fall back to searching occupied entries when descriptors have changed since insertion.

Definition at line 439 of file grids.py.

◆ _update_quality()

None qdpy.containers.grids.Grid._update_quality ( self,
GridIndexLike ig )
protected
Update quality in bin ``ig`` of the grid.

Definition at line 302 of file grids.py.

◆ best_index()

Optional[GridIndexLike] qdpy.containers.grids.Grid.best_index ( self)
Stored cell index of the cached best individual, or None for an empty grid.

Definition at line 226 of file grids.py.

◆ discard()

None qdpy.containers.grids.Grid.discard ( self,
IndividualLike individual,
bool also_from_parents = False )
Remove the matching entry and refresh cell quality and occupancy.

Use the cell in which the stored object was admitted. A descriptor
edit after admission does not relocate it.

Reimplemented from qdpy.containers.base.Container.

Reimplemented in qdpy.containers.sliding.SlidingBoundariesGrid.

Definition at line 418 of file grids.py.

◆ features()

GridFeaturesLike qdpy.containers.grids.Grid.features ( self)
Return the features values in the grid.

Definition at line 207 of file grids.py.

◆ filled_bins()

int qdpy.containers.grids.Grid.filled_bins ( self)
Return the number of filled bins of the container.

Definition at line 187 of file grids.py.

◆ filled_str()

str qdpy.containers.grids.Grid.filled_str ( self)
Return a string describing the fullness of the grid (not the container itself, which is handled by ``Container.size_str``).

Definition at line 233 of file grids.py.

◆ fitness()

GridFitnessLike qdpy.containers.grids.Grid.fitness ( self)
Return the fitness values in the grid.

Definition at line 202 of file grids.py.

◆ index_grid()

qdpy.containers.grids.Grid.index_grid ( self,
param )
Return a cell index from an individual, descriptors, or named scores.

Individuals use this grid's descriptor accessor. A score mapping
requires ``features_score_names``. The regular grid includes both
endpoints and places the upper endpoint in the last bin.

:raises IndexError: If descriptors have the wrong length or exceed
    their domain.
:raises RuntimeError: If a score mapping lacks configured names.

Definition at line 261 of file grids.py.

◆ max_items_per_bin()

int qdpy.containers.grids.Grid.max_items_per_bin ( self)
Return the maximal number of items stored in a bin of the grid.

Definition at line 182 of file grids.py.

◆ nb_items_per_bin()

GridItemsPerBinLike qdpy.containers.grids.Grid.nb_items_per_bin ( self)
Return the number of items stored in each bin of the grid.

Definition at line 197 of file grids.py.

◆ qd_score()

float qdpy.containers.grids.Grid.qd_score ( self,
bool normalized = True )
Sum quality across the grid.

By default use the normalised fitness of one representative per
occupied cell, with direction determined by each objective's weight
sign. A populated grid with an infinite fitness bound returns NaN
when normalised. An empty grid has a score of zero.
With ``normalized=False``, sum raw objective values across all stored
entries, including multiple entries in one cell.

Reimplemented from qdpy.containers.base.Container.

Definition at line 475 of file grids.py.

◆ quality()

GridQualityLike qdpy.containers.grids.Grid.quality ( self)
One representative fitness object per cell, or None when empty.

Definition at line 212 of file grids.py.

◆ quality_array()

np.ndarray qdpy.containers.grids.Grid.quality_array ( self)
Array of representative raw fitness values with objectives on the last axis.

Empty cells contain NaN. For one objective, use
``quality_array[..., 0]`` to get the descriptor-shaped fitness surface.

Definition at line 217 of file grids.py.

◆ shape()

ShapeLike qdpy.containers.grids.Grid.shape ( self)
Return the shape of the grid.

Definition at line 177 of file grids.py.

◆ solutions()

GridSolutionsLike qdpy.containers.grids.Grid.solutions ( self)
Return the solutions in the grid.

Definition at line 192 of file grids.py.


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