Skip to content

Commit 85d06a9

Browse files
committed
remove surfaces from tests
1 parent a6507da commit 85d06a9

File tree

6 files changed

+52
-41
lines changed

6 files changed

+52
-41
lines changed

tests/local_test_performance/local_test_global_opt.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
from tqdm import tqdm
33
import numpy as np
44

5-
from surfaces.test_functions.mathematical import RastriginFunction
6-
75
from gradient_free_optimizers import (
86
RandomSearchOptimizer,
97
RandomRestartHillClimbingOptimizer,
@@ -25,7 +23,11 @@
2523
def test_global_perf(Optimizer):
2624
ackley_function = RastriginFunction(n_dim=1, metric="score")
2725

28-
search_space = {"x0": np.arange(-100, 101, 1)}
26+
def objective_function(para):
27+
score = -para["x1"] * para["x1"]
28+
return score
29+
30+
search_space = {"x1": np.arange(-100, 101, 1)}
2931
initialize = {"vertices": 2}
3032

3133
n_opts = 33
@@ -35,7 +37,7 @@ def test_global_perf(Optimizer):
3537
for rnd_st in tqdm(range(n_opts)):
3638
opt = Optimizer(search_space, initialize=initialize, random_state=rnd_st)
3739
opt.search(
38-
ackley_function.objective_function,
40+
objective_function,
3941
n_iter=n_iter,
4042
memory=False,
4143
verbosity=False,

tests/test_early_stop.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ def objective_function(para):
105105
n_iter_no_change = 5
106106
early_stopping = {
107107
"n_iter_no_change": 5,
108-
"tol_abs": 0.1,
108+
"tol_abs": 1,
109109
"tol_rel": None,
110110
}
111111

112112
start1 = {"x1": 0}
113-
start2 = {"x1": 0.1}
114-
start3 = {"x1": 0.2}
115-
start4 = {"x1": 0.3}
116-
start5 = {"x1": 0.4}
113+
start2 = {"x1": 1}
114+
start3 = {"x1": 2}
115+
start4 = {"x1": 3}
116+
start5 = {"x1": 4}
117117

118118
warm_start_l = [
119119
start1,
@@ -162,13 +162,13 @@ def objective_function(para):
162162
n_iter_no_change = 5
163163
early_stopping = {
164164
"n_iter_no_change": n_iter_no_change,
165-
"tol_abs": 0.1,
165+
"tol_abs": 10,
166166
"tol_rel": None,
167167
}
168168

169169
start1 = {"x1": 0}
170-
start2 = {"x1": 0.09}
171-
start3 = {"x1": 0.20}
170+
start2 = {"x1": 9}
171+
start3 = {"x1": 20}
172172

173173
warm_start_l = [
174174
start1,

tests/test_optimizers/test_opt_algos_simple.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from gradient_free_optimizers.optimizers.core_optimizer import search_tracker
22
import pytest
3+
import numpy as np
34

45
from gradient_free_optimizers import (
56
HillClimbingOptimizer,
@@ -21,8 +22,6 @@
2122
ForestOptimizer,
2223
)
2324

24-
from surfaces.test_functions.mathematical import SphereFunction
25-
2625
optimizers = (
2726
"Optimizer",
2827
[
@@ -47,13 +46,20 @@
4746
)
4847

4948

50-
sphere_function = SphereFunction(n_dim=2, metric="score")
49+
def objective_function(para):
50+
score = -para["x1"] * para["x1"]
51+
return score
52+
53+
54+
search_space = {
55+
"x1": np.arange(0, 10, 1),
56+
}
5157

5258

5359
@pytest.mark.parametrize(*optimizers)
5460
def test_opt_algos_0(Optimizer):
55-
opt = Optimizer(sphere_function.search_space())
56-
opt.search(sphere_function.objective_function, n_iter=15)
61+
opt = Optimizer(search_space)
62+
opt.search(objective_function, n_iter=15)
5763

5864
_ = opt.best_para
5965
_ = opt.best_score

tests/test_optimizers/test_random_state.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55

66

77
from ._parametrize import optimizers_non_deterministic as optimizers
8-
from surfaces.test_functions.mathematical import AckleyFunction
98
from gradient_free_optimizers import DirectAlgorithm
109

11-
ackkley_function = AckleyFunction()
12-
1310

1411
def objective_function(para):
1512
score = -(para["x0"] * para["x0"] + para["x1"] * para["x1"])
@@ -33,13 +30,13 @@ def objective_function(para):
3330
def test_random_state_0(Optimizer):
3431
opt0 = Optimizer(search_space, initialize={"random": n_random}, random_state=1)
3532
opt0.search(
36-
ackkley_function.objective_function,
33+
objective_function,
3734
n_iter=n_iter,
3835
)
3936

4037
opt1 = Optimizer(search_space, initialize={"random": n_random}, random_state=1)
4138
opt1.search(
42-
ackkley_function.objective_function,
39+
objective_function,
4340
n_iter=n_iter,
4441
)
4542

@@ -56,13 +53,13 @@ def test_random_state_0(Optimizer):
5653
def test_random_state_1(Optimizer):
5754
opt0 = Optimizer(search_space, initialize={"random": n_random}, random_state=10)
5855
opt0.search(
59-
ackkley_function.objective_function,
56+
objective_function,
6057
n_iter=n_iter,
6158
)
6259

6360
opt1 = Optimizer(search_space, initialize={"random": n_random}, random_state=10)
6461
opt1.search(
65-
ackkley_function.objective_function,
62+
objective_function,
6663
n_iter=n_iter,
6764
)
6865

@@ -76,13 +73,13 @@ def test_random_state_1(Optimizer):
7673
def test_random_state_2(Optimizer):
7774
opt0 = Optimizer(search_space, initialize={"random": n_random}, random_state=1)
7875
opt0.search(
79-
ackkley_function.objective_function,
76+
objective_function,
8077
n_iter=n_iter,
8178
)
8279

8380
opt1 = Optimizer(search_space, initialize={"random": n_random}, random_state=10)
8481
opt1.search(
85-
ackkley_function.objective_function,
82+
objective_function,
8683
n_iter=n_iter,
8784
)
8885

@@ -100,15 +97,15 @@ def test_random_state_direct():
10097
search_space, initialize={"random": n_random}, random_state=1
10198
)
10299
opt0.search(
103-
ackkley_function.objective_function,
100+
objective_function,
104101
n_iter=n_iter,
105102
)
106103

107104
opt1 = DirectAlgorithm(
108105
search_space, initialize={"random": n_random}, random_state=10
109106
)
110107
opt1.search(
111-
ackkley_function.objective_function,
108+
objective_function,
112109
n_iter=n_iter,
113110
)
114111

@@ -124,10 +121,10 @@ def test_random_state_direct():
124121
@pytest.mark.parametrize(*optimizers)
125122
def test_no_random_state_0(Optimizer):
126123
opt0 = Optimizer(search_space, initialize={"random": n_random})
127-
opt0.search(ackkley_function.objective_function, n_iter=n_iter)
124+
opt0.search(objective_function, n_iter=n_iter)
128125

129126
opt1 = Optimizer(search_space, initialize={"random": n_random})
130-
opt1.search(ackkley_function.objective_function, n_iter=n_iter)
127+
opt1.search(objective_function, n_iter=n_iter)
131128

132129
print("\n opt0.search_data \n", opt0.search_data)
133130
print("\n opt1.search_data \n", opt1.search_data)

tests/test_parameters/test_simulated_annealing.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
import pytest
66
import numpy as np
77

8-
from surfaces.test_functions.mathematical import SphereFunction
9-
108
from gradient_free_optimizers import SimulatedAnnealingOptimizer
119

1210

13-
sphere_function = SphereFunction(n_dim=2)
14-
objective_function = sphere_function.objective_function
15-
search_space = sphere_function.search_space()
11+
def objective_function(para):
12+
score = -para["x1"] * para["x1"]
13+
return score
14+
15+
16+
search_space = {
17+
"x1": np.arange(0, 10, 1),
18+
}
1619

1720

1821
n_iter = 1000

tests/test_parameters/test_stochastic_hill_climbing.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
import pytest
66
import numpy as np
77

8-
from surfaces.test_functions.mathematical import SphereFunction
9-
108
from gradient_free_optimizers import StochasticHillClimbingOptimizer
119

1210

13-
sphere_function = SphereFunction(n_dim=2)
14-
objective_function = sphere_function.objective_function
15-
search_space = sphere_function.search_space()
11+
n_iter = 1000
1612

1713

18-
n_iter = 1000
14+
def objective_function(para):
15+
score = -para["x1"] * para["x1"]
16+
return score
17+
18+
19+
search_space = {
20+
"x1": np.arange(0, 10, 1),
21+
}
1922

2023

2124
def test_p_accept():

0 commit comments

Comments
 (0)