Ejemplo n.º 1
0
def create_search_space(input_shape=(2,), output_shape=(3,), *args, **kwargs):

    ss = KSearchSpace(input_shape, output_shape)
    x = ss.input_nodes[0]

    out_xor = ConstantNode(op=Dense(1, activation="sigmoid"), name="XOR")

    out_and = ConstantNode(op=Dense(1, activation="sigmoid"), name="AND")
    ss.connect(x, out_and)

    out_or = ConstantNode(op=Dense(1, activation="sigmoid"), name="OR")
    ss.connect(x, out_or)

    in_xor = VariableNode(name="in_XOR")
    in_xor.add_op(Concatenate(ss, [x]))
    in_xor.add_op(Concatenate(ss, [x, out_and]))
    in_xor.add_op(Concatenate(ss, [x, out_or]))
    in_xor.add_op(Concatenate(ss, [x, out_and, out_or]))
    ss.connect(in_xor, out_xor)

    out = ConstantNode(name="OUT")
    out.set_op(Concatenate(ss, stacked_nodes=[out_xor, out_and, out_or]))

    return ss
Ejemplo n.º 2
0
    def test_create_multiple_inputs_with_one_vnode(self):
        from deephyper.search.nas.model.space import KSearchSpace
        from deephyper.search.nas.model.space.node import VariableNode, ConstantNode
        from deephyper.search.nas.model.space.op.op1d import Dense
        from deephyper.search.nas.model.space.op.merge import Concatenate
        struct = KSearchSpace([(5, ), (5, )], (1, ))

        merge = ConstantNode()
        merge.set_op(Concatenate(struct, struct.input_nodes))

        vnode1 = VariableNode()
        struct.connect(merge, vnode1)

        vnode1.add_op(Dense(1))

        struct.set_ops([0])

        struct.create_model()
Ejemplo n.º 3
0
    def set_output_node(self, graph, output_nodes):
        """Set the output node of the search_space.

        Args:
            graph (nx.DiGraph): graph of the search_space.
            output_nodes (Node): nodes of the current search_space without successors.

        Returns:
            Node: output node of the search_space.
        """
        if len(output_nodes) == 1:
            node = ConstantNode(op=Identity(), name='Structure_Output')
            graph.add_node(node)
            graph.add_edge(output_nodes[0], node)
        else:
            node = ConstantNode(name='Structure_Output')
            op = Concatenate(self, output_nodes)
            node.set_op(op=op)
        return node
Ejemplo n.º 4
0
def create_search_space(
        input_shape=(2, ), output_shape=(3, ), *args, **kwargs):

    ss = KSearchSpace(input_shape, output_shape)
    x = ss.input_nodes[0]

    out_xor = ConstantNode(op=Dense(1), name="XOR")
    ss.connect(x, out_xor)

    out_and = ConstantNode(op=Dense(1), name="AND")
    ss.connect(x, out_and)

    out_or = ConstantNode(op=Dense(1), name="OR")
    ss.connect(x, out_or)

    out = ConstantNode(name="OUT")
    out.set_op(Concatenate(ss, stacked_nodes=[out_xor, out_and, out_or]))

    return ss
Ejemplo n.º 5
0
def create_structure(input_shape=[(1, ), (942, ), (5270, ), (2048, )], output_shape=(1,), num_cells=2, *args, **kwargs):

    struct = AutoOutputStructure(input_shape, output_shape, regression=True)
    input_nodes = struct.input_nodes

    output_submodels = [input_nodes[0]]

    for i in range(1, 4):
        vnode1 = VariableNode('N1')
        add_mlp_op_(vnode1)
        struct.connect(input_nodes[i], vnode1)

        vnode2 = VariableNode('N2')
        add_mlp_op_(vnode2)
        struct.connect(vnode1, vnode2)

        vnode3 = VariableNode('N3')
        add_mlp_op_(vnode3)
        struct.connect(vnode2, vnode3)

        output_submodels.append(vnode3)

    merge1 = ConstantNode(name='Merge')
    merge1.set_op(Concatenate(struct, merge1, output_submodels))

    vnode4 = VariableNode('N4')
    add_mlp_op_(vnode4)
    struct.connect(merge1, vnode4)

    prev = vnode4

    for i in range(num_cells):
        vnode = VariableNode(f'N{i+1}')
        add_mlp_op_(vnode)
        struct.connect(prev, vnode)

        merge = ConstantNode(name='Merge')
        merge.set_op(AddByPadding(struct, merge, [vnode, prev]))

        prev = merge


    return struct
Ejemplo n.º 6
0
def create_structure(input_shape=[(1, ), (942, ), (5270, ), (2048, )],
                     output_shape=(1, ),
                     num_cells=2,
                     *args,
                     **kwargs):

    struct = AutoOutputStructure(input_shape, output_shape, regression=True)
    input_nodes = struct.input_nodes

    output_submodels = [input_nodes[0]]

    for i in range(1, 4):
        cnode1 = ConstantNode(name='N', op=Dense(1000, tf.nn.relu))
        struct.connect(input_nodes[i], cnode1)

        cnode2 = ConstantNode(name='N', op=Dense(1000, tf.nn.relu))
        struct.connect(cnode1, cnode2)

        cnode3 = ConstantNode(name='N', op=Dense(1000, tf.nn.relu))
        struct.connect(cnode2, cnode3)

        output_submodels.append(cnode3)

    merge1 = ConstantNode(name='Merge')
    merge1.set_op(Concatenate(struct, merge1, output_submodels))

    cnode4 = ConstantNode(name='N', op=Dense(1000, tf.nn.relu))
    struct.connect(merge1, cnode4)

    prev = cnode4

    for i in range(num_cells):
        cnode = ConstantNode(name='N', op=Dense(1000, tf.nn.relu))
        struct.connect(prev, cnode)

        merge = ConstantNode(name='Merge')
        merge.set_op(AddByPadding(struct, merge, [cnode, prev]))

        prev = merge

    return struct
Ejemplo n.º 7
0
def create_search_space(
        input_shape=(2, ), output_shape=(5, ), *args, **kwargs):

    ss = KSearchSpace(input_shape, output_shape)
    x = ss.input_nodes[0]

    nunits = 10

    hid_2 = ConstantNode(op=Dense(nunits, "relu"), name="hid_2")
    out_2 = ConstantNode(op=Dense(1), name="out_2")
    ss.connect(hid_2, out_2)

    hid_3 = ConstantNode(op=Dense(nunits, "relu"), name="hid_3")
    out_3 = ConstantNode(op=Dense(1), name="out_3")
    ss.connect(hid_3, out_3)

    hid_4 = ConstantNode(op=Dense(nunits, "relu"), name="hid_4")
    out_4 = ConstantNode(op=Dense(1), name="out_4")
    ss.connect(hid_4, out_4)

    hid_5 = ConstantNode(op=Dense(nunits, "relu"), name="hid_5")
    out_5 = ConstantNode(op=Dense(1), name="out_5")
    ss.connect(hid_5, out_5)

    hid_6 = ConstantNode(op=Dense(nunits, "relu"), name="hid_6")
    out_6 = ConstantNode(op=Dense(1), name="out_6")
    ss.connect(hid_6, out_6)

    # L1 DEPENDENT ON DATA OVERALL
    in_2 = VariableNode(name="in_2")
    in_2.add_op(Concatenate(ss, [x]))
    in_2.add_op(Concatenate(ss, [x, out_3]))
    in_2.add_op(Concatenate(ss, [x, out_4]))
    in_2.add_op(Concatenate(ss, [x, out_5]))
    in_2.add_op(Concatenate(ss, [x, out_6]))

    ss.connect(in_2, hid_2)

    # L2 DEPENDANT ON DATA, L1 AND L3
    in_3 = VariableNode(name="in_3")
    in_3.add_op(Concatenate(ss, [x, out_2]))
    in_3.add_op(Concatenate(ss, [x, out_4]))

    ss.connect(in_3, hid_3)

    # L3 DEPENDANT ON DATA, L1 L2 AND WIDTH
    in_4 = VariableNode(name="in_4")
    in_4.add_op(Concatenate(ss, [x]))
    in_4.add_op(Concatenate(ss, [x, out_2]))
    in_4.add_op(Concatenate(ss, [x, out_3]))
    in_4.add_op(Concatenate(ss, [x, out_5]))
    in_4.add_op(Concatenate(ss, [x, out_6]))
    in_4.add_op(Concatenate(ss, [x, out_2, out_3]))
    in_4.add_op(Concatenate(ss, [x, out_2, out_5]))
    in_4.add_op(Concatenate(ss, [x, out_2, out_6]))
    in_4.add_op(Concatenate(ss, [x, out_3, out_5]))
    in_4.add_op(Concatenate(ss, [x, out_3, out_6]))
    in_4.add_op(Concatenate(ss, [x, out_5, out_6]))
    in_4.add_op(Concatenate(ss, [x, out_3, out_5, out_6]))
    in_4.add_op(Concatenate(ss, [x, out_2, out_5, out_6]))
    in_4.add_op(Concatenate(ss, [x, out_2, out_3, out_6]))
    in_4.add_op(Concatenate(ss, [x, out_2, out_3, out_5]))
    in_4.add_op(Concatenate(ss, [x, out_2, out_3, out_5, out_6]))

    ss.connect(in_4, hid_4)

    # HEIGHT DEPENDANT ON ALL MEASURES COMBINED AND DATA
    in_5 = VariableNode(name="in_5")
    in_5.add_op(Concatenate(ss, [x]))
    in_5.add_op(Concatenate(ss, [x, out_2]))
    in_5.add_op(Concatenate(ss, [x, out_3]))
    in_5.add_op(Concatenate(ss, [x, out_4]))
    in_5.add_op(Concatenate(ss, [x, out_6]))
    in_5.add_op(Concatenate(ss, [x, out_2, out_3]))
    in_5.add_op(Concatenate(ss, [x, out_2, out_4]))
    in_5.add_op(Concatenate(ss, [x, out_2, out_6]))
    in_5.add_op(Concatenate(ss, [x, out_3, out_4]))
    in_5.add_op(Concatenate(ss, [x, out_3, out_6]))
    in_5.add_op(Concatenate(ss, [x, out_4, out_6]))
    in_5.add_op(Concatenate(ss, [x, out_3, out_4, out_6]))
    in_5.add_op(Concatenate(ss, [x, out_2, out_4, out_6]))
    in_5.add_op(Concatenate(ss, [x, out_2, out_3, out_6]))
    in_5.add_op(Concatenate(ss, [x, out_2, out_3, out_4]))
    in_5.add_op(Concatenate(ss, [x, out_2, out_3, out_4, out_6]))
    ss.connect(in_5, hid_5)

    # WIDTH DEPENDANT ON DATA AND CROSS SECTION
    in_6 = VariableNode(name="in_6")
    in_6.add_op(Concatenate(ss, [x]))
    in_6.add_op(Concatenate(ss, [x, out_2]))
    in_6.add_op(Concatenate(ss, [x, out_3]))
    in_6.add_op(Concatenate(ss, [x, out_4]))
    in_6.add_op(Concatenate(ss, [x, out_5]))
    ss.connect(in_6, hid_6)

    out = ConstantNode(name="OUT")
    out.set_op(
        Concatenate(ss, stacked_nodes=[out_2, out_3, out_4, out_5, out_6]))

    return ss