Termination#

Layer 2: Compose

saealib.Termination

Termination class to determine when to stop the optimization process.

saealib.TerminationCondition

Composable termination condition.

saealib.max_fe(value)[ソース]#

Create a termination condition based on maximum function evaluations.

パラメータ:

value (int) -- Maximum number of function evaluations.

戻り値:

A composable condition that returns True when ctx.fe >= value.

戻り値の型:

TerminationCondition

サンプル

>>> termination = Termination(max_fe(2000))
>>> condition = max_fe(2000) & max_gen(100)
saealib.max_gen(value)[ソース]#

Create a termination condition based on maximum generations.

パラメータ:

value (int) -- Maximum number of generations.

戻り値:

A composable condition that returns True when ctx.gen >= value.

戻り値の型:

TerminationCondition

サンプル

>>> termination = Termination(max_gen(100))
>>> condition = max_gen(100) | max_fe(2000)
saealib.f_target(value)[ソース]#

Create a termination condition based on a target objective value.

Intended for single-objective problems. The direction is taken from ctx.direction (-1 for minimization, +1 for maximization), so the condition is met when the best objective found reaches value from the correct side (best <= value when minimizing, best >= value when maximizing). Returns False while the archive is empty.

パラメータ:

value (float) -- Target objective value.

戻り値:

A composable condition that returns True when the best objective in the archive reaches value.

戻り値の型:

TerminationCondition

サンプル

>>> termination = Termination(max_fe(2000), f_target(1e-6))
saealib.stalled(window, tol=1e-08)[ソース]#

Create a termination condition based on lack of improvement (stagnation).

Terminates when the best score (f @ direction, higher is better) has not improved by more than tol for window consecutive generations. Improvement is tracked across calls using ctx.gen; the returned condition is therefore stateful and intended to be used once per run.

パラメータ:
  • window (int) -- Number of generations without improvement before terminating.

  • tol (float, optional) -- Minimum score increase counted as an improvement, by default 1e-8.

戻り値:

A composable condition that returns True after window stagnant generations.

戻り値の型:

TerminationCondition

サンプル

>>> termination = Termination(max_fe(2000), stalled(20))