本文整理汇总了Python中networkx.algorithms.bipartite.projected_graph函数的典型用法代码示例。如果您正苦于以下问题:Python projected_graph函数的具体用法?Python projected_graph怎么用?Python projected_graph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了projected_graph函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_directed_projection
def test_directed_projection(self):
G=nx.DiGraph()
G.add_edge('A',1)
G.add_edge(1,'B')
G.add_edge('A',2)
G.add_edge('B',2)
P=bipartite.projected_graph(G,'AB')
assert_edges_equal(list(P.edges()),[('A','B')])
P=bipartite.weighted_projected_graph(G,'AB')
assert_edges_equal(list(P.edges()),[('A','B')])
assert_equal(P['A']['B']['weight'],1)
P=bipartite.projected_graph(G,'AB',multigraph=True)
assert_edges_equal(list(P.edges()),[('A','B')])
G=nx.DiGraph()
G.add_edge('A',1)
G.add_edge(1,'B')
G.add_edge('A',2)
G.add_edge(2,'B')
P=bipartite.projected_graph(G,'AB')
assert_edges_equal(list(P.edges()),[('A','B')])
P=bipartite.weighted_projected_graph(G,'AB')
assert_edges_equal(list(P.edges()),[('A','B')])
assert_equal(P['A']['B']['weight'],2)
P=bipartite.projected_graph(G,'AB',multigraph=True)
assert_edges_equal(list(P.edges()),[('A','B'),('A','B')])
示例2: test_directed_projection
def test_directed_projection(self):
G = nx.DiGraph()
G.add_edge("A", 1)
G.add_edge(1, "B")
G.add_edge("A", 2)
G.add_edge("B", 2)
P = bipartite.projected_graph(G, "AB")
assert_equal(sorted(P.edges()), [("A", "B")])
P = bipartite.weighted_projected_graph(G, "AB")
assert_equal(sorted(P.edges()), [("A", "B")])
assert_equal(P["A"]["B"]["weight"], 1)
P = bipartite.projected_graph(G, "AB", multigraph=True)
assert_equal(sorted(P.edges()), [("A", "B")])
G = nx.DiGraph()
G.add_edge("A", 1)
G.add_edge(1, "B")
G.add_edge("A", 2)
G.add_edge(2, "B")
P = bipartite.projected_graph(G, "AB")
assert_equal(sorted(P.edges()), [("A", "B")])
P = bipartite.weighted_projected_graph(G, "AB")
assert_equal(sorted(P.edges()), [("A", "B")])
assert_equal(P["A"]["B"]["weight"], 2)
P = bipartite.projected_graph(G, "AB", multigraph=True)
assert_equal(sorted(P.edges()), [("A", "B"), ("A", "B")])
示例3: test_path_projected_graph
def test_path_projected_graph(self):
G = nx.path_graph(4)
P = bipartite.projected_graph(G, [1, 3])
assert_equal(sorted(P.nodes()), [1, 3])
assert_equal(sorted(P.edges()), [(1, 3)])
P = bipartite.projected_graph(G, [0, 2])
assert_equal(sorted(P.nodes()), [0, 2])
assert_equal(sorted(P.edges()), [(0, 2)])
示例4: test_path_projected_properties_graph
def test_path_projected_properties_graph(self):
G=nx.path_graph(4)
G.add_node(1,name='one')
G.add_node(2,name='two')
P=bipartite.projected_graph(G,[1,3])
assert_nodes_equal(list(P),[1,3])
assert_edges_equal(list(P.edges()),[(1,3)])
assert_equal(P.node[1]['name'],G.node[1]['name'])
P=bipartite.projected_graph(G,[0,2])
assert_nodes_equal(list(P),[0,2])
assert_edges_equal(list(P.edges()),[(0,2)])
assert_equal(P.node[2]['name'],G.node[2]['name'])
示例5: test_project_multigraph
def test_project_multigraph(self):
G=nx.Graph()
G.add_edge('a',1)
G.add_edge('b',1)
G.add_edge('a',2)
G.add_edge('b',2)
P=bipartite.projected_graph(G,'ab')
assert_edges_equal(list(P.edges()),[('a','b')])
P=bipartite.weighted_projected_graph(G,'ab')
assert_edges_equal(list(P.edges()),[('a','b')])
P=bipartite.projected_graph(G,'ab',multigraph=True)
assert_edges_equal(list(P.edges()),[('a','b'),('a','b')])
示例6: test_path_projected_properties_graph
def test_path_projected_properties_graph(self):
G = nx.path_graph(4)
G.add_node(1, name="one")
G.add_node(2, name="two")
P = bipartite.projected_graph(G, [1, 3])
assert_equal(sorted(P.nodes()), [1, 3])
assert_equal(sorted(P.edges()), [(1, 3)])
assert_equal(P.node[1]["name"], G.node[1]["name"])
P = bipartite.projected_graph(G, [0, 2])
assert_equal(sorted(P.nodes()), [0, 2])
assert_equal(sorted(P.edges()), [(0, 2)])
assert_equal(P.node[2]["name"], G.node[2]["name"])
示例7: test_star_projected_graph
def test_star_projected_graph(self):
G = nx.star_graph(3)
P = bipartite.projected_graph(G, [1, 2, 3])
assert_equal(sorted(P.nodes()), [1, 2, 3])
assert_equal(sorted(P.edges()), [(1, 2), (1, 3), (2, 3)])
P = bipartite.weighted_projected_graph(G, [1, 2, 3])
assert_equal(sorted(P.nodes()), [1, 2, 3])
assert_equal(sorted(P.edges()), [(1, 2), (1, 3), (2, 3)])
P = bipartite.projected_graph(G, [0])
assert_equal(sorted(P.nodes()), [0])
assert_equal(sorted(P.edges()), [])
示例8: test_project_multigraph
def test_project_multigraph(self):
G = nx.Graph()
G.add_edge("a", 1)
G.add_edge("b", 1)
G.add_edge("a", 2)
G.add_edge("b", 2)
P = bipartite.projected_graph(G, "ab")
assert_edges_equal(P.edges(), [("a", "b")])
P = bipartite.weighted_projected_graph(G, "ab")
assert_edges_equal(P.edges(), [("a", "b")])
P = bipartite.projected_graph(G, "ab", multigraph=True)
assert_edges_equal(P.edges(), [("a", "b"), ("a", "b")])
示例9: block_cutpoint_tree
def block_cutpoint_tree(G, projected=False, verbose=False):
input_graph = Graph(G)
top_nodes = []
bottom_nodes = []
articulation_points = set(nx.articulation_points(input_graph))
if verbose:
print "Articulation points:", articulation_points
for biconnected_component in nx.biconnected_components(input_graph):
inter = biconnected_component.intersection(articulation_points)
if verbose:
print "Inter:", inter
top_nodes.extend(
[json.dumps(sorted(biconnected_component)) for _ in inter]
)
#top_nodes.extend([G.subgraph(bcc) for _ in inter])
bottom_nodes.extend([x for x in inter])
#bottom_nodes.extend([G.subgraph(x) for x in inter])
if verbose:
print "Top nodes:", top_nodes
print "Bottom nodes:", bottom_nodes
edges = zip(top_nodes, bottom_nodes)
if verbose:
print "Edges:", edges
bc_tree = Graph()
bc_tree.add_edges_from(edges)
if projected:
return Graph(bipartite.projected_graph(bc_tree, top_nodes))
else:
return bc_tree
示例10: connected_reconstructions
def connected_reconstructions(reconstruction_shots):
g = nx.Graph()
for r in reconstruction_shots:
g.add_node(r, bipartite=0)
for shot_id in reconstruction_shots[r]:
g.add_node(shot_id, bipartite=1)
g.add_edge(r, shot_id)
p = bipartite.projected_graph(g, reconstruction_shots.keys())
return p.edges()
示例11: main
def main():
G = initialize()
user, business = node_initialize(G)
user = list(set(user) & set(G.nodes()))
business = list(set(business) & set(G.nodes()))
G = make_bipartite(G, user, business)
print nx.is_bipartite(G)
G = list(nx.connected_component_subgraphs(G))[0]
user, business = bipartite.sets(G)
print "nodes separated"
Gu = bipartite.projected_graph(G, user)
print Gu.number_of_nodes()
示例12: main
def main():
G=nx.Graph()
with open('clean_essays.csv', 'rb') as csvfile:
readerz = csv.reader(csvfile, delimiter=',')
for row in readerz:
title = row[0]
thnx = row[3].replace(' and', ',').replace(', ', ',').split(',')
people = [x.strip() for x in thnx if (x!=' ' and x!='')]
G.add_node(title, klass='essay')
for p in people:
if p != 'None':
G.add_node(p, klass='person')
G.add_edge(p, title)
p_nodes = [n for n,d in G.nodes_iter(data=True) if d['klass']=='person']
e_nodes = [n for n,d in G.nodes_iter(data=True) if d['klass']=='essay']
BP = bipartite.projected_graph(G,p_nodes)
BE = bipartite.projected_graph(G,e_nodes)
nx.write_gml(BP, 'people.gml')
nx.write_gml(BE, 'essays.gml')
print "Done"
示例13: len
for line in readFile:
length = len(line.split(","))
srcIp = line.split(",")[1]
destIp = line.split(",")[length -2]
keyVal = srcIp+"-"+destIp;
if keyVal not in edgeMap:
edgeMap[keyVal] = True
edgeArr.append((srcIp,destIp))
validNodes.append(srcIp)
srcNodes = list(set(srcNodes)- (set(srcNodes) - set(validNodes)))
G.add_edges_from(edgeArr)
PG = bipartite.projected_graph(G,srcNodes)
listVal = nx.connected_components(PG)
for el in listVal:
length = len(el)
if length < 5:
continue
print(length)
# print(nx.number_connected_components(G))
# print(nx.number_connected_components(PG))
示例14: folded_graph
def folded_graph(B):
bottom_nodes, top_nodes = bipartite.sets(B)
F = bipartite.projected_graph(B, top_nodes)
return F
示例15: len
count += 1
return Sum / count
print "is bottom_nodes a bipartite set?",bipartite.is_bipartite_node_set(G, bottom_nodes)
print "is top_nodesa bipartite set?",bipartite.is_bipartite_node_set(G, top_nodes)
print len(bottom_nodes)," bottom nodes",len(top_nodes)," top nodes"
print "Average subreddits moderated per moderator: ",mymean(G.degree_iter(bottom_nodes))
print "Average moderators per subreddit: ",mymean(G.degree_iter(top_nodes))
if export:
nx.write_gexf(G,"C:\\Users\\Theseus\\Documents\\moderatorproject\\untouched.gexf")
print "gexf exported"
pg1 = bipartite.projected_graph(G, bottom_nodes)
print "Unweighted moderator to moderator projection made"
print "Average unweighted degree: ",mymean(pg1.degree_iter())
if export:
nx.write_gexf(pg1,"C:\\Users\\Theseus\\Documents\\moderatorproject\\bottoms.gexf")
print "gexf exported"
pg2 = bipartite.projected_graph(G, top_nodes)
print "Unweighted subreddit to subreddit projection made"
print "Average unweighted degree: ",mymean(pg2.degree_iter())
if export:
nx.write_gexf(pg2,"C:\\Users\\Theseus\\Documents\\moderatorproject\\tops.gexf")
print "gexf exported"
wpg1 = bipartite.weighted_projected_graph(G, bottom_nodes)
print "Weighted bottom node projection made"