saealib.Termination#
- class saealib.Termination(*conditions)[ソース]#
ベースクラス:
objectTermination class to determine when to stop the optimization process.
Accepts one or more callable conditions. Each condition receives an
OptimizationStateand returnsTruewhen the process should terminate. The optimization stops when any condition evaluates toTrue.- パラメータ:
*conditions (ConditionFunc or TerminationCondition) -- One or more callable conditions. Each must accept an
OptimizationStateand returnbool.- 例外:
ValueError -- If no conditions are provided.
TypeError -- If any condition is not callable.
サンプル
>>> termination = Termination(max_fe(2000)) >>> termination = Termination(max_fe(2000), max_gen(100)) >>> termination = Termination( ... max_fe(2000), ... lambda ctx: ctx.archive.get("f").min() < 1e-6, ... ) >>> termination = Termination.all_of(max_fe(2000), max_gen(100)) >>> termination = Termination.not_(max_gen(100))
Methods
Build a Termination that stops when all conditions are met (AND). |
|
Build a Termination that stops when any condition is met (OR). |
|
Return the termination contract inferred from registered conditions. |
|
Check if the composed termination condition is met. |
|
Build a Termination that stops when |
Method Details
- Termination.__init__(*conditions)[ソース]#
- パラメータ:
conditions (ConditionFunc | TerminationCondition)
- classmethod Termination.all_of(*conditions)[ソース]#
Build a Termination that stops when all conditions are met (AND).
- パラメータ:
*conditions (ConditionFunc or TerminationCondition) -- One or more callable conditions.
- 戻り値:
A termination combining the conditions with AND.
- 戻り値の型:
- 例外:
ValueError -- If no conditions are provided.
- classmethod Termination.any_of(*conditions)[ソース]#
Build a Termination that stops when any condition is met (OR).
Equivalent to
Termination(*conditions); provided for symmetry withall_of()andnot_().- パラメータ:
*conditions (ConditionFunc or TerminationCondition) -- One or more callable conditions.
- 戻り値:
A termination combining the conditions with OR.
- 戻り値の型:
- Termination.contract()[ソース]#
Return the termination contract inferred from registered conditions.
- 戻り値の型:
- Termination.is_terminated(ctx)[ソース]#
Check if the composed termination condition is met.
- パラメータ:
ctx (OptimizationState) -- The current optimization context.
- 戻り値:
True if the termination condition is met, False otherwise.
- 戻り値の型:
bool
- classmethod Termination.not_(condition)[ソース]#
Build a Termination that stops when
conditionis not met (NOT).- パラメータ:
condition (ConditionFunc or TerminationCondition) -- The condition to negate.
- 戻り値:
A termination that negates the given condition.
- 戻り値の型: