metaheuristic_designer.parameter_schedules package#

Submodules#

Module contents#

Built-in parameter schedules for dynamic algorithm configuration.

class LinearSchedule(init_value, final_value)[source]#

Bases: SchedulableParameter

Schedule that interpolates linearly between init_value and final_value.

Parameters:
init_valuefloat

Value at progress 0.

final_valuefloat

Value at progress 1.

Parameters:
  • init_value (float)

  • final_value (float)

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:

float

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 LogisticSchedule(init_value, final_value, k=10, exact_bounds=False)[source]#

Bases: SchedulableParameter

Schedule that transitions between two values following a sigmoid curve.

The steepness is controlled by k. When exact_bounds is True, the output is rescaled to exactly start at init_value and end at final_value.

Parameters:
init_valuefloat

Starting value.

final_valuefloat

Target value.

kfloat, optional

Steepness of the logistic curve (default 10).

exact_boundsbool, optional

If True, the output is rescaled to hit the exact bounds at progress 0 and 1.

Parameters:
  • init_value (float)

  • final_value (float)

  • k (float)

  • exact_bounds (bool)

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:

float

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 RandomSchedule(init_value, final_value, rng=None)[source]#

Bases: SchedulableParameter

Schedule that returns a uniform random value between init_value and final_value at every call, ignoring progress.

Parameters:
init_valuefloat

Lower bound of the random interval.

final_valuefloat

Upper bound of the random interval.

rngRNGLike, optional

Random number generator.

Parameters:
  • init_value (float)

  • final_value (float)

  • 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:

float

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 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 StepSchedule(steps)[source]#

Bases: SchedulableParameter

Schedule defined by a dictionary of progress-value pairs.

At progress p, the schedule returns the value associated with the largest key ≤ p. This produces a step function.

Parameters:
stepsdict

Mapping of progress thresholds (floats in [0, 1]) to the values that should be active at or after that threshold.

Parameters:

steps (dict[float, Any])

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:

float

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 ThresholdSchedule(init_value, final_value, threshold=0.5)[source]#

Bases: SchedulableParameter

Schedule that returns init_value until progress reaches threshold, then switches to final_value.

Parameters:
init_valuefloat

Value used before the threshold.

final_valuefloat

Value used after the threshold.

thresholdfloat, optional

Progress point at which the switch occurs (default 0.5).

Parameters:
  • init_value (float)

  • final_value (float)

  • threshold (float)

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:

float

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 ExponentialDecaySchedule(init_value, final_value=0, alpha=0.9, iterative=True)[source]#

Bases: SchedulableParameter

Schedule that exponentially decays a value from init_value towards final_value.

In iterative mode (iterative=True, the default), the current value is multiplied by alpha each time the schedule is evaluated. In continuous mode, the decay follows the function final_value + (init_value - final_value) * exp(-alpha * progress).

Parameters:
init_valuefloat

Starting value at progress 0.

final_valuefloat, optional

Asymptotic value (default 0).

alphafloat, optional

Decay factor. In iterative mode it must be in (0, 1); in continuous mode it controls the rate of decay.

iterativebool, optional

If True (default), the value is updated step-by-step. If False, decay is computed directly from progress.

Parameters:
  • init_value (float)

  • final_value (float)

  • alpha (float)

  • iterative (bool)

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:

float

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 ProbabilityAnnealingSchedule(temperature_init=100, iterations=100, alpha=0.99, rng=None)[source]#

Bases: StridedSchedule

Annealing strategies for probabilities.

Holds a temperature parameter that is exponentially decayed and transformed into a probability using an ExponentialDecaySchedule internally.

Parameters:
temperature_initint, optional

Initial temperature, by default 100

iterationsint, optional

iterations to keep the previous parameter without updating, by default 100

alphafloat, optional

multiplier to apply to the temperature each update, by default 0.99

rng

Random state.

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:

float

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 StridedSchedule(subschedule, iterations=100)[source]#

Bases: SchedulableParameter

Schedule that applies a subschedule when a number of iterations have passed, keeping the previous value between updates.

Parameters:
subschedule: SchedulableParameter

Parameter schedule to modify the parameter each iterations iterations.

iterationsint, optional

iterations to keep the current value unchanged, by default 100

Parameters:

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:

float

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 CosineSchedule(amplitude=1, frequency=None, phase=0, offset=0)[source]#

Bases: SchedulableParameter

Schedule that models the parameter as a cosine wave in the range [0, 1].

Parameters:
amplitudefloat

Amplitude of the cosine wave.

frequencyfloat

Frequency of the cosine wave.

phasefloat

Phase of the cosine wave.

offsetfloat

Offset of the cosine wave.

Parameters:
  • amplitude (float)

  • frequency (float)

  • phase (float)

  • offset (float)

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:

float

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 NoisySchedule(subschedule, noise_level=0.01, rng=None)[source]#

Bases: SchedulableParameter

Schedule that applies gaussian noise to a subschedule.

Parameters:
subschedule: SchedulableParameter

Parameter schedule to modify the parameter each iterations iterations.

noise_levelfloat, optional

Standard deviation of the gaussian noise applied to the parameter value

Parameters:

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:

float

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.