Created
November 11, 2023 22:49
-
-
Save celsowm/2839af52dab8a708bfdaace437bbce00 to your computer and use it in GitHub Desktop.
plot_neural_network.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
import matplotlib.pyplot as plt | |
def plot_neural_network(entrada, oculta, saida): | |
G = nx.DiGraph() | |
G.add_nodes_from([f'Entrada{i+1}' for i in range(entrada)]) | |
G.add_nodes_from([f'Oculta{i+1}' for i in range(oculta)]) | |
G.add_nodes_from([f'Saida{i+1}' for i in range(saida)]) | |
for e in range(entrada): | |
for h in range(oculta): | |
G.add_edge(f'Entrada{e+1}', f'Oculta{h+1}') | |
for h in range(oculta): | |
for s in range(saida): | |
G.add_edge(f'Oculta{h+1}', f'Saida{s+1}') | |
pos = {} | |
for i, node_type in enumerate(['Entrada', 'Oculta', 'Saida']): | |
for j in range(eval(node_type.lower())): | |
pos[f'{node_type}{j+1}'] = (i, j-(eval(node_type.lower())-1)/2) | |
nx.draw(G, pos, with_labels=True, node_size=800, node_color='skyblue', font_weight='bold', font_size=10) | |
plt.title('Representacao dos Neuronios da Rede Neural') | |
plt.show() | |
# Exemplo de uso para 2 nós de entrada, 3 nós na camada oculta e 1 nó de saída | |
plot_neural_network(3, 4, 1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment