Overview
Graph centrality of a node is measured by the maximum shortest distance from the node to all other reachable nodes. This measurement, along with other measurements like closeness centrality and graph diameter, can be considered jointly to determine whether a node is literally located at the very center of the graph.
Graph centrality takes on values between 0 to 1, nodes with higher scores are closer to the center.
Concepts
Shortest Distance
The shortest distance of two nodes is the number of edges contained in the shortest path between them. Please refer to Closeness Centrality for more details.
Graph Centrality
Graph centrality score of a node defined by this algorithm is the inverse of the maximum shortest distance from the node to all other reachable nodes. The formula is:
where x
is the target node, y
is any node that connects with x
along edges (x
itself is excluded), d(x,y)
is the shortest distance between x
and y
.
In this graph, the green number and red number next to each node is the shortest distance between the node and the green node and red node. Graph centrality scores of the green and red nodes are 1/4 = 0.25
and 1/3 = 0.3333
respectively.
Regarding closeness centrality, the green node has score 8/(1+1+1+1+2+3+4+3) = 0.5
, the red node has score 8/(3+3+3+2+1+1+2+1) = 0.5
. When two nodes have the same closeness centrality score, graph centrality can be viewed as the subsidiary basis to determine which node is closer to the center.
Considerations
- The graph centrality score of isolated nodes is 0.
- The Graph Centrality algorithm ignores the direction of edges but calculates them as undirected edges.
Parameters
Name |
Type |
Spec |
Default |
Optional |
Description |
---|---|---|---|---|---|
project |
String | / | / | / | The projection on which the algorithm will run. This is required for writeback modes but not applicable to return modes. |
ids |
[]_id |
/ | / | Yes | Specifies nodes by their _id values for computation; computes for all nodes if it is unset. |
uuids |
[]_uuid |
/ | / | Yes | Specifies nodes by their _uuid values for computation; computes for all nodes if it is unset. |
direction |
String | in , out |
/ | Yes | Specifies direction of edges in each shortest path, with in for incoming direction, out for outgoing direction; ignores direction if not set. |
return_id_uuid |
String | uuid , id , both |
uuid |
Yes | Includes _uuid , _id , or both values for nodes in the results. |
limit |
Integer | ≥-1 | -1 |
Yes | Limits the number of results returned; -1 includes all results. |
order |
String | asc , desc |
/ | Yes | Sorts nodes by their centrality scores. |
Example Graph
To create this graph:
// Runs each row separately in order in an empty graphset
create().node_schema("user").edge_schema("vote")
insert().into(@user).nodes([{_id:"A"},{_id:"B"},{_id:"C"},{_id:"D"},{_id:"E"},{_id:"F"},{_id:"G"},{_id:"H"},{_id:"I"},{_id:"J"}])
insert().into(@vote).edges([{_from:"A", _to:"B"}, {_from:"A", _to:"C"}, {_from:"A", _to:"D"}, {_from:"E", _to:"A"}, {_from:"E", _to:"F"}, {_from:"F", _to:"G"}, {_from:"F", _to:"I"}, {_from:"G", _to:"H"}, {_from:"H", _to:"I"}])
Running on HDC Projections
Creating HDC Projections
To project the entire graph to the HDC server hdc-server-1
as hdc_graph_centrality
:
hdc.graph.create("hdc_graph_centrality", {
nodes: {"*": ["*"]},
edges: {"*": ["*"]},
direction: "undirected",
load_id: true,
update: "static",
query: "query",
default: true
}).to("hdc-server-1")
File Writeback
algo(graph_centrality).params({
project: "hdc_graph_centrality",
return_id_uuid: "id"
}).write({
file: {
filename: "graph_centrality"
}
})
Results:
_id,graph_centrality
C,0.2
I,0.25
G,0.25
A,0.25
E,0.333333
J,0
D,0.2
F,0.333333
H,0.2
B,0.2
DB Writeback
Writes the graph_centrality
values from the results to the specified node property. The property type is float
.
algo(graph_centrality).params({
project: "hdc_graph_centrality"
}).write({
db:{
property: 'gc'
}
})
Full Return
exec{
algo(graph_centrality).params({
return_id_uuid: "id",
ids: ["A","B","C"],
order: "asc"
}) as r
return r
} on hdc_graph_centrality
Results:
_id | graph_centrality |
---|---|
B | 0.2 |
C | 0.2 |
A | 0.25 |
Stream Return
exec{
algo(graph_centrality).params({
return_id_uuid: "id"
}).stream() as gc
where gc.graph_centrality > 0.25
return gc
} on hdc_graph_centrality
Results:
_id | graph_centrality |
---|---|
E | 0.333333 |
F | 0.333333 |