metaheuristic_designer.encodings.composite_encoding module#

Encoding that chains a sequence of encodings into a single composite operation.

class CompositeEncoding(encodings, **kwargs)[source]#

Bases: ParameterExtendingEncoding

Encoding that applies a sequence of encodings in order.

Encodings are applied from first to last for decoding, and in reverse order for encoding. This allows stacking transformations such as type casting followed by reshaping or sigmoid mapping.

Parameters:
encodingsiterable of Encoding

The encodings to apply in sequence.

**kwargs

Forwarded to ParameterExtendingEncoding.

Attributes:
params

Access parameter values by attribute-style lookup.

Parameters:

encodings (Iterable[Encoding])

Methods

decode(population)

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

decode_params(genotype[, copy])

Extract the auxiliary parameter blocks from a genotype matrix.

encode(solutions[, 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

gather_params()[source]#

Overridable thin wrapper around get_params

encode(solutions, 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:
  • solutions (Iterable)

  • params (dict | None)

decode(population)[source]#

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

Return type:

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

Parameters:
population: ndarray

Population that should be decoded.

Returns:
solutions: Iterable

List/array of solutions.

Parameters:

population (Iterable)

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])