eckity.genetic_encodings.gp.tree.utils
This module implements some utility functions.
1""" 2This module implements some utility functions. 3""" 4 5 6def create_terminal_set(X): 7 """ 8 Create a terminal set from a 2D-shaped numpy array. 9 10 Example: \n 11 X = array([[ 4, 7, -7, -10], \n 12 [ 7, -3, 3, -8], \n 13 [ 8, -5, -3, -1]]) 14 15 Returns the list: \n 16 ['x0', 'x1', 'x2', 'x3'] 17 18 Parameters 19 ---------- 20 X : 2d numpy array 21 The array from which we wish to extract features -- which will become terminals. 22 23 Returns 24 ------- 25 Terminal set (a list). 26 27 """ 28 29 return [f'x{i}' for i in range(X.shape[1])] 30 31 32def _generate_args(X): 33 """ 34 Generate keyword arguments from a 2d array for passing to GPTree.execute. 35 36 Example: \n 37 X = array([[ 4, 7, -7, -10], \n 38 [ 7, -3, 3, -8], \n 39 [ 8, -5, -3, -1]]) 40 41 Returns the dict: \n 42 {'x0': array([4, 7, 8]), \n 43 'x1': array([ 7, -3, -5]), \n 44 'x2': array([-7, 3, -3]), \n 45 'x3': array([-10, -8, -1])} 46 47 Returns 48 ------- 49 kwargs : dict 50 A keyword dictionary that includes a value for every variable x_i in the terminal set. 51 52 """ 53 54 kwargs = dict() 55 for i in range(X.shape[1]): 56 kwargs[f'x{i}'] = X[:, i] 57 return kwargs
def
create_terminal_set(X):
7def create_terminal_set(X): 8 """ 9 Create a terminal set from a 2D-shaped numpy array. 10 11 Example: \n 12 X = array([[ 4, 7, -7, -10], \n 13 [ 7, -3, 3, -8], \n 14 [ 8, -5, -3, -1]]) 15 16 Returns the list: \n 17 ['x0', 'x1', 'x2', 'x3'] 18 19 Parameters 20 ---------- 21 X : 2d numpy array 22 The array from which we wish to extract features -- which will become terminals. 23 24 Returns 25 ------- 26 Terminal set (a list). 27 28 """ 29 30 return [f'x{i}' for i in range(X.shape[1])]
Create a terminal set from a 2D-shaped numpy array.
Example:
X = array([[ 4, 7, -7, -10],
[ 7, -3, 3, -8],
[ 8, -5, -3, -1]])
Returns the list:
['x0', 'x1', 'x2', 'x3']
Parameters
- X (2d numpy array): The array from which we wish to extract features -- which will become terminals.
Returns
- Terminal set (a list).