In [1]:
import matplotlib.pyplot as plt
import networkx as nx
import pandas as pd
import numpy as np
from genome import Genome
%matplotlib inline
In [2]:
X = np.array([[0,0],[0,1],[1,0],[1,1]], dtype=np.float16)
Y = np.array([[0],[1],[1],[0]], dtype=np.float16)
data = X,Y
In [3]:
class Visualize(object):
'''
Mutate Visualization: Using PyGraphViz and Dot Syntax
'''
def __init__(self, GENOME):
self.nodes, self.connections = GENOME
def create(self):
'''
Create a directed graph from a Genome (Genotype)
'''
# Capture a List of Lists for in/out connections
connectionList = self.connections[['in','out']].values.tolist()
connectionList = [tuple(aList) for aList in connectionList]
return connectionList
# Cluster nodes by type
#sensorNodes = self.nodes.loc[self.nodes.type == ("sensor"),("node")].values.tolist()
#hiddenNodes = self.nodes.loc[self.nodes.type == ("hidden"),("node")].values.tolist()
#outputNodes = self.nodes.loc[self.nodes.type == ("output"),("node")].values.tolist()
# Create the dot syntax map
#graphString = ("digraph {")
#for ix,ele in enumerate(connectionList):
# graphString += (str(ele[0]) + "->" + str(ele[1]) + ";")
#graphString += ("}")
# Create the Graph
#G = nx.Graph(graphString, strict=False, directed=False, rankdir='LR')
#G.node_attr['shape']='circle'
#G.add_subgraph(sensorNodes, name='cluster_sensors', label="Sensor Nodes", rank="same")
#G.add_subgraph(hiddenNodes, name='cluster_hidden', label="Hidden Nodes")
#G.add_subgraph(outputNodes, name='cluster_output', label="Output Nodes", rank="same")
#imageResult = G.draw(format='png', prog='dot')
#return imageResult
In [4]:
options = {'node_color': 'black',
'edge_color': 'blue',
#'with_labels': True,
#'font_weight': 'bold',
'node_size': 1,
#'arrows': True,
'width': 0.025}
In [5]:
g = Genome(data)
GENOME = g.create()
v = Visualize(GENOME)
G = nx.Graph()
G.add_edges_from(v.create())
nx.draw(G, **options)
In [6]:
for _ in range(1000):
g.mutate(GENOME)
v = Visualize(GENOME)
G = nx.Graph()
G.add_edges_from(v.create())
nx.draw(G, **options)
In [ ]: