eckity.creators.gp_creators.full

 1from overrides import overrides
 2
 3from eckity.creators.gp_creators.tree_creator import GPTreeCreator
 4
 5
 6class FullCreator(GPTreeCreator):
 7	def __init__(self,
 8				 init_depth=None,
 9				 function_set=None,
10				 terminal_set=None,
11				 erc_range=None,
12				 bloat_weight=0.1,
13				 events=None):
14		"""
15		Tree creator using the full method
16
17		Parameters
18		----------
19		init_depth : (int, int)
20		Min and max depths of initial random trees. The default is None.
21
22		function_set : list
23			List of functions used as internal nodes in the GP tree. The default is None.
24
25		terminal_set : list
26			List of terminals used in the GP-tree leaves. The default is None.
27
28		erc_range : (float, float)
29			Range of values for ephemeral random constant (ERC). The default is None.
30
31		bloat_weight : float
32			Bloat control weight to punish large trees. Bigger values make a bigger punish.
33
34		events : list
35			List of events related to this class
36		"""
37		super().__init__(init_depth=init_depth, function_set=function_set, terminal_set=terminal_set,
38						 erc_range=erc_range, bloat_weight=bloat_weight, events=events)
39
40	@overrides
41	def create_tree(self, tree_ind, max_depth=5):
42		"""
43		Create a random tree using the full method, and assign it to the given individual.
44
45		Parameters
46		----------
47		tree_ind: Tree
48			An individual of GP Tree representation with an initially empty tree
49
50		max_depth: int
51			Maximum depth of tree. The default is 5.
52
53		Returns
54		-------
55		None.
56		"""
57		self._create_tree(tree_ind, max_depth, 0)
58
59	def _create_tree(self, tree_ind, max_depth=5, depth=0):
60		"""
61		Recursively create a random tree using the full method.
62
63		Parameters
64		----------
65		max_depth : int
66			Maximum depth of tree. The default is 5.
67
68		depth : int, optional
69			Current depth in recursive process. The default is 0.
70
71		Returns
72		-------
73		None.
74
75		"""
76		is_func = False
77
78		if depth >= max_depth:
79			node = tree_ind.random_terminal()
80		else:
81			node = tree_ind.random_function()
82			is_func = True
83
84		tree_ind.add_tree(node)
85
86		if is_func:
87			for i in range(tree_ind.arity[node]):
88				self._create_tree(tree_ind, max_depth, depth=depth + 1)
 7class FullCreator(GPTreeCreator):
 8	def __init__(self,
 9				 init_depth=None,
10				 function_set=None,
11				 terminal_set=None,
12				 erc_range=None,
13				 bloat_weight=0.1,
14				 events=None):
15		"""
16		Tree creator using the full method
17
18		Parameters
19		----------
20		init_depth : (int, int)
21		Min and max depths of initial random trees. The default is None.
22
23		function_set : list
24			List of functions used as internal nodes in the GP tree. The default is None.
25
26		terminal_set : list
27			List of terminals used in the GP-tree leaves. The default is None.
28
29		erc_range : (float, float)
30			Range of values for ephemeral random constant (ERC). The default is None.
31
32		bloat_weight : float
33			Bloat control weight to punish large trees. Bigger values make a bigger punish.
34
35		events : list
36			List of events related to this class
37		"""
38		super().__init__(init_depth=init_depth, function_set=function_set, terminal_set=terminal_set,
39						 erc_range=erc_range, bloat_weight=bloat_weight, events=events)
40
41	@overrides
42	def create_tree(self, tree_ind, max_depth=5):
43		"""
44		Create a random tree using the full method, and assign it to the given individual.
45
46		Parameters
47		----------
48		tree_ind: Tree
49			An individual of GP Tree representation with an initially empty tree
50
51		max_depth: int
52			Maximum depth of tree. The default is 5.
53
54		Returns
55		-------
56		None.
57		"""
58		self._create_tree(tree_ind, max_depth, 0)
59
60	def _create_tree(self, tree_ind, max_depth=5, depth=0):
61		"""
62		Recursively create a random tree using the full method.
63
64		Parameters
65		----------
66		max_depth : int
67			Maximum depth of tree. The default is 5.
68
69		depth : int, optional
70			Current depth in recursive process. The default is 0.
71
72		Returns
73		-------
74		None.
75
76		"""
77		is_func = False
78
79		if depth >= max_depth:
80			node = tree_ind.random_terminal()
81		else:
82			node = tree_ind.random_function()
83			is_func = True
84
85		tree_ind.add_tree(node)
86
87		if is_func:
88			for i in range(tree_ind.arity[node]):
89				self._create_tree(tree_ind, max_depth, depth=depth + 1)
FullCreator( init_depth=None, function_set=None, terminal_set=None, erc_range=None, bloat_weight=0.1, events=None)
 8	def __init__(self,
 9				 init_depth=None,
10				 function_set=None,
11				 terminal_set=None,
12				 erc_range=None,
13				 bloat_weight=0.1,
14				 events=None):
15		"""
16		Tree creator using the full method
17
18		Parameters
19		----------
20		init_depth : (int, int)
21		Min and max depths of initial random trees. The default is None.
22
23		function_set : list
24			List of functions used as internal nodes in the GP tree. The default is None.
25
26		terminal_set : list
27			List of terminals used in the GP-tree leaves. The default is None.
28
29		erc_range : (float, float)
30			Range of values for ephemeral random constant (ERC). The default is None.
31
32		bloat_weight : float
33			Bloat control weight to punish large trees. Bigger values make a bigger punish.
34
35		events : list
36			List of events related to this class
37		"""
38		super().__init__(init_depth=init_depth, function_set=function_set, terminal_set=terminal_set,
39						 erc_range=erc_range, bloat_weight=bloat_weight, events=events)

Tree creator using the full method

Parameters
  • init_depth ((int, int)):

  • Min and max depths of initial random trees. The default is None.

  • function_set (list): List of functions used as internal nodes in the GP tree. The default is None.
  • terminal_set (list): List of terminals used in the GP-tree leaves. The default is None.
  • erc_range ((float, float)): Range of values for ephemeral random constant (ERC). The default is None.
  • bloat_weight (float): Bloat control weight to punish large trees. Bigger values make a bigger punish.
  • events (list): List of events related to this class
@overrides
def create_tree(self, tree_ind, max_depth=5):
41	@overrides
42	def create_tree(self, tree_ind, max_depth=5):
43		"""
44		Create a random tree using the full method, and assign it to the given individual.
45
46		Parameters
47		----------
48		tree_ind: Tree
49			An individual of GP Tree representation with an initially empty tree
50
51		max_depth: int
52			Maximum depth of tree. The default is 5.
53
54		Returns
55		-------
56		None.
57		"""
58		self._create_tree(tree_ind, max_depth, 0)

Create a random tree using the full method, and assign it to the given individual.

Parameters
  • tree_ind (Tree): An individual of GP Tree representation with an initially empty tree
  • max_depth (int): Maximum depth of tree. The default is 5.
Returns
  • None.