metaheuristic_designer.encodings.sigmoid_encoding module#

Encoding that applies a sigmoid function to enable continuous operators on binary problems.

class SigmoidEncoding(as_probability=True, threshold=0.5, **kwargs)[source]#

Bases: Encoding

Encoding that maps binary solutions to continuous values via a sigmoid.

The encoding applies \(\sigma(x) = 1 / (1 + e^{-x})\) pointwise. During encoding, the logit function is applied to the probability parameter (producing real numbers). During decoding, the sigmoid is applied again. This allows real-valued operators (e.g., Gaussian mutation) to be used on binary problems.

Parameters:
as_probabilitybool, optional

If True (default), each component is returned as a probability in (0, 1). If False, the probability is thresholded to produce a hard 0/1 value.

thresholdfloat, optional

Threshold used when as_probability=False. Must be in (0, 1). Default is 0.5.

**kwargs

Forwarded to Encoding.

Attributes:
params

Access parameter values by attribute-style lookup.

Parameters:
  • as_probability (bool)

  • threshold (float)

Methods

decode(population)

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

encode(solutions)

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(solutions)[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)

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