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

Local Clustering Coefficient

HDC

Overview

The Local Clustering Coefficient algorithm calculates the density of connection among the immediate neighbors of a node. It quantifies the ratio of actual connections among the neighbors to the maximum possible connections.

The local clustering coefficient provides insights into the cohesion of a node's ego network. In the context of a social network, the local clustering coefficient helps understand the degree of interconnectedness among an individual's friends or acquaintances. A high local clustering coefficient suggests that the person's friends are likely to be connected to each other, indicating the presence of a closely-knit social group, such as a family. Conversely, a low local clustering coefficient indicates a more dispersed or loosely interconnected ego network, where the person's friends do not have strong connections with each other.

Concepts

Local Clustering Coefficient

Mathematically, the local clustering coefficient of a node in an undirected graph is calculated as the ratio of the number of connected neighbor pairs to the total number of possible neighbor pairs:

where n is the number of nodes contained in the 1-hop neighborhood of node v (denoted as N(v)), i and j are any two distinct nodes within N(v), δ(i,j) is equal to 1 if i and j are connected, and 0 otherwise.

In this example, the local clustering coefficient of the red node is 1/(5*4/2) = 0.1.

Considerations

  • The Local Clustering Coefficient algorithm ignores the direction of edges but calculates them as undirected edges.

Example Graph

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

ALTER GRAPH CURRENT_GRAPH ADD EDGE {
  knows ()-[]->()
};
INSERT (Lee:default {_id: "Lee"}),
       (Choi:default {_id: "Choi"}),
       (Mia:default {_id: "Mia"}),
       (Fiona:default {_id: "Fiona"}),
       (Chang:default {_id: "Chang"}),
       (John:default {_id: "John"}),
       (Park:default {_id: "Park"}),
       (Choi)-[:knows]->(Park),
       (Choi)-[:knows]->(Lee),
       (Park)-[:knows]->(Lee),
       (Park)-[:knows]->(Mia),
       (Lee)-[:knows]->(Mia),
       (Mia)-[:knows]->(Fiona),
       (Fiona)-[:knows]->(Lee),
       (Lee)-[:knows]->(Chang),
       (Lee)-[:knows]->(John),
       (John)-[:knows]->(Fiona);

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: clustering_coefficient

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.
return_id_uuidStringuuid, id, bothuuidYesIncludes _uuid, _id, or both to represent nodes in the results.
limitInteger≥-1-1YesLimits the number of results returned; -1 includes all results.
orderStringasc, desc/YesSorts the results by local clustering coefficient clce_centrality.

File Writeback

CALL algo.clustering_coefficient.write("my_hdc_graph", {
  ids: ["Lee", "Choi"],
  return_id_uuid: "id"
}, {
  file: {
    filename: "lcc"
  }
})

Result:

File: lcc
_id,clce_centrality
Lee,0.266667
Choi,1

DB Writeback

Writes the clce_centrality values from the results to the specified node property. The property type is float.

CALL algo.clustering_coefficient.write("my_hdc_graph", {}, {
  db: {
    property: "lcc"
  }
})

Full Return

CALL algo.clustering_coefficient.run("my_hdc_graph", {
  return_id_uuid: "id",
  order: "desc"
}) YIELD r
RETURN r

Result:

_idclce_centrality
John1
Choi1
Park0.666667
Fiona0.666667
Mia0.666667
Lee0.266667
Chang0

Stream Return

CALL algo.clustering_coefficient.stream("my_hdc_graph", {}) YIELD r
FILTER r.clce_centrality = 1 
RETURN count(r)

Result: 2