Skip to content

Commit 6049e0d

Browse files
committed
chore(tests): Adds tests for GSGP.
1 parent e6cfcaa commit 6049e0d

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import sys
2+
3+
import numpy as np
4+
5+
from opytimizer.core import function
6+
from opytimizer.optimizers.evolutionary import gsgp
7+
from opytimizer.spaces import tree
8+
9+
10+
def test_gsgp_mutation():
11+
new_gsgp = gsgp.GSGP()
12+
13+
tree_space = tree.TreeSpace(
14+
n_agents=10,
15+
n_terminals=2,
16+
n_variables=1,
17+
min_depth=1,
18+
max_depth=5,
19+
functions=["SUM"],
20+
lower_bound=[0],
21+
upper_bound=[10],
22+
)
23+
24+
new_gsgp._mutation(tree_space)
25+
26+
27+
def test_gsgp_mutate():
28+
new_gsgp = gsgp.GSGP()
29+
30+
tree_space = tree.TreeSpace(
31+
n_agents=10,
32+
n_terminals=2,
33+
n_variables=1,
34+
min_depth=1,
35+
max_depth=5,
36+
functions=["SUM"],
37+
lower_bound=[0],
38+
upper_bound=[10],
39+
)
40+
41+
new_gsgp._mutate(tree_space.trees[0], tree_space.n_variables, 1)
42+
43+
44+
def test_gsgp_crossover():
45+
new_gsgp = gsgp.GSGP()
46+
47+
tree_space = tree.TreeSpace(
48+
n_agents=10,
49+
n_terminals=2,
50+
n_variables=1,
51+
min_depth=1,
52+
max_depth=5,
53+
functions=["SUM"],
54+
lower_bound=[0],
55+
upper_bound=[10],
56+
)
57+
58+
new_gsgp._crossover(tree_space)
59+
60+
61+
def test_gsgp_cross():
62+
new_gsgp = gsgp.GSGP()
63+
64+
tree_space = tree.TreeSpace(
65+
n_agents=10,
66+
n_terminals=2,
67+
n_variables=1,
68+
min_depth=1,
69+
max_depth=5,
70+
functions=["SUM"],
71+
lower_bound=[0],
72+
upper_bound=[10],
73+
)
74+
75+
new_gsgp._cross(
76+
tree_space.trees[0], tree_space.trees[1], tree_space.n_variables, 1, 1
77+
)

0 commit comments

Comments
 (0)