UltipaDocs
Try Playground
  • Introduction
    • Show Algorithms
    • Install and Uninstall
    • Run Algorithms
    • Algorithm Results and Statistics
    • Degree Centrality
    • Closeness Centrality
    • Harmonic Centrality
    • Graph Centrality
    • Betweenness Centrality
    • Eigenvector Centrality
    • CELF
    • PageRank
    • ArticleRank
    • 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
      • GraphSAGE
      • GraphSAGE Train
      • 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

✓ File Writeback ✓ Property Writeback ✓ Direct Return ✓ Stream Return ✓ Stats

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. Directed self-loop is regarded as an incoming edge 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

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

Syntax

  • Command: algo(degree)
  • Parameters:
NameType
Spec
Default
Optional
Description
ids / uuids[]_id / []_uuid//YesID/UUID of the nodes to calculate, calculate for all nodes if not set
edge_schema_property[]@<schema>?.<property>Numeric type, must LTE/YesEdge property(-ies) to use as edge weight(s), where the values of multiple properties are summed up
directionstringin, out/Yesin for in-degree, out for out-degree
limitint≥-1-1YesNumber of results to return, -1 to return all results
orderstringasc, desc/YesSort nodes by the size of degree

Examples

The example is a social network, edge property @follow.score can be used as weights:

File Writeback

SpecContent
filename_id,degree
UQL
algo(degree).params().write({
  file:{ 
    filename: 'degree_all'
  }
})

Statistics: total_degree = 20, average_degree = 2.25
Results: File degree_all

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

Property Writeback

SpecContentWrite toData Type
propertydegreeNode propertydouble
UQL
algo(degree).params({
  edge_schema_property: '@follow.score'
}).write({
  db:{ 
    property: 'degree'
  }
})

Statistics: total_degree = 40.4, average_degree = 5.05
Results: Degree for each node is written to a new property named degree, statistics is returned at the same time

Direct Return

Alias Ordinal
Type
DescriptionColumns
0[]perNodeNode and its degree_uuid, degree
1KVTotal and average degree of all nodestotal_degree, average_degree
UQL
algo(degree).params({ 
  edge_schema_property: '@follow.score',
  order: 'desc' 
}) as degree, stats
return degree, stats

Results: degree and stats

_uuiddegree
311.1
26.5
46.1
65.2
14.9
54.3
72.3
80
total_degreeaverage_degree
40.45.05

Stream Return

Alias Ordinal
Type
DescriptionColumns
0[]perNodeNode and its degree_uuid, degree

Example: Find 1-hop neighbors of the node with the highest degree, return all information of those neighbors

UQL
algo(degree).params({
  order: 'desc',
  limit: 1 
}).stream() as results
khop().src({_uuid == results._uuid}).depth(1) as neighbors
return neighbors{*}

Results: neighbors

_id_uuid
Bill7
Sam5
Joe4
Cathy2
Mike1

Stats Return

Alias Ordinal
Type
DescriptionColumns
0KVTotal and average degree of all nodestotal_degree, average_degree
UQL
algo(degree).params({
  direction: 'out'
}).stats() as stats
return stats

Results: stats

total_degreeaverage_degree
101.25