UltipaDocs
Try Playground
  • Introduction
  • Managing HDC Graphs
  • Managing Distributed Projections
  • Installing Algorithms
  • Running Algorithms
    • Degree Centrality
    • Closeness Centrality
    • Harmonic Centrality
    • Graph Centrality
    • Betweenness Centrality
    • Eigenvector Centrality
    • Katz Centrality
    • CELF
    • PageRank
    • ArticleRank
    • TextRank
    • HITS
    • SybilRank
    • Jaccard Similarity
    • Overlap Similarity
    • Cosine Similarity
    • Pearson Correlation Coefficient
    • Euclidean Distance
    • K-Hop All
    • Bipartite Graph
    • HyperANF
    • Connected Component
    • Triangle Counting
    • Induced Subgraph
    • k-Core
    • k-Truss
    • p-Cohesion
    • k-Edge Connected Components
    • Local Clustering Coefficient
    • Topological Sort
    • Schema Overview
    • Dijkstra's Single-Source Shortest Path
    • Delta-Stepping Single-Source Shortest Path
    • Shortest Path Faster Algorithm (SPFA)
    • Minimum Spanning Tree
    • Breadth-First Search (BFS)
    • Depth-First Search (DFS)
    • Adamic-Adar Index
    • Common Neighbors
    • Preferential Attachment
    • Resource Allocation
    • Total Neighbors
    • Louvain
    • Leiden
    • Label Propagation
    • HANP
    • k-Means
    • kNN (k-Nearest Neighbors)
    • K-1 Coloring
    • Conductance
      • Random Walk
      • Node2Vec Walk
      • Node2Vec
      • Struc2Vec Walk
      • Struc2Vec
      • LINE
      • Fast Random Projection
      • Summary of Graph Embedding
      • Gradient Descent
      • Backpropagation
      • Skip-gram
      • Skip-gram Optimization
  1. Docs
  2. /
  3. Graph Analytics & Algorithms
  4. /
  5. Centrality

Degree Centrality

HDC Distributed

Overview

The Degree Centrality algorithm is used to find important nodes in the network, it measures the number of incoming and/or outgoing edges incident to the node, or the sum of weights of those edges. Degree is the simplest and most efficient graph algorithm since it only considers the 1-hop neighborhood of nodes. Degree plays a vital role in scientific computing, feature extraction, supernode recognition and other fields.

Concepts

In-Degree and Out-Degree

The number of incoming edges a node has is called its in-degree; accordingly, the number of outgoing edges is called out-degree. If ignores edge direction, it is degree.

In this graph, the red node has in-degree of 4 and out-degree of 3, and its degree is 7. A directed self-loop is regarded as both an incoming and an outgoing edge.

Weighted Degree

In many applications, each edge of a graph has an associated numeric value, called weight. In weighted graph, weighted degree of a node is the sum of weights of all its neighbor edges. Unweighted degree is equivalent to when all edge weights are 1.

In this weighted graph, the red node has weighted in-degree of 0.5 + 0.3 + 2 + 1 = 3.8 and weighted out-degree of 1 + 0.2 + 2 = 3.2, and its weighted degree is 3.2 + 3.8 = 7.

Considerations

  • The degree of an isolated node depends only on its self-loop. If it has no self-loop, degree is 0.
  • Every self-loop is counted as two edges attaching to its node. Directed self-loop is viewed as an incoming edge and an outgoing edge.

Example Graph

Run the following statements on an empty graph to define its structure and insert data:

ALTER GRAPH CURRENT_GRAPH ADD NODE {
  user ()
};
ALTER GRAPH CURRENT_GRAPH ADD EDGE {
  follow ()-[{score float}]->()
};
INSERT (Mike:user {_id: "Mike"}),
       (Cathy:user {_id: "Cathy"}),
       (Anna:user {_id: "Anna"}),
       (Joe:user {_id: "Joe"}),
       (Sam:user {_id: "Sam"}),
       (Bob:user {_id: "Bob"}),
       (Bill:user {_id: "Bill"}),
       (Tim:user {_id: "Tim"}),
       (Mike)-[:follow {score: 1.9}]->(Cathy),
       (Cathy)-[:follow {score: 1.8}]->(Mike),
       (Mike)-[:follow {score: 1.2}]->(Anna),
       (Cathy)-[:follow {score: 2.6}]->(Anna),
       (Cathy)-[:follow {score: 0.2}]->(Joe),
       (Joe)-[:follow {score: 4.2}]->(Anna),
       (Bob)-[:follow {score: 1.7}]->(Joe),
       (Sam)-[:follow {score: 3.5}]->(Bob),
       (Sam)-[:follow {score: 0.8}]->(Anna),
       (Bill)-[:follow {score: 2.3}]->(Anna);

Running on HDC Graphs

Creating HDC Graph

To load the entire graph to the HDC server hdc-server-1 as my_hdc_graph:

CREATE HDC GRAPH my_hdc_graph ON "hdc-server-1" OPTIONS {
  nodes: {"*": ["*"]},
  edges: {"*": ["*"]},
  direction: "undirected",
  load_id: true,
  update: "static"
}

Parameters

Algorithm name: degree

Name
Type
Spec
Default
Optional
Description
ids[]_id//YesSpecifies nodes for computation by their _id. If unset, computation includes all nodes.
uuids[]_uuid//YesSpecifies nodes for computation by their _uuid. If unset, computation includes all nodes.
edge_schema_property[]"<@schema.?><property>"//YesSpecifies numeric edge properties used to compute weighted degrees by summing their values. Only properties of numeric type are considered, and edges without these properties are ignored.
directionStringin, out/YesSpecifies in for in-degrees, out for out-degrees. If unset, general degree is computed.
return_id_uuidStringuuid, id, bothuuidYesIncludes _uuid, _id, or both values in the results to represent nodes.
limitInteger≥-1-1YesLimits the number of results returned. Set to -1 to include all results.
orderStringasc, desc/YesSorts the results by degree_centrality.

File Writeback

algo(degree).params({
  projection: "my_hdc_graph",
  return_id_uuid: "id",
  order: "desc"
}).write({
  file: {
    filename: "degree"
  }
})

Result:

File: degree
_id,degree_centrality
Anna,5
Cathy,4
Joe,3
Mike,3
Bob,2
Sam,2
Bill,1
Tim,0

DB Writeback

Writes the degree_centrality values from the results to the specified node property. The property type is double.

CALL algo.degree.write("my_hdc_graph", {
  edge_schema_property: 'score'
}, {
  db: {
    property: "degree"
  }
})

Full Return

CALL algo.degree.run("my_hdc_graph", {
  edge_schema_property: 'score',
  return_id_uuid: "id",
  order: 'desc'
}) YIELD r
RETURN r

Result:

_iddegree_centrality
Anna11.1
Cathy6.5
Joe6.1
Bob5.2
Mike4.9
Sam4.3
Bill2.3
Tim0

Stream Return

To find neighbors of the node with the highest out-degree:

CALL algo.degree.stream("my_hdc_graph", {
  direction: "out",
  order: "desc",
  limit: 1
}) YIELD outTop1
MATCH (src WHERE src._uuid = outTop1._uuid)-(neigh)
RETURN DISTINCT neigh._id

Result:

neigh._id
Anna
Joe
Mike

Running on Distributed Projections

Creating Distributed Projection

To project the entire graph to its shard servers as myProj:

CREATE PROJECTION myProj OPTIONS {
  nodes: {"*": ["*"]}, 
  edges: {"*": ["*"]},
  direction: "undirected",
  load_id: true
}

Parameters

Algorithm name: degree

Name
Type
Spec
Default
Optional
Description
edge_schema_property"<@schema.?><property>"//YesSpecifies numeric edge properties used to compute weighted degrees. Only properties of numeric type are considered, and edges without these properties are ignored.
directionStringin, out/YesSpecifies in for in-degrees, out for out-degrees. If unset, general degree is computed.
limitInteger≥-1-1YesLimits the number of results returned. Set to -1 to include all results.
orderStringasc, desc/YesSorts the results by degree_centrality.

File Writeback

algo(degree).params({
  projection: "myProj",
  order: "desc"
}).write({
  file: {
    filename: "degree"
  }
})

Result:

File: degree
_id,degree_centrality
Anna,5
Cathy,4
Joe,3
Mike,3
Bob,2
Sam,2
Bill,1
Tim,0

DB Writeback

Writes the degree_centrality values from the results to the specified node property. The property type is double.

CALL algo.degree.write("myProj", {
  edge_schema_property: 'score'
}, {
  db: {
    property: "degree"
  }
})