NetworkX

Previous topic

projected_graph

Next topic

collaboration_weighted_projected_graph

weighted_projected_graph

weighted_projected_graph(B, nodes, ratio=False)[source]

Return a weighted unipartite projection of B onto the nodes of one bipartite node set.

The weighted projected graph is the projection of the bipartite network B onto the specified nodes with weights representing the number of shared neighbors or the ratio between actual shared neighbors and possible shared neighbors if ratio=True [R110]. The nodes retain their names and are connected in the resulting graph if they have an edge to a common node in the original graph.

Parameters :

B : NetworkX graph

The input graph should be bipartite.

nodes : list or iterable

Nodes to project onto (the “bottom” nodes).

ratio: Bool (default=False) :

If True, edge weight is the ratio between actual shared neighbors and possible shared neighbors. If False, edges weight is the number of shared neighbors.

Returns :

Graph : NetworkX graph

A graph that is the projection onto the given nodes.

Notes

No attempt is made to verify that the input graph B is bipartite. The graph and node properties are (shallow) copied to the projected graph.

References

[R110](1, 2) Borgatti, S.P. and Halgin, D. In press. “Analyzing Affiliation Networks”. In Carrington, P. and Scott, J. (eds) The Sage Handbook of Social Network Analysis. Sage Publications.

Examples

>>> from networkx.algorithms import bipartite
>>> B = nx.path_graph(4)
>>> G = bipartite.weighted_projected_graph(B, [1,3])
>>> print(G.nodes())
[1, 3]
>>> print(G.edges(data=True))
[(1, 3, {'weight': 1})]
>>> G = bipartite.weighted_projected_graph(B, [1,3], ratio=True)
>>> print(G.edges(data=True))
[(1, 3, {'weight': 0.5})]