Created
November 12, 2023 02:01
-
-
Save celsowm/c372b5594c220956e0a11f7b8e1e40a2 to your computer and use it in GitHub Desktop.
neural_network_plot_dinamico.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