saealib.ArchiveMixin

class saealib.ArchiveMixin(attrs, init_capacity=100, key_attr='x', atol=0.0, rtol=0.0, **kwargs)[source]

Bases: object

A mixin class for using Population as an Archive.

Must be subclassed via multiple inheritance as a subclass of the Population class. Handle archive of evaluated solutions. (self.data must have at least key_attr (default is “x”).) Duplicate removal and range queries can be performed.

Parameters:
  • attrs (list[PopulationAttribute])

  • init_capacity (int)

  • key_attr (str)

  • atol (float)

  • rtol (float)

data

Dictionary to store archive data.

Type:

dict[str, np.ndarray]

duplicate_log

List to store duplicate solutions information.

Type:

list[dict]

key_attr

Key for duplicate checking

Type:

str

atol

Absolute tolerance for duplicate check.

Type:

float

rtol

Relative tolerance for duplicate check.

Type:

float

Methods

__init__

add

Add a new solution to the archive.

get_duplicated_population

Return a Population object without removing duplicates.

get_knn

Get k-nearest neighbors of the given solution from the archive.

Method Details

ArchiveMixin.__init__(attrs, init_capacity=100, key_attr='x', atol=0.0, rtol=0.0, **kwargs)[source]
Parameters:
  • attrs (list[PopulationAttribute])

  • init_capacity (int)

  • key_attr (str)

  • atol (float)

  • rtol (float)

ArchiveMixin.add(element=None, **kwargs)[source]

Add a new solution to the archive. Duplicate solutions are ignored.

Parameters:
  • element (Individual | dict | None) – Data for the additional individual

  • **kwargs – Set attribute values individually and add them. Alternatively, overwrite based on the element’s value and add it.

Returns:

idx – Destination Index

Return type:

int

Examples

>>> arcv.add(ind)
>>> arcv.add({"x": x_val})
>>> arcv.add(x=x_val, f=0.1)
>>> arcv.add(ind, f=0.1)
ArchiveMixin.get_duplicated_population()[source]

Return a Population object without removing duplicates.

Return type:

Population without removing duplicates.

ArchiveMixin.get_knn(x, k)[source]

Get k-nearest neighbors of the given solution from the archive.

Parameters:
  • x (np.ndarray) – The solution to find neighbors for.

  • k (int) – The number of neighbors to retrieve.

Returns:

The k-nearest neighbors’ solutions and their objective values.

Return type:

tuple[np.ndarray, np.ndarray]