Networkx中Betweenness与Current Flow Betweenness的weight参数含义问询
Great question—let’s break down exactly how these two NetworkX functions handle the weight parameter, and whether your approach is correct for your use case.
1. Betweenness Centrality (nx.betweenness_centrality)
Core Logic
This function calculates how often a node lies on the shortest path between all pairs of nodes. When you specify the weight parameter, NetworkX interprets this value as the cost or distance of traversing the edge. The algorithm prioritizes paths with the smallest total weight sum (i.e., "shortest" paths in terms of cumulative cost).
Your Usage: Correct for Your Scenario
Since your edge weights represent relationship strength (higher values = stronger, more preferred connections), using the raw weight would be counterproductive—high-weight edges would be treated as "longer" paths, so the algorithm would avoid them.
By passing the 'reciprocal' attribute (1/weight), you convert relationship strength into a cost metric: stronger edges become lower-cost paths. This ensures the algorithm prioritizes these edges, which means nodes on these high-strength paths get higher betweenness scores—exactly what you want.
Verifying Your Result
Looking at your example graph:
- The reciprocal weight for edge 1-2 is 0.05, while 1-3 is 1.
- The shortest path (by reciprocal weight) from 1 to 4 is
1->2->4(total cost: 0.05 + 1 = 1.05), not1->3->4(total cost: 1 + 1 = 2). - This is why node 2 has a betweenness score of 1.0 and node 3 has 0.0—perfectly aligning with your goal of rewarding nodes connected by stronger edges.
2. Current Flow Betweenness Centrality (nx.current_flow_betweenness_centrality)
Core Logic
This function models node importance using circuit theory: nodes are treated as nodes in an electrical circuit, and edges are conductors. Here, the weight parameter is interpreted as the conductance of the edge (higher conductance = easier for current to flow through the edge, equivalent to lower electrical resistance).
Your Usage: Correct for Your Scenario
Since your weights represent relationship strength, using the raw 'weight' parameter is the right choice. Higher strength translates to higher conductance, so more current flows through those edges. Nodes that lie on these high-conductance paths will have higher current flow betweenness scores, which matches your requirement.
Verifying Your Result
In your example:
- Edge 1-2 has the highest conductance (weight=20), so most current between node pairs (like 2↔3 or 2↔4) passes through nodes 1 and 2.
- This explains why nodes 1 and 2 have higher scores (~1.31) compared to nodes 3 and 4 (~0.69)—exactly what you’d expect for stronger connections.
Why Correlation Changes When Using the Same Weight Parameter
You noted that in larger graphs, using the same weight parameter (instead of reciprocal for betweenness) makes the two metrics more correlated. This is likely an accidental side effect of conflicting weight interpretations:
- For
betweenness_centrality, raw weights act as penalties (high strength = high cost, so edges are avoided). - For
current_flow_betweenness_centrality, raw weights act as rewards (high strength = high conductance, so edges are favored).
In some graph structures, these opposing effects might cancel out to produce more correlated scores, but this isn’t the correct usage for your goal. Your original approach (reciprocal for betweenness, raw weight for current flow) aligns with the algorithms’ design and your requirement that stronger edges contribute more to centrality.
内容的提问来源于stack exchange,提问作者Forinstance

