def box_with_connectable(text, box_size, box_loc, node_spacing, hidden_layer_node_num, box_colour='#55CC77'): # the box nb = NodeBrush('box', size=size) nb.size = box_size nb.color = box_colour nodes3 = viznet.node_sequence(nb, 1, box_loc, space=node_spacing) nodes3[0].text(text, 'right', fontsize=font_size_small) # the connectable-invisible nodes nb = NodeBrush('invisible', size=box_size[1]) # box_size[1] is the height of box # nb = NodeBrush([ # None, # "rectangle", # "none" # ], size=box_size[1]) # box_size[1] is the height of box invis = viznet.node_sequence(nb, hidden_layer_node_num, box_loc, space=node_spacing) return nodes3, invis
def box_with_connectable(text, box_size, box_loc, node_spacing, hidden_layer_node_num, box_colour='lime', text_pos='right', text_kwargs={}): # def box_with_connectable(text, box_size, box_loc, node_spacing, hidden_layer_node_num, box_colour='#55CC77'): # the box nb = NodeBrush('box', size=size) nb.size = box_size nb.color = box_colour nodes3 = viznet.node_sequence(nb, 1, box_loc, space=node_spacing) text_colour = box_colour if box_colour == 'lime': text_colour = 'green' if box_colour == 'grey': text_colour = 'black' nodes3[0].text(text, text_pos, fontsize=font_size_small, color=text_colour) # the connectable-invisible nodes nb = NodeBrush('invisible', size=box_size[1]) # box_size[1] is the height of box # nb = NodeBrush([ # None, # "rectangle", # "none" # ], size=box_size[1]) # box_size[1] is the height of box invis = viznet.node_sequence(nb, hidden_layer_node_num, box_loc, space=node_spacing) return nodes3, invis
def draw_feed_forward(ax, num_node_list, size=2): ''' draw a feed forward neural network. Args: num_node_list (list<int>): number of nodes in each layer. ''' num_hidden_layer = len(num_node_list) - 2 token_list = ['\sigma^z'] + \ ['y^{(%s)}' % (i + 1) for i in range(num_hidden_layer)] + ['\psi'] kind_list = ['nn.input'] + ['nn.hidden'] * num_hidden_layer + ['nn.output'] radius_list = [0.3] + [0.2] * num_hidden_layer + [0.3] y_list = 1.5 * np.arange(len(num_node_list)) text_list = ['$\phi$'] * 3 seq_list = [] for n, kind, radius, y, text in zip(num_node_list, kind_list, radius_list, y_list, text_list): b = NodeBrush(kind) _nodes = viznet.node_sequence(b, n, center=(0, y)) for _n in _nodes: _n.text(text, 'center', fontsize=18) # print(_nodes) seq_list.append(_nodes) eb = EdgeBrush('<--') for st, et in zip(seq_list[:-1], seq_list[1:]): viznet.connecta2a(st, et, eb) # viznet.node_sequence(NodeBrush('box', ax, size=size), 1, (0,4)) # node = NodeBrush('box', size=size) node.size = (0.5, 0.3) viznet.node_sequence(node, 1, (0, ))