saealib.StrategySwitcher#

class saealib.StrategySwitcher(primary, fallback, *, metric='spearman', threshold=0.56, mid=None, mid_threshold=None)[ソース]#

ベースクラス: AccuracyBasedSurrogateSwitcher[OptimizationStrategy]

Switch between optimization strategies based on an accuracy threshold.

Generalizes a threshold-based switch between two strategies to an arbitrary accuracy metric and pair of strategies: use primary (e.g. a surrogate-heavy strategy such as PS) once the metric surpasses the threshold, otherwise fall back to fallback (e.g. a more robust strategy such as IB or GB).

Passing mid and mid_threshold opts into a three-way split that mirrors Hanawa et al. (2025)'s IB/GB/PS recommendation instead of a two-way one: fallback below threshold, mid between threshold and mid_threshold, primary at or above mid_threshold. Both must be supplied together — see Parameters.

パラメータ:
  • primary (OptimizationStrategy) -- Strategy used when accuracy is satisfactory (e.g. PS).

  • fallback (OptimizationStrategy) -- Strategy used when accuracy is poor (e.g. IB or GB).

  • metric (str) -- Metric key. Default: "spearman".

  • threshold (float) -- Minimum acceptable metric value to leave fallback. Default: 0.56.

  • mid (OptimizationStrategy or None) -- Optional third strategy (e.g. GB) used when accuracy is between threshold and mid_threshold. Enables three-way mode when provided together with mid_threshold. Default: None (two-way mode, switch() behaves exactly as without this parameter).

  • mid_threshold (float or None) -- Minimum metric value to move from mid to primary in three-way mode. Must be supplied together with mid — there is no default, since the paper's PS-viable band is narrow and accuracy-metric-dependent. Default: None.

例外:

ValueError -- If exactly one of mid / mid_threshold is provided.

メモ

The default threshold of 0.56 is taken from Hanawa et al. (2025), which recommends IB when Spearman rho is 0.56 or below, GB when rho is between 0.57 and 0.99, and PS only at an exact rho of 1.0 — a three-way split, not a two-way split at 0.56. By default (mid unset), this StrategySwitcher collapses that finding to a two-strategy approximation, so 0.56 is best used as an IB/GB boundary rather than as a PS-switching threshold — callers pairing primary=PS with the default two-way mode should be aware of the mismatch. To reproduce the paper's three-way recommendation exactly, pass mid (GB) and mid_threshold=1.0 alongside primary (PS), fallback (IB), and threshold=0.57:

switcher = StrategySwitcher(
    primary=ps_strategy,
    fallback=ib_strategy,
    mid=gb_strategy,
    threshold=0.57,
    mid_threshold=1.0,
)
for ctx in optimizer.iterate():
    optimizer.set_strategy(
        switcher.switch(optimizer.surrogate_manager.last_accuracy)
    )

参照

[34]: Hanawa, Y., Harada, T., & Miura, Y. (2025). Impact of surrogate model accuracy on performance and model management strategy in surrogate-assisted evolutionary algorithms. Array, 27, 100461.

Methods

__init__

contract

Return the strategy-switcher contract.

switch

Return primary, mid (if configured), or fallback based on the metric.

Method Details

StrategySwitcher.__init__(primary, fallback, *, metric='spearman', threshold=0.56, mid=None, mid_threshold=None)[ソース]#
パラメータ:
戻り値の型:

None

StrategySwitcher.contract()[ソース]#

Return the strategy-switcher contract.

戻り値の型:

ComponentContract

StrategySwitcher.switch(accuracy)[ソース]#

Return primary, mid (if configured), or fallback based on the metric.

パラメータ:

accuracy (SurrogateAccuracy | None)

戻り値の型:

OptimizationStrategy