Skip to content

Commit 778ff14

Browse files
committed
add 'test_sigma_self_adaptation'
1 parent 8532802 commit 778ff14

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/test_optimizers/test_parameter/test_evolution_strategy_para_init.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,24 @@ def objective_function(para):
5454
@pytest.mark.parametrize(*pytest_wrapper)
5555
def test_hill_climbing_para(opt_para):
5656
_base_para_test_func(opt_para, EvolutionStrategyOptimizer)
57+
58+
59+
def test_sigma_self_adaptation():
60+
"""Test that sigma values adapt during optimization."""
61+
search_space = {"x1": np.arange(-10, 11, 1), "x2": np.arange(-10, 11, 1)}
62+
63+
opt = EvolutionStrategyOptimizer(search_space, population=5)
64+
65+
# All individuals should have sigma attribute initialized to epsilon
66+
for ind in opt.individuals:
67+
assert hasattr(ind, "sigma")
68+
assert ind.sigma == ind.epsilon
69+
70+
initial_sigmas = [ind.sigma for ind in opt.individuals]
71+
72+
opt.search(objective_function, n_iter=50, verbosity=False)
73+
74+
final_sigmas = [ind.sigma for ind in opt.individuals]
75+
76+
# At least one sigma should have changed (self-adaptation working)
77+
assert initial_sigmas != final_sigmas

0 commit comments

Comments
 (0)