metaheuristic_designer.encodings.image_encoding module#

Encoding for image-based optimization tasks.

class ImageEncoding(shape, color=True, **kwargs)[source]#

Bases: Encoding

Encoding that maps between flat genotype vectors and image tensors.

Each individual is reshaped to (height, width, channels). When color is False the channel dimension is omitted (grayscale).

Parameters:
shapetuple of int

(height, width) of the image.

colorbool, optional

If True (default), the image has 3 colour channels (RGB). If False, it has 1 channel (grayscale).

**kwargs

Forwarded to Encoding.

Attributes:
params

Access parameter values by attribute-style lookup.

Parameters:
  • shape (Tuple[int, int])

  • color (bool)

Methods

decode(population)

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

encode(solution)

Encodes a list of solutions to our problem to an population 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)[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)

decode(population)[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 (ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool])