saealib.StrategySwitcher#
- class saealib.StrategySwitcher(primary, fallback, *, metric='spearman', threshold=0.56, mid=None, mid_threshold=None)[source]#
Bases:
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 tofallback(e.g. a more robust strategy such as IB or GB).Passing
midandmid_thresholdopts into a three-way split that mirrors Hanawa et al. (2025)’s IB/GB/PS recommendation instead of a two-way one:fallbackbelowthreshold,midbetweenthresholdandmid_threshold,primaryat or abovemid_threshold. Both must be supplied together — see Parameters.- 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
thresholdandmid_threshold. Enables three-way mode when provided together withmid_threshold. Default:None(two-way mode,switch()behaves exactly as without this parameter).mid_threshold (float or None) – Minimum metric value to move from
midtoprimaryin three-way mode. Must be supplied together withmid— there is no default, since the paper’s PS-viable band is narrow and accuracy-metric-dependent. Default:None.
- Raises:
ValueError – If exactly one of
mid/mid_thresholdis provided.
Notes
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 (
midunset), thisStrategySwitchercollapses 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 pairingprimary=PSwith the default two-way mode should be aware of the mismatch. To reproduce the paper’s three-way recommendation exactly, passmid(GB) andmid_threshold=1.0alongsideprimary(PS),fallback(IB), andthreshold=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) )
References
[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
Return the strategy-switcher contract. |
|
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)[source]#
- Parameters:
primary (OptimizationStrategy)
fallback (OptimizationStrategy)
metric (str)
threshold (float)
mid (OptimizationStrategy | None)
mid_threshold (float | None)
- Return type:
None
- StrategySwitcher.switch(accuracy)[source]#
Return primary, mid (if configured), or fallback based on the metric.
- Parameters:
accuracy (SurrogateAccuracy | None)
- Return type: