metaheuristic_designer.schedulable_parameter module#

Module for schedule-dependent parameters whose value changes with progress.

class SchedulableParameter(rng=None)[source]#

Bases: ABC

Abstract base for parameters that depend on the optimization progress.

A schedulable parameter is a callable that receives a progress value between 0 and 1 and returns the parameter’s value at that point. Subclasses implement evaluate().

Parameters:
rngRNGLike, optional

Random number generator, made available for subclasses that need stochastic schedules.

Parameters:

rng (int | Generator | None)

Methods

__call__(progress)

Shorthand for evaluate().

evaluate(progress)

Return the parameter value at the given progress.

abstract evaluate(progress)[source]#

Return the parameter value at the given progress.

Return type:

Any

Parameters:
progressfloat

Current progress, a number between 0 (start) and 1 (end).

Returns:
Any

The parameter value at this stage of the optimization.

Parameters:

progress (float)

Notes

The return value is not restricted to numbers. You can return: * a float (e.g., a linearly decaying mutation strength), * an int (e.g., a discrete number of mutated components), * a bool (e.g., switching on/off a feature after a threshold), * a string (e.g., switching between strategies), or * any other object that the consuming component expects.

This makes schedules suitable for changing discrete algorithm choices as well as continuous numerical parameters.

class ParameterFromLambda(schedule_fn, rng=None)[source]#

Bases: SchedulableParameter

Schedulable parameter that wraps a user-supplied function.

Parameters:
schedule_fncallable

A function (progress) -> value that defines the schedule.

rngRNGLike, optional

Random number generator (passed through to the base class).

Parameters:
  • schedule_fn (Callable)

  • rng (int | Generator | None)

Methods

__call__(progress)

Shorthand for evaluate().

evaluate(progress)

Return the parameter value at the given progress.

evaluate(progress)[source]#

Return the parameter value at the given progress.

Return type:

Any

Parameters:
progressfloat

Current progress, a number between 0 (start) and 1 (end).

Returns:
Any

The parameter value at this stage of the optimization.

Parameters:

progress (float)

Notes

The return value is not restricted to numbers. You can return: * a float (e.g., a linearly decaying mutation strength), * an int (e.g., a discrete number of mutated components), * a bool (e.g., switching on/off a feature after a threshold), * a string (e.g., switching between strategies), or * any other object that the consuming component expects.

This makes schedules suitable for changing discrete algorithm choices as well as continuous numerical parameters.