saealib.Archive¶
- class saealib.Archive(attrs, init_capacity=100, key_attr='x', atol=0.0, rtol=0.0, **kwargs)[source]¶
Bases:
ArchiveMixin,PopulationConcrete archive:
ArchiveMixinmixed intoPopulation.- Parameters:
attrs (list[PopulationAttribute])
init_capacity (int)
key_attr (str)
atol (float)
rtol (float)
Methods
Initialize a Population. |
|
Add a new solution to the archive. |
|
Append a new individual to the population. |
|
Get the indices that would sort the population by a specific attribute. |
|
Clear the population. |
|
Delete individuals from the population. |
|
Create an empty Population with the same schema. |
|
Extend this population with another population. |
|
Extract individuals with indices, and return new Population. |
|
Get the array of a specific attribute. |
|
Get the array of a specific attribute. |
|
Get a cached value. |
|
Return a Population object without removing duplicates. |
|
Get k-nearest neighbors of the given solution from the archive. |
|
Return a read only view of the specified key. |
|
Public method to call when the structure changes. |
|
Public method to call when the value changes. |
|
Reorder individuals in the population. |
|
Set a cache value. |
|
Cut the population to a new size. |
|
Update array in place and bump the value version. |
Method Details
- Archive.__init__(attrs, init_capacity=100, key_attr='x', atol=0.0, rtol=0.0, **kwargs)¶
Initialize a Population.
- Parameters:
attrs (List[PopulationAttribute]) – List of population attributes. Each attribute defines a column in the population.
init_capacity (int, optional) – Initial capacity of the population, by default 100.
key_attr (str)
atol (float)
rtol (float)
- Archive.add(element=None, **kwargs)¶
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)
- Archive.append(element=None, **kwargs)¶
Append a new individual to the population.
- 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.
- Return type:
None
Examples
>>> pop.append(ind) >>> pop.append({"x": x_val}) >>> pop.append(x=x_val, f=0.1) >>> pop.append(ind, f=0.1)
- Archive.argsort(name, reverse=False)¶
Get the indices that would sort the population by a specific attribute.
- Parameters:
name (str) – The attribute name to sort by.
reverse (bool, optional) – Whether to sort in descending order, by default False.
- Return type:
ndarray
- Archive.clear()¶
Clear the population.
- Return type:
None
- Archive.delete(index)¶
Delete individuals from the population.
- Parameters:
index (int, slice, list[int], np.ndarray) – The index or indices of individuals to delete.
- Return type:
None
- Archive.empty_like(capacity=None)¶
Create an empty Population with the same schema.
- Parameters:
capacity (int) – Initial capacity of the new Population. Defaults to
self._capacity.
- Archive.extend(other)¶
Extend this population with another population.
- Parameters:
other (Population | dict) – The other population to extend from.
- Return type:
None
- Archive.extract(indices)¶
Extract individuals with indices, and return new Population.
- Parameters:
indices (np.ndarray | List[int] | slice) – Indices to extract
- Return type:
Self
- Archive.get(key, default=None)¶
Get the array of a specific attribute.
- Parameters:
key (str) – The attribute name to get the array for.
default (Any) – Returned when the key is absent.
- Return type:
ndarray
- Archive.get_array(key)¶
Get the array of a specific attribute.
- Parameters:
key (str) – The attribute name to get the array for.
- Return type:
ndarray
- Archive.get_cache(key)¶
Get a cached value.
Returns
Noneif the key is not found.- Parameters:
key (str) – The key of the cache.
- Returns:
The cached value, or
Noneif not found.- Return type:
Any | None
- Archive.get_duplicated_population()¶
Return a Population object without removing duplicates.
- Return type:
Population without removing duplicates.
- Archive.get_knn(x, k)¶
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]
- Archive.get_readonly_array(key)¶
Return a read only view of the specified key.
- Parameters:
key (str)
- Return type:
ndarray
- Archive.mod_structure()¶
Public method to call when the structure changes.
- Return type:
None
- Archive.mod_value()¶
Public method to call when the value changes.
- Return type:
None
- Archive.reorder(order)¶
Reorder individuals in the population.
- Parameters:
order (np.ndarray) – The new order of individuals.
- Return type:
None
- Archive.set_cache(key, value)¶
Set a cache value.
The cache is automatically cleared when the population is modified (via
mod_valueormod_structure).- Parameters:
key (str) – The key of the cache.
value (Any) – The value to be cached.
- Return type:
None
- Archive.truncate(new_size)¶
Cut the population to a new size.
- Parameters:
new_size (int) – The new size of the population.
- Return type:
None
- Archive.update_array(key, value)¶
Update array in place and bump the value version.
- Parameters:
key (str)
value (Any)
- Return type:
ndarray