def showPath(self, highlight=None): # with open(self.verticesFn,'a') as Vwr: # with open(self.edgesFn,'a') as Ewr: # for i in range(8): # Vwr.write('\nc0_' + `i` + ', ') # Ewr.write('\np8_0_t,' + 'c0_' + `i` + ',c') # highlight['c0_'+`i`] = [0.69, 0.0, 0.498] # start = datetime.datetime.now() edge_data = SFrame.read_csv(self.edgesFn) vertex_data = SFrame.read_csv(self.verticesFn) g = SGraph(vertices=vertex_data, edges=edge_data, vid_field='name', src_field='src', dst_field='dst') # end = datetime.datetime.now() # print (end - start) # g.show(vlabel='attributes', elabel='relation', h_offset=0.3,v_offset=-0.025, highlight=highlight, arrows=True) # highLight g.show(vlabel='attributes', vlabel_hover=False, elabel='relation', highlight=highlight, arrows=True) # highLight sleep(20) pass
def showPath(self, highlight=None): edge_data = SFrame.read_csv(self.edgesFn) vertex_data = SFrame.read_csv(self.verticesFn) g = SGraph(vertices=vertex_data, edges=edge_data, vid_field='name', src_field='src', dst_field='dst') g.show(vlabel='id', elabel='relation', highlight=highlight, arrows=True) # highLight sleep(10) pass
def showPath(self, highlight=None): # start = datetime.datetime.now() edge_data = SFrame.read_csv(self.edgesFn) vertex_data = SFrame.read_csv(self.verticesFn) g = SGraph(vertices=vertex_data, edges=edge_data, vid_field='name', src_field='src', dst_field='dst') # end = datetime.datetime.now() # print (end - start) # g.show(vlabel='attributes',vlabel_hover=True, elabel='relation', h_offset=0.3,v_offset=-0.025, highlight=highlight, arrows=True) # highLight g.show(vlabel='id', elabel='relation', vlabel_hover=True, highlight=highlight, arrows=True) # highLight sleep(30) pass
#g = SGraph(vertices=vertex_data, edges=edge_data, vid_field='name', # src_field='src', dst_field='dst') #targets = ['James Bond', 'Moneypenny'] #subgraph = g.get_neighborhood(ids=targets, radius=1, full_subgraph=True) #subgraph.show(vlabel='id', highlight=['James Bond', 'Moneypenny'], arrows=True) #from graphlab import SGraph, Vertex, Edge #g = SGraph() #verts = [Vertex(0, attr={'breed': 'labrador'}), # Vertex(1, attr={'breed': 'labrador'}), # Vertex(2, attr={'breed': 'vizsla'})] #g = g.add_vertices(verts) #g = g.add_edges(Edge(1, 2)) #print g from graphlab import SFrame, SGraph edge_data = SFrame.read_csv('http://s3.amazonaws.com/dato-datasets/bond/bond_edges.csv') vertex_data = SFrame.read_csv('http://s3.amazonaws.com/dato-datasets/bond/bond_vertices.csv') g = SGraph(vertices=vertex_data, edges=edge_data, vid_field='name',src_field='src', dst_field='dst') #print g g.show()
def main(): g = SGraph() verts = [] #initialize the Karate graph with unique label fields for each node for i in range(0, 34): verts.append(Vertex(i, attr={'label': str(i)})) g = g.add_vertices(verts) #prepare the path for the Karate network data fname = "./karate.txt" #read the edges from Karate.txt and add them to the SGraph object with open(fname) as f: for l in f: #print(l) #parse the src and dst ids for the next edge ids = l.split() src = int(ids[0]) dst = int(ids[1]) #add the edge as a graphlabl.Edge object to the graph g = g.add_edges(Edge(src, dst)) #visualize the graph #print(g.summary()) #randId=rn.sample(range(0,34),1)[0] #print(randId) #test = g.get_vertices(fields={'label':'1'})[randId] #test.show() #print(test) ids = range(0, 34) #label propagation loop flag = False iteration = 0 #rounds=5 #initialize neigh dict for performance gns = {} cur_max = 0 start = time.time() #start=time.time() while flag == False: #pick vertice iteration order randomly rn.shuffle(ids) flag = True #print(ids) start = time.time() for index in ids: #print(index) cur_max = LPA(g, index) if str(cur_max) != g.get_vertices(ids=[index])['label'][0]: flag = False g.vertices['label'] = g.vertices.apply(lambda x: str( cur_max) if x['__id'] == index else x['label']) #print(end-start) iteration += 1 print(iteration) end = time.time() #end=time.time() print(end - start) print iteration g.show(vlabel='label')
#targets = ['James Bond', 'Moneypenny'] #subgraph = g.get_neighborhood(ids=targets, radius=1, full_subgraph=True) #subgraph.show(vlabel='id', highlight=['James Bond', 'Moneypenny'], arrows=True) #from graphlab import SGraph, Vertex, Edge #g = SGraph() #verts = [Vertex(0, attr={'breed': 'labrador'}), # Vertex(1, attr={'breed': 'labrador'}), # Vertex(2, attr={'breed': 'vizsla'})] #g = g.add_vertices(verts) #g = g.add_edges(Edge(1, 2)) #print g from graphlab import SFrame, SGraph edge_data = SFrame.read_csv( 'http://s3.amazonaws.com/dato-datasets/bond/bond_edges.csv') vertex_data = SFrame.read_csv( 'http://s3.amazonaws.com/dato-datasets/bond/bond_vertices.csv') g = SGraph(vertices=vertex_data, edges=edge_data, vid_field='name', src_field='src', dst_field='dst') #print g g.show()
import graphlab as gl from graphlab import SFrame, SGraph, Vertex, Edge edge_data = SFrame.read_csv( 'http://s3.amazonaws.com/dato-datasets/bond/bond_edges.csv') g = SGraph() g = g.add_edges(edge_data, src_field='src', dst_field='dst') print g g.save('james_bond') new_graph = gl.load_sgraph('james_bond') g.show(vlabel='id', highlight=['James Bond', 'Moneypenny'], arrows=True)