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. Connectivity & Compactness

K-Hop All

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

Overview

The K-Hop All algorithm identifies the neighborhood of each node within a graph. This algorithm finds extensive application in various scenarios, including relationship discovery, impact prediction, and friend suggestion.

The K-Hop All algorithm can be considered as the batch execution of the UQL K-Hop Query.

Considerations

Although the K-Hop All algorithm is optimized for high concurrency performance, it is important to note that this algorithm may require significant computational resources when dealing with large graphs (those with tens of millions of nodes or edges), or graphs containing many super nodes. To optimize performance, it is advisable to avoid performing K-Hop All calculation that is excessively deep, considering the specific characteristics and size of the graph being analyzed.

NOTE

In graph G = (V, E), if |V|/|E|=100, querying the 5-hop neighbors of a node requires a theoretical computational complexity of 105 (equivalent to 10 billion computations), which would take approximately 100ms. Extrapolating from this, completing such a query in a graph with 10 million nodes would require 1 million seconds (equivalent to around 12 days). It's important to consider the computational demands and time requirements when working with graphs of this scale.

Syntax

  • Command: algo(khop_all)
  • Parameters:
Name
Type
Spec
Default
Optional
Description
ids / uuids[]_id / []_uuid//YesID/UUID of the target nodes to perform k-hop queries, target all nodes if not set
k_startint>= 11YesStarting depth of the k-hop query, the querying depth is [k_start, k_end]
k_endint>= 11YesEnding depth of the k-hop query, the querying depth is [k_start, k_end]
directionstringin, out/YesAll edge directions in the querying path
node_property[]@<schema>?.<property>Numeric type, must LTE/YesNode properties to perform aggregations; this option must be used with aggregate_opt
aggregate_opt[]stringmax, min, mean, sum, var, dev/YesThe aggregation methods to perform on the values of the specified node properties; this option must be used with node_property, with each method corresponds to one property

max: maximum, min: minimum, mean: average, sum: sum, var: variance, dev: standard deviation
src_includeint0, 10Yes1 means to include every target node in its querying and aggregation results, 0 means not to include
limitint≥-1-1YesNumber of results to return, -1 to return all results

Examples

The example is a transaction network between bank cards:

File Writeback

Spec
ContentDescription
filename_ids_id,_idThe first _id represents the target node, the second _id represents the neighbor of the target node
filename_id,aggregate_result1,...,aggregate_resultN,count_id represents the target node, aggregate_result1 ~ aggregate_resultN are the aggregation results, the last count is the total number of neighbors of the target node
UQL
algo(khop_all).params({
  ids: ['card1', 'card7'],
  k_start: 2,
  k_end: 3,
  direction: 'out',
  node_property: ['@card.level', '@card.balance'],
  aggregate_opt: ['max', 'mean']
}).write({
  file:{
    filename_ids: 'neighbors',
    filename: 'aggregations'
  }
})

Results: Files neighbors, aggregations

File: neighbors
card1,card7
card1,card3
card1,card4
card7,card4
File: aggregations
card1,4.000000,3174.103333,3.000000,
card7,2.000000,4768.800000,1.000000,

Property Writeback

SpecContentWrite toData Type
propertyNumber of neighborsNode propertydouble
UQL
algo(khop_all).params({ 
  k_start: 2,
  k_end: 2
}).write({
  db:{ 
    property: 'khop2'
  }
})

Results: The number of 2-hop neighbors of each node is written to a new property named khop2

Direct Return

Alias OrdinalType
Description
Columns
0[]perNodeNode and its aggregation results, and number of neighbors_uuid, value
UQL
algo(khop_all).params({
  ids: ['card1', 'card7'],
  k_start: 2,
  k_end: 3,
  node_property: ['@card.level', '@card.balance'],
  aggregate_opt: ['max', 'mean']
}) as r
return r

Results: r

_uuidvalue
15.000000,6884.060000,6.000000,
75.000000,7361.870000,5.000000,

Stream Return

Alias OrdinalType
Description
Columns
0[]perNodeNode and its aggregation results, and number of neighbors_uuid, value
UQL
algo(khop_all).params({
   uuids: [2],
   k_start: 2,
   k_end: 2,
   node_property: '@card.balance',
   aggregate_opt: 'max'
}).stream() as results 
return results

Results: results

_uuidvalue
227123.800000,2.000000,