Exemple #1
0
    def setUp(self):
        self.n1 = node.Node()
        self.n2 = node.Node()
        self.n3 = node.Node()
        self.n4 = node.Node()
        self.n5 = node.Node()
        self.n6 = node.Node()

        self.f1 = node.Function(2)
        self.f2 = node.Function(3)
        # ``function_dict'' is not separated based on kinds of nodes
        # such as non-terminal nodes or terminal nodes here.
        self.function_dict = {0: self.f1, 1: self.f2}
Exemple #2
0
def get_add():
    """
    Build and get an "add" function.
    :return: function object.
    """
    def add_func(x):
        return np.nan_to_num(x[0] + x[1])

    return node.Function(2, add_func)
Exemple #3
0
def get_sin():
    """
    Build and get an "sin" function.
    :return: function object.
    """
    def sin_func(x):
        return np.sin(x[0])

    return node.Function(1, sin_func)
Exemple #4
0
def get_x(dim_i):
    """
    get function of x.
    :return: function object.
    """
    def x_func(x):
        return x[:, dim_i]

    return node.Function(0, x_func)
Exemple #5
0
def get_div():
    """
    Build and get an "div" function.
    :return: function object.
    """
    def div_func(x):
        return np.nan_to_num(x[0] / x[1])

    return node.Function(2, div_func)
Exemple #6
0
def get_mul():
    """
    Build and get an "mul" function.
    :return: function object.
    """
    def mul_func(x):
        return np.nan_to_num(x[0] * x[1])

    return node.Function(2, mul_func)
Exemple #7
0
def get_sub():
    """
    Build and get an "sub" function.
    :return: function object.
    """
    def sub_func(x):
        return np.nan_to_num(x[0] - x[1])

    return node.Function(2, sub_func)
Exemple #8
0
def get_val(val=1.0):
    """
    get function of constant.
    :param val: float. value of constant.
    :return: function object.
    """
    def val_func(x):
        return np.array([val for _ in range(len(x))], float)

    return node.Function(0, val_func)
Exemple #9
0
def get_x(dim_i):
    """
    get function of i-th elements in x.
    :param dim_i: int. target dimension.
    :return: function object.
    """

    def x_func(x):
        return x[:, dim_i]
    return node.Function(0, x_func)
Exemple #10
0
    def setUp(self):
        self.n1 = node.Node(0)
        self.n2 = node.Node(1)
        self.n3 = node.Node(0)
        self.n4 = node.Node(1)
        self.n5 = node.Node(0)
        self.n6 = node.Node(1)

        self.f1 = node.Function(2)
        self.f2 = node.Function(3)
        # ``function_dict'' is not separated based on kinds of nodes
        # such as non-terminal nodes or terminal nodes here.
        self.function_dict = {0: self.f1, 1: self.f2}

        node.set_children(self.n1, [self.n2, self.n3])
        node.set_children(self.n2, [self.n4, self.n5, self.n6])

        self.s1 = solution.Solution(self.n1)
        self.depth = 2
        self.n_nodes = 6
Exemple #11
0
def get_and(n_children=2):
    """
    Build and get an "and" function.
    :param n_children: int. the number of children.
    :return: function object.
    """
    def and_func(x):
        result = x[0]
        for i in range(len(x)-1):
            result = np.logical_and(result, x[i+1])
        return result

    return node.Function(n_children, and_func)
Exemple #12
0
def get_nor(n_children=2):
    """
    Build and get a "nor" function.
    :param n_children: int. the number of children.
    :return: function object.
    """
    def nor_func(x):
        result = x[0]
        for i in range(len(x)-1):
            result = np.logical_or(result, x[i+1])
        result = np.logical_not(result)
        return result

    return node.Function(n_children, nor_func)
Exemple #13
0
def f_non_terminal(n_children=2):
    def print_non_terminal(x):
        print('non_terminal')

    return node.Function(n_children, print_non_terminal)
Exemple #14
0
def f_terminal():
    def print_terminal(x):
        print('terminal')

    return node.Function(0, print_terminal)
Exemple #15
0
def f_terminal(n_children=0):
    def print_terminal(x):
        print('terminal')

    return node.Function(n_children, print_terminal)