本文整理汇总了Python中networkx.algorithms.bipartite.projected_graph函数的典型用法代码示例。如果您正苦于以下问题:Python projected_graph函数的具体用法?Python projected_graph怎么用?Python projected_graph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了projected_graph函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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')])
开发者ID:argriffing,项目名称:networkx,代码行数:28,代码来源:test_project.py
示例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")])
开发者ID:ciarancourtney,项目名称:cloudify-trial,代码行数:28,代码来源:test_project.py
示例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)])
开发者ID:ciarancourtney,项目名称:cloudify-trial,代码行数:8,代码来源:test_project.py
示例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'])
开发者ID:argriffing,项目名称:networkx,代码行数:12,代码来源:test_project.py
示例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')])
开发者ID:argriffing,项目名称:networkx,代码行数:12,代码来源:test_project.py
示例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"])
开发者ID:ciarancourtney,项目名称:cloudify-trial,代码行数:12,代码来源:test_project.py
示例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()), [])
开发者ID:ciarancourtney,项目名称:cloudify-trial,代码行数:12,代码来源:test_project.py
示例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")])
开发者ID:ciarancourtney,项目名称:cloudify-trial,代码行数:12,代码来源:test_project.py
示例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
开发者ID:clayadavis,项目名称:pyphlow,代码行数:29,代码来源:pyphlow.py
示例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()
开发者ID:mapillary,项目名称:OpenSfM,代码行数:11,代码来源:tools.py
示例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()
开发者ID:niutyut,项目名称:cs224w-1,代码行数:12,代码来源:bipartite.py
示例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"
开发者ID:avyfain,项目名称:pg-essays,代码行数:23,代码来源:get_net.py
示例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))
开发者ID:ravleen24,项目名称:NetworkAnomalyDetection,代码行数:28,代码来源:numberOfComponents.py
示例14: folded_graph
def folded_graph(B):
bottom_nodes, top_nodes = bipartite.sets(B)
F = bipartite.projected_graph(B, top_nodes)
return F
开发者ID:pekzeki,项目名称:SNAofYelp,代码行数:6,代码来源:bipartite_db_friends.py
示例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"
开发者ID:tz18,项目名称:interlockingmoderatorship,代码行数:31,代码来源:networkxprojection.py
示例16: list
DG.add_node(directors.index(row['name']),label=row['name'],name=row['name'])
if row['cname'] not in companies:
companies.append(row['cname'])
DG.add_node(row['ocid'],label=row['cname'],name=row['cname'])
DG.add_edge(directors.index(row['name']),row['ocid'])
if reduce!=-1:
from networkx.algorithms import bipartite
officers,companies=bipartite.sets(DG)
#print list(officers)
#print list(companies)
if reduce=="officers":
#Collapse the bipartite graph to a graph of journalists connected via a common tag
OG= bipartite.projected_graph(DG, officers)
elif reduce=='companies':
#Collapse the bipartite graph to a set of tags connected via a common journalist
OG= bipartite.projected_graph(DG, companies)
else: OG=DG
else: OG=DG
'''
modularity=1
if modularity!=-1:
import community
partition = community.best_partition(G)
size = float(len(set(partition.values())))
pos = nx.spring_layout(G)
count = 0.
for com in set(partition.values()) :
开发者ID:flyeven,项目名称:scraperwiki-scraper-vault,代码行数:31,代码来源:opencorporates_trawler_gexf.py
示例17: load_stock
def load_stock(stock):
with open(PROCESSED_PATH+stock, 'r') as f:
return pickle.load(f)
def load_user(user):
with open(USER_PATH+user, 'r') as f:
return pickle.load(f)
stocks = {f: load_stock(f) for f in listdir(PROCESSED_PATH) if isfile(join(PROCESSED_PATH,f))}
users = {f: load_user(f) for f in listdir(USER_PATH) if isfile(join(USER_PATH, f))}
# Bipartite graphs in networkx are implemented using a normal graph where nodes have an attribute
# value of either 0 or 1 depending on which graph it belongs to
G = nx.Graph()
# Add all stocks
G.add_nodes_from(stocks.keys(), bipartite=0)
# Add all users
G.add_nodes_from(users.keys(), bipartite=1)
for (symbol, stock_tweets) in stocks.iteritems():
# Find the users that tweeted about this stock
user_ids = set([tweet.author.id_str for tweet in stock_tweets])
G.add_edges_from([(symbol, user) for user in user_ids if user in users.keys()])
# Create the user network from the bipartite network
stock_nodes = set(n for n,d in G.nodes(data=True) if d['bipartite']==0)
user_nodes = set(G) - stock_nodes
U = bipartite.projected_graph(G, user_nodes)
开发者ID:benzemann,项目名称:TwitterStockAnalyzer,代码行数:27,代码来源:bipartite_network.py
示例18: describe
def describe(self, extra=False):
"""
Provides a summary of graph statistics. Includes basic statistics like the number of nodes, edges,
denstiy, and the average degree for one mode. Prints a string that contains each of the items that make up the summary.
Density is calculated using one of the modes of the original bipartite network graph.
**Parameters** :
> *extra* : `bool`
>> Runs the low efficiency algorithms, which can be resource-intensive on large networks.
>> Recommended maximum network size for the low efficiency algorithms is around 100 nodes.
**Returns** : `string`
> Returns the descriptive string that contains information about the `MultiGraphPlus` object.
"""
mode1 = self.mode1
mode2 = self.mode2
density = bipartite.density(self, bipartite.sets(self)[0])
edges = self.number_of_edges()
nodes_mode1 = 0
nodes_mode2 = 0
for n in self.nodes():
if self.node[n]['type'] == mode1:
nodes_mode1 += 1
elif self.node[n]['type'] == mode2:
nodes_mode2 += 1
descriptives_nodes = "This is a bipartite network of types '{}' and '{}'.\n " \
"{} nodes are of the type '{}'.\n " \
"{} nodes are of the type '{}'.\n".format(str(mode1), str(mode2), str(nodes_mode1),
str(mode1), str(nodes_mode2), str(mode2))
descriptives_edges = "There are {} edges.\n".format(str(edges))
descriptives_density = "Density: {}.\n".format(str(density))
descriptives = descriptives_nodes + descriptives_edges + descriptives_density
if extra:
# Note: for each mode of the bipartite graph, degree and betweenness centrality are the same.
# Keeping them both makes it easy to compare them and make sure they are the same.
degree_mode1 = bipartite.degree_centrality(self, bipartite.sets(self)[0])
degree_mode2 = bipartite.degree_centrality(self, bipartite.sets(self)[1])
degree_mode1 = list(degree_mode1.values())
degree_mode2 = list(degree_mode2.values())
degree_mode1 = np.mean(degree_mode1)
degree_mode2 = np.mean(degree_mode2)
betweenness_mode1 = bipartite.betweenness_centrality(self, bipartite.sets(self)[0])
betweenness_mode1 = list(betweenness_mode1.values())
betweenness_mode1 = np.mean(betweenness_mode1)
betweenness_mode2 = bipartite.betweenness_centrality(self, bipartite.sets(self)[1])
betweenness_mode2 = list(betweenness_mode2.values())
betweenness_mode2 = np.mean(betweenness_mode2)
g = nx.Graph(self)
projection = bipartite.projected_graph(g, bipartite.sets(g)[0])
transitivity = nx.transitivity(projection)
descriptives_transitivity = "Transitivity: {}.\n".format(str(transitivity))
descriptives_degree_centrality = "Mean Degree Centrality for '{}': {}.\n" \
"Mean Degree Centrality for '{}': {}.\n".format(str(mode1),
str(degree_mode1),
str(mode2),
str(degree_mode2))
descriptives_btwn_centrality = "Mean Betweenness Centrality for '{}': {}.\n"\
"Mean Betweenness Centrality for '{}': {}.\n".format(str(mode1),
str(betweenness_mode1),
str(mode2),
str(betweenness_mode2))
descriptives = descriptives + descriptives_transitivity +\
descriptives_degree_centrality + descriptives_btwn_centrality
print(descriptives)
return descriptives
开发者ID:networks-lab,项目名称:gitnet,代码行数:71,代码来源:multigraph.py
示例19: len
tx.size()
disciplines = df.SC_l.unique()
techniques = {det for de in df.topics if de is not nan for det in de}
# <codecell>
df.SC_l
# <codecell>
len(techniques)
# <codecell>
disc = bi.projected_graph(tx, g2.nodes())
# <codecell>
sorted(disc.degree().iteritems(), key= operator.itemgetter(1))
# <markdowncell>
# ## Retrieving further literature if needed from WoS
# <codecell>
## generate searches that can be run back against WoS - it says it will take up to 5000 terms!
'"'+'" or "'.join([de for de,val in de_counts_sorted if val > 90 and val < 200]) + '"'
开发者ID:datapractice,项目名称:machinelearning,代码行数:29,代码来源:ML_literature.py
示例20: zip
df = df[(df[CREATE_GRAPH_OF].notnull()) & (df[LINKED_BY].notnull())]
print "[+] Removed null values..."
# Dedup
dd = df.groupby(columns).size().reset_index().rename(columns={0: 'w'})
print "[+] Created deduplicated dataset..."
# Creating the bipartite graph
G = nx.Graph()
G.add_nodes_from( dd[CREATE_GRAPH_OF].unique(), bipartite=0 )
G.add_nodes_from( dd[LINKED_BY].unique(), bipartite=1 )
G.add_edges_from( zip(dd[CREATE_GRAPH_OF], dd[LINKED_BY]) )
print "[+] Created bipartite graph..."
# Projecting the main projected graph
graph = bipartite.projected_graph(G, dd[CREATE_GRAPH_OF].unique(), multigraph=False)
print "[+] Created projected graph..."
# Outputting the corresponding data frame
d = pd.DataFrame(graph.edges())
d.columns = [CREATE_GRAPH_OF + '__1', CREATE_GRAPH_OF + '__2']
# Recipe outputs
print "[+] Writing output dataset..."
graph = dataiku.Dataset(output_name)
graph.write_with_schema(d)
开发者ID:AaronPetersBAH,项目名称:dataiku-contrib,代码行数:30,代码来源:recipe.py
注:本文中的networkx.algorithms.bipartite.projected_graph函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论