public final class Centrality extends Object
Centrality indices serve to quantify an intuitive feeling that in most networks some nodes or edges are "more central" than others. The provided methods assign a double value to each node or edge of a graph that represents its centrality. The higher an assigned value, the more central the element is considered by the algorithm.
Also, this class provides convenience methods that normalize the returned centrality values such that they lie within
the interval [0,1]
.
Modifier and Type | Method and Description |
---|---|
static void |
closenessCentrality(Graph graph,
INodeMap closeness,
boolean directed,
IDataProvider edgeCosts)
Computes the closeness centrality for the nodes of a graph.
|
static void |
degreeCentrality(Graph graph,
INodeMap centrality,
boolean considerInEdges,
boolean considerOutEdges)
Computes the degree centrality for the nodes of a given graph.
|
static void |
edgeBetweenness(Graph graph,
IEdgeMap centrality,
boolean directed,
IDataProvider edgeCosts)
Computes betweenness centrality for each edge of a given graph.
|
static void |
graphCentrality(Graph graph,
INodeMap centrality,
boolean directed,
IDataProvider edgeCosts)
Computes the graph centrality for the nodes of a graph.
|
static void |
nodeBetweenness(Graph graph,
INodeMap centrality,
boolean directed,
IDataProvider edgeCosts)
Computes betweenness centrality for each node of a given graph.
|
static void |
nodeEdgeBetweenness(Graph graph,
INodeMap nodeCentrality,
IEdgeMap edgeCentrality,
boolean directed,
IDataProvider edgeCosts)
Computes betweenness centrality for each node and edge of a given graph.
|
static void |
normalize(Graph graph,
IEdgeMap map)
Normalizes the
double values of a given IEdgeMap by dividing each of them by the maximum of all values
(maximum norm). |
static void |
normalize(Graph graph,
INodeMap map)
Normalizes the
double values of a given INodeMap by dividing each of them by the maximum of all values
(maximum norm). |
static void |
weightCentrality(Graph graph,
INodeMap centrality,
boolean considerInEdges,
boolean considerOutEdges,
IDataProvider edgeWeights)
Computes the weight centrality for the nodes of a graph.
|
public static final void closenessCentrality(Graph graph, INodeMap closeness, boolean directed, IDataProvider edgeCosts)
Closeness centrality is defined as the reciprocal of the sum of shortest path distances of a node to all other
nodes in the graph. Therefore, a node with high closeness centrality has short distances to all other nodes of a graph.
If the sum of the shortest path distances is 0
, the closeness of a node is set to
Double.POSITIVE_INFINITY
.
connected
.O(graph.N()^2 + graph.N() * graph.E())
for unweighted graphsO((graph.N() * graph.E()) + graph.N()^2 * log(graph.N()))
for weighted graphsgraph
- the input graphcloseness
- the INodeMap
that will be filled during the execution and returns a double value (centrality) for each nodedirected
- true
if the graph should be considered as directed, false
otherwiseedgeCosts
- the IDataProvider
that returns a positive double value (cost) or null
if the edges are of equal costpublic static final void degreeCentrality(Graph graph, INodeMap centrality, boolean considerInEdges, boolean considerOutEdges)
Degree centrality is the number of the incoming, outgoing or overall edges incident to a node (measures incoming, outgoing and overall degree).
considerInEdges
and considerOutEdges
must be true
.O(graph.N())
graph
- the input graphcentrality
- the INodeMap
that will be filled during the execution and returns a double value (centrality) for each nodeconsiderInEdges
- true
if the incoming edges should be considered, false
otherwiseconsiderOutEdges
- true
if the outgoing edges should be considered, false
otherwisepublic static final void edgeBetweenness(Graph graph, IEdgeMap centrality, boolean directed, IDataProvider edgeCosts)
Betweenness centrality is a measure for how often an edge lies on a shortest path between each pair of nodes in the graph. Removing a central edge will cause many shortest paths to change.
O(graph.N() * graph.E())
for unweighted graphsO(graph.N() * (graph.E() + graph.N()) * log(graph.N())
for weighted graphsgraph
- the input graphcentrality
- the IEdgeMap
that will be filled during the execution and returns a double value (centrality) for each edgedirected
- true
if the graph should be considered as directed, false
otherwiseedgeCosts
- the IDataProvider
that returns a positive double value (cost) or null
if the edges are of equal cost;
for invalid input values the algorithm uses cost 1.0
public static final void graphCentrality(Graph graph, INodeMap centrality, boolean directed, IDataProvider edgeCosts)
Graph centrality is defined as the reciprocal of the maximum of all shortest path distances from a node to all other nodes in the graph. Nodes with high graph centrality have short distances to all other nodes in the graph.
INodeMap
must be given as input that returns for each Node
a zero value
that represents the initial closeness centrality.O(graph.N()^2 + graph.N() * graph.E())
for unweighted graphsO((graph.N() * graph.E()) + graph.N()^2 * log(graph.N()))
for weighted graphsgraph
- the input graphcentrality
- the INodeMap
that will be filled during the execution and returns a double value (centrality) for each nodedirected
- true
if the graph should be considered as directed, false
otherwiseedgeCosts
- the IDataProvider
that returns a positive double value (cost) or null
if the edges are of equal costpublic static final void nodeBetweenness(Graph graph, INodeMap centrality, boolean directed, IDataProvider edgeCosts)
Betweenness centrality is a measure for how often a node lies on a shortest path between each pair of nodes in the graph. Removing a central edge will cause many shortest paths to change.
O(graph.N() * graph.E())
for unweighted graphsO(graph.N() * (graph.E() + graph.N()) * log(graph.N())
for weighted graphsgraph
- the input graphcentrality
- the INodeMap
that will be filled during the execution and returns a double value (centrality) for each nodedirected
- true
if the graph should be considered as directed, false
otherwiseedgeCosts
- the IDataProvider
that returns a positive double value (cost) or null
if the edges are of equal cost;
for invalid input values the algorithm uses cost 1.0
public static final void nodeEdgeBetweenness(Graph graph, INodeMap nodeCentrality, IEdgeMap edgeCentrality, boolean directed, IDataProvider edgeCosts)
Betweenness centrality is a measure for how often a node/edge lies on a shortest path between each pair of nodes in the graph. Removing a central node/edge will cause many shortest paths to change.
O(graph.N() * graph.E())
for unweighted graphsO(graph.N() * (graph.E() + graph.N()) * log(graph.N())
for weighted graphsgraph
- the input graphnodeCentrality
- the INodeMap
that will be filled during the execution and returns a double value (centrality) for each nodeedgeCentrality
- the IEdgeMap
that will be filled during the execution and returns a double value (centrality) for each edgedirected
- true
if the graph should be considered as directed, false
otherwiseedgeCosts
- the IDataProvider
that returns a positive double value (cost) or null
if the edges are of equal cost;
for invalid input values the algorithm uses cost 1.0
public static final void normalize(Graph graph, IEdgeMap map)
double
values of a given IEdgeMap
by dividing each of them by the maximum of all values
(maximum norm).Double.POSITIVE_INFINITY
, all values other than Double.POSITIVE_INFINITY
are set
to 0
.e
: map.getDouble(e) >= 0
graph
- the input graphmap
- the IEdgeMap
that will be filled during the execution and returns a double value from [0,1]
intervalpublic static final void normalize(Graph graph, INodeMap map)
double
values of a given INodeMap
by dividing each of them by the maximum of all values
(maximum norm).Double.POSITIVE_INFINITY
, all values other than Double.POSITIVE_INFINITY
are set
to 0
.n
: map.getDouble(n) >= 0
graph
- the input graphmap
- the INodeMap
that will be filled during the execution and returns a double value from [0,1]
intervalpublic static final void weightCentrality(Graph graph, INodeMap centrality, boolean considerInEdges, boolean considerOutEdges, IDataProvider edgeWeights)
Weight centrality measures the weight associated with incoming, outgoing, or all edges of a node.
edgeWeights
is null
, then degreeCentrality
is invoked instead.O(graph.E())
graph
- the input graphcentrality
- the INodeMap
that will be filled during the execution and returns a double value (centrality) for each nodeconsiderInEdges
- true
if the incoming edges should be considered, false
otherwiseconsiderOutEdges
- true
if the outgoing edges should be considered, false
otherwiseedgeWeights
- the IDataProvider
that returns a positive double value (weight) or null
if the edges are considered to
have uniform weight of 1.0