Termination#
Termination class to determine when to stop the optimization process. |
|
Composable termination condition. |
- saealib.max_fe(value)[source]#
Create a termination condition based on maximum function evaluations.
- Parameters:
value (int) – Maximum number of function evaluations.
- Returns:
A composable condition that returns True when
ctx.fe >= value.- Return type:
Examples
>>> termination = Termination(max_fe(2000)) >>> condition = max_fe(2000) & max_gen(100)
- saealib.max_gen(value)[source]#
Create a termination condition based on maximum generations.
- Parameters:
value (int) – Maximum number of generations.
- Returns:
A composable condition that returns True when
ctx.gen >= value.- Return type:
Examples
>>> termination = Termination(max_gen(100)) >>> condition = max_gen(100) | max_fe(2000)
- saealib.f_target(value)[source]#
Create a termination condition based on a target objective value.
Intended for single-objective problems. The direction is taken from
ctx.direction(-1for minimization,+1for maximization), so the condition is met when the best objective found reachesvaluefrom the correct side (best <= valuewhen minimizing,best >= valuewhen maximizing). ReturnsFalsewhile the archive is empty.- Parameters:
value (float) – Target objective value.
- Returns:
A composable condition that returns True when the best objective in the archive reaches
value.- Return type:
Examples
>>> termination = Termination(max_fe(2000), f_target(1e-6))
- saealib.stalled(window, tol=1e-08)[source]#
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 thantolforwindowconsecutive generations. Improvement is tracked across calls usingctx.gen; the returned condition is therefore stateful and intended to be used once per run.- Parameters:
window (int) – Number of generations without improvement before terminating.
tol (float, optional) – Minimum score increase counted as an improvement, by default
1e-8.
- Returns:
A composable condition that returns True after
windowstagnant generations.- Return type:
Examples
>>> termination = Termination(max_fe(2000), stalled(20))