本文整理汇总了Python中igraph.Graph.delete_vertices方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.delete_vertices方法的具体用法?Python Graph.delete_vertices怎么用?Python Graph.delete_vertices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类igraph.Graph
的用法示例。
在下文中一共展示了Graph.delete_vertices方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LFR
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import delete_vertices [as 别名]
class LFR ( BaseInputGraph ):
def __init__(self, trialval=1):
ws = []
edges = []
self.trial = trialval
with open("./binary_networks/mu0.5/network%d.dat" % self.trial, "r") as txt:
for line in txt:
seg = line.split()
edges.append((int(seg[0]), int(seg[1])))
ws.append(1)
maxid = max( edges, key=itemgetter(1))[1]
maxid = max( maxid, max(edges,key=itemgetter(0))[0] )
self.g = Graph()
print maxid
self.g.add_vertices(maxid + 1)
with open("./binary_networks/mu0.5/community%d.dat" % self.trial, "r") as txt:
for line in txt:
seg = line.split()
#print seg[0]
self.g.vs[int(seg[0])]["comm"] = seg[1] #note: string is returned
self.g.add_edges(edges)
self.g.to_undirected()
self.g.simplify()
self.g.delete_vertices(0)
self.g.es["weight"] = ws
BaseInputGraph.write_ground_truth(self, "./ground_truth_community%d.groups" % self.trial)
print "#nodes=", maxid + 1
print "#edges=", len(self.g.es)
def run(self):
#supervised
C = []
for i in range(6):
commval = str(random.randint(0,100))
group = [i for i, comm in enumerate(self.g.vs["comm"]) if comm == commval]
C += BaseInputGraph.get_C(self, group)
#unsupervised
C = BaseInputGraph.unsupervised_logexpand(self)
BaseInputGraph.run(self, C, p0=np.array([1 , 1]))
BaseInputGraph.results(self, Graph.community_fastgreedy, hasgnc = False,\
filename="%d" %self.trial)
示例2: len
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import delete_vertices [as 别名]
print "graph contains ", len(g.es), "edges"
print "graph contains ", len(g.vs), "vertices"
# filterOutNoise(edge)
minDegree = 5
for e in g.es:
if e["weight"] < 10000.0:
g.delete_edges(e)
for x in range(8):
print "removing:"
for v in g.vs:
if v.degree() < minDegree:
g.delete_vertices(v)
print "graph contains ", len(g.es), "edges"
print "graph contains ", len(g.vs), "vertices"
drawPNG = True
if drawPNG:
print "drawing begins:"
layout = g.layout('kk')
width, height = 5000, 5000
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
ctx = cairo.Context(surface)
ctx.scale(width, height)
ctx.rectangle(0, 0, 1, 1)
ctx.set_source_rgba(0, 0, 0, 0)
ctx.fill()
示例3: Pathway
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import delete_vertices [as 别名]
class Pathway(object):
""" Pathway object """
def __init__(self, name):
"""
Initializes the variables of the object.
Name is needed, all other variables will be initialized later if needed.
"""
self.name = name
self.commname = ''
self.rlst = [] #list of principal reactions, aligned with primlst
self.elst = [] #list of enzymes catalyzing the pathway
self.srlst = []
self.rnlst = []
self.primlst = [] #list of (inel,outel), where inel/outel are list of strings themselves
self.sclst = []
self.splst = []
self.todo = []
self.substrates = [] #counted with multiplicities
self.byproducts = [] #counted with multiplicities
self.finished = False
self.primgraph = Graph(0,directed = True)
self.totgraph = Graph(0,directed = True)
def dependence(self, dic):
""" initializes the variables substrates, byproducts and elst: the dependence of the pathway """
for (j,prim) in enumerate(self.primlst):
r = self.rlst[j]
if prim[0][0] in r.inels:
self.substrates.extend(r.inels)
self.byproducts.extend(r.outels)
else:
self.substrates.extend(r.outels)
self.byproducts.extend(r.inels)
self.elst.extend(r.elst)
def appendr(self,r,prim):
""" append reaction and its primaries to the corresponding lists """
self.rlst.append(r)
self.primlst.append(prim)
def create_primgraph(self, filterlst):
""" initializes the self.primgraph variable: the primary component graph of the pathway p """
for (j,prim) in enumerate(self.primlst):
r = self.rlst[j]
vsearch(self.primgraph,r.name)
for i in prim[0]:
vsearch(self.primgraph,i.name)
self.primgraph.add_edges([(i.name,r.name)])
for o in prim[1]:
vsearch(self.primgraph,o.name)
self.primgraph.add_edges([(r.name,o.name)])
if self.primgraph.vcount() != 0:
vn = [v for v in self.primgraph.vs['name'][:] if v in filterlst]
if vn != []:
self.primgraph.delete_vertices(vn)
def create_totgraph(self, filterlst):
""" initializes the self.totgraph variable: the total graph of the pathway p """
for r in self.srlst:
vsearch(self.totgraph,r.name)
for i in r.innames:
vsearch(self.totgraph,i)
self.totgraph.add_edges([(i,r.name)])
for o in r.outnames:
vsearch(self.totgraph,o)
self.totgraph.add_edges([(r.name,o)])
if r.reversible == True:
vsearch(self.totgraph,r.name+'_r')
for i in r.innames:
self.totgraph.add_edges([(r.name+'_r',i)])
for o in r.outnames:
self.totgraph.add_edges([(o,r.name+'_r')])
if self.totgraph.vcount() != 0:
for vn in filterlst:
if vn in self.totgraph.vs['name'][:]:
self.totgraph.delete_vertices([vn])
inprimlst = [1 if name in self.primgraph.vs['name'][:] or name[0:len(name)-2] in self.primgraph.vs['name'][:] else 0 for name in self.totgraph.vs['name']]
self.totgraph.vs['inprim'] = inprimlst
pnamelst = [self.name if int(i) == 1 else '' for i in inprimlst]
self.totgraph.vs['pnamelst'] = pnamelst
示例4: extract_hash_tags_re
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import delete_vertices [as 别名]
continue
except ValueError as noJson:
noJsonCount = noJsonCount +1
continue
"""
Checking if node already exists in the list of name which is also indexed like id in igraph
so look up is fast
Everytime a new edge/node is touched update_ts is updated to the timestamp from the tweet
"""
text = text.lower()
hashtags = extract_hash_tags_re(text)
tweet_time = seconds_since_epoch(text.split('timestamp: ')[1].replace(')\n',''))
g.delete_edges(get_delete_old_edges(g,'updated_ts',tweet_time))
g.delete_vertices(get_isolated_nodes(g))
if len(hashtags) > 1:
tagSet = set(itertools.combinations(hashtags,2))
for frm, to in tagSet:
if frm not in g.vs['name'] and to not in g.vs['name']:
g.add_vertex(frm,updated_ts=tweet_time)
g.add_vertex(to,updated_ts=tweet_time)
g.add_edge(frm,to, updated_ts = tweet_time )
if frm not in g.vs['name'] and to in g.vs['name']:
g.add_vertex(frm,updated_ts=tweet_time)
g.add_edge(frm,to, updated_ts = tweet_time )
g.vs.find(to)['updated_ts'] = tweet_time
if frm in g.vs['name'] and to not in g.vs['name']:
示例5: part_three
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import delete_vertices [as 别名]
#.........这里部分代码省略.........
str(data_pts_thinned[index_cursor_point]))
path_points_ordered.append([])
# If no connection, still keep path_points_ordered same in
# size, need it at the end
else:
# Path exists
path_between_strokes = []
for _path_points in shortest_path[0]:
# shortest path contains an array of shortest paths,
# meaning there could be more than one,
# I take the first one, doesn't make any difference
# color_img[g.vs[_path_points]['point']] = [0,0,0]
path_points.append(g.vs[_path_points]['point'])
# Save path points so that we can delete them later on
path_between_strokes.append(
g.vs[_path_points]['point'])
# print 'start: ' + str(start_vertex['point'])
# print 'end: ' + str(end_vertex['point'])
# print 'path: ' + str(path_points)
path_points_ordered.append(path_between_strokes)
# 1st pass:
# Remove all points used in any path - except data points
path_points = list(set(path_points))
# Remove multiple entries first
for i in path_points:
if i not in valid_cursor_local:
g.delete_vertices(g.vs.find(point=i))
# 2nd pass:
# Remove isolated points
isolated_points = []
for i in range(0, len(g.vs)):
if len(g.incident(g.vs[i])) == 0:
isolated_points.append(g.vs[i]['point'])
for i in isolated_points:
g.delete_vertices(g.vs.find(point=i))
# color_img[i] = [0,0,0]
# 3rd pass:
# Originating from the cursor_positions, DFS? overkill to all
# possible positions
# Take care of the timing of these auxilary points - push other
# boundaries to make room for these
# Get List of cursor points that have something attached to them
for _cursor_no in range(0, len(valid_cursor_local)):
if valid_cursor_local[_cursor_no] in g.vs['point']:
# print 'index: ' + str(_cursor_no) + ' ' +
# str(valid_cursor_local[_cursor_no])
paths = g.shortest_paths_dijkstra(source=g.vs.find(
point=valid_cursor_local[_cursor_no]))
if len(paths) > 0: # result of shortest paths is a list of
# list with one outermost element
paths = paths[0]
missed_points = []
示例6: __init__
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import delete_vertices [as 别名]
class hash_tag_graph:
"""
hash tag graph class
"""
def __init__(self,window_duration=60,verbose=True):
"""
Initialize the class
:return: hash_tag_graph object
"""
self.t_window = window_duration
self.latest_time = 0
self.graph = Graph()
self.verbose=verbose
def trim(self):
"""
remove edges outside time window
:return: None
"""
# identify edges outside window
min_time = self.latest_time - self.t_window
edges_to_trim = self.graph.es.select(time_lt=min_time)
if self.verbose: print("Edges to trim: "+str(edges_to_trim))
# remove edges outside of t_window
self.graph.delete_edges(edges_to_trim)
# identify vertices with 0 degree to delete
vertices_to_trim = self.graph.vs.select(_degree=0)
if self.verbose: print("Vertices to trim: "+str(vertices_to_trim._name_index))
self.graph.delete_vertices(vertices_to_trim)
def add_tweet(self,hash_tag_tuple,epoch_time):
"""
Adds tweet to hash tag graph and updates graph such that it only contains tweets
withing window_duration of the latest in time tweet. If tweet is outside of the window_duration
than it is not added to the graph and nothing happens
:return:
"""
# Check if tweet is in order, inside the window duration, or outside
t_diff = self.latest_time - epoch_time > self.t_window
if t_diff <= self.t_window:
self.latest_time = max(epoch_time,self.latest_time)
current_vertices = self.graph.vs._name_index
if self.verbose:
print('Graph name index: '+str(current_vertices))
print('Graph name index type: '+str(type(current_vertices)))
# current vertivces will have none type when it is initilazed empty
if current_vertices is not None:
# Add hashtag to graph as vertex, if its already exists, nothing happens
for hash_tag in hash_tag_tuple:
# only add hashtag if it isn't already in the graph
if hash_tag not in current_vertices:
if self.verbose: print("Adding Vertex: "+str(hash_tag))
self.graph.add_vertex(name=hash_tag)
else:
# Add hashtag to graph as vertex, if its already exists, nothing happens
for hash_tag in hash_tag_tuple:
if self.verbose: print("Adding Vertex: "+str(hash_tag))
self.graph.add_vertex(name=hash_tag)
# Add edges with associated epoch time
for edge in combinations(hash_tag_tuple,r=2):
if self.verbose: print('Adding Edge Pair:'+str(edge)+" Time:"+str(epoch_time))
self.graph.add_edge(source=edge[0],target=edge[1],time=epoch_time)
self.trim()
# if tweet is outside of the time window than toss it
else:
return
return
def get_mean_degree(self):
"""
Compute the average degree
#.........这里部分代码省略.........