saealib.Termination#

class saealib.Termination(*conditions)[ソース]#

ベースクラス: object

Termination class to determine when to stop the optimization process.

Accepts one or more callable conditions. Each condition receives an OptimizationState and returns True when the process should terminate. The optimization stops when any condition evaluates to True.

パラメータ:

*conditions (ConditionFunc or TerminationCondition) -- One or more callable conditions. Each must accept an OptimizationState and return bool.

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

__init__

all_of

Build a Termination that stops when all conditions are met (AND).

any_of

Build a Termination that stops when any condition is met (OR).

contract

Return the termination contract inferred from registered conditions.

is_terminated

Check if the composed termination condition is met.

not_

Build a Termination that stops when condition is not met (NOT).

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.

戻り値の型:

Termination

例外:

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 with all_of() and not_().

パラメータ:

*conditions (ConditionFunc or TerminationCondition) -- One or more callable conditions.

戻り値:

A termination combining the conditions with OR.

戻り値の型:

Termination

Termination.contract()[ソース]#

Return the termination contract inferred from registered conditions.

戻り値の型:

ComponentContract

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 condition is not met (NOT).

パラメータ:

condition (ConditionFunc or TerminationCondition) -- The condition to negate.

戻り値:

A termination that negates the given condition.

戻り値の型:

Termination