Weighted projection of B with a user-specified weight function.
The bipartite network B is projected on to the specified nodes with weights computed by a user-specified function. This function must accept as a parameter the neighborhood sets of two nodes and return an integer or a float.
The nodes retain their attributes and are connected in the resulting graph if they have an edge to a common node in the original graph.
Parameters : | B : NetworkX graph
nodes : list or iterable
weight_function: function :
|
---|---|
Returns : | Graph : NetworkX graph
|
See also
is_bipartite, is_bipartite_node_set, sets, weighted_projected_graph, collaboration_weighted_projected_graph, overlap_weighted_projected_graph, projected_graph
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.
Examples
>>> from networkx.algorithms import bipartite
>>> def jaccard(unbrs, vnbrs):
... return float(len(unbrs & vnbrs)) / len(unbrs | vnbrs)
...
>>> def shared(unbrs, vnbrs):
... return len(unbrs & vnbrs)
...
>>> B = nx.path_graph(5)
>>> G = bipartite.generic_weighted_projected_graph(B, [0, 2, 4], weight_function=jaccard)
>>> print(G.nodes())
[0, 2, 4]
>>> print(G.edges(data=True))
[(0, 2, {'weight': 0.5}), (2, 4, {'weight': 0.5})]
>>> G = bipartite.generic_weighted_projected_graph(B, [0, 2, 4], weight_function=shared)
>>> print(G.nodes())
[0, 2, 4]
>>> print(G.edges(data=True))
[(0, 2, {'weight': 1}), (2, 4, {'weight': 1})]