metaheuristic_designer.encodings.parameter_extending_encoding module#

Encoding that splits a genotype into a solution part and auxiliary parameters.

class ParameterExtendingEncoding(dimension, param_sizes, base_encoding=None, verify=False, **kwargs)[source]#

Bases: Encoding, ABC

Encoding that appends extra parameters to the solution genotype.

The genotype vector is split into two parts: the first dimension elements hold the actual solution, and the remaining elements store one or more named parameter blocks (e.g., velocity for PSO, mutation strengths for self-adaptation). A base encoding is applied to the solution part; the parameters are stored raw.

Parameters:
dimensionint

Number of decision variables in the solution.

param_sizesiterable of (name, length)

Named blocks of extra parameters appended to the genotype.

base_encodingEncoding, optional

Encoding applied to the solution part. Defaults to DefaultEncoding.

verifybool, optional

If True, additional shape and key checks are performed in encode_params().

**kwargs

Forwarded to Encoding.

Attributes:
params

Access parameter values by attribute-style lookup.

Parameters:
  • dimension (int)

  • param_sizes (Iterable[Tuple[str, int]])

  • base_encoding (Optional[Encoding])

  • verify (bool)

Methods

decode(population_matrix)

Decodes a population matrix into a list/array of solutions.

decode_params(genotype[, copy])

Extract the auxiliary parameter blocks from a genotype matrix.

encode(solution[, params])

Encodes a list of solutions to our problem to an population matrix.

encode_params(param_dict)

Stack a dictionary of parameter arrays into a single matrix.

extract_params(population_matrix)

Return only the auxiliary-parameter part of the genotype matrix.

extract_solution(population_matrix)

Return only the solution part of the genotype matrix.

gather_params()

Overridable thin wrapper around get_params

get_params()

Return a copy of the current parameter dictionary.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Re-evaluate all stored parameters at the current progress.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

get_state

encode(solution, params=None)[source]#

Encodes a list of solutions to our problem to an population matrix.

Return type:

ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool]

Parameters:
solutions: Iterable

Solutions that should be encoded.

Returns:
population: ndarray

Population array.

Parameters:
  • solution (Iterable)

  • params (dict | None)

decode(population_matrix)[source]#

Decodes a population matrix into a list/array of solutions.

Return type:

Iterable

Parameters:
population: ndarray

Population that should be decoded.

Returns:
solutions: Iterable

List/array of solutions.

Parameters:

population_matrix (ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool])

decode_params(genotype, copy=True)[source]#

Extract the auxiliary parameter blocks from a genotype matrix.

Return type:

dict

Parameters:
genotypeMatrixLike

The full genotype matrix (solution + parameters).

copybool, optional

Whether to return copies of the parameter arrays.

Returns:
dict

Dictionary mapping parameter names to their sub-arrays.

Parameters:
  • genotype (ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool])

  • copy (bool)

extract_solution(population_matrix)[source]#

Return only the solution part of the genotype matrix.

Return type:

ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool]

Parameters:
population_matrixMatrixLike

The full genotype matrix.

Returns:
MatrixLike

The first dimension columns containing the solution.

Parameters:

population_matrix (ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool])

extract_params(population_matrix)[source]#

Return only the auxiliary-parameter part of the genotype matrix.

Return type:

ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool]

Parameters:
population_matrixMatrixLike

The full genotype matrix.

Returns:
MatrixLike

The columns beyond dimension that contain the extra parameters.

Parameters:

population_matrix (ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool])

encode_params(param_dict)[source]#

Stack a dictionary of parameter arrays into a single matrix.

Return type:

ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool]

Parameters:
param_dictdict

Mapping from parameter names to 2-D arrays.

Returns:
MatrixLike

A (population_size, total_param_size) array.

Parameters:

param_dict (dict)