ECG
SQL function: cugraph_ecg
Official cuGraph reference: C API
Stabilize community assignments by combining an ensemble of randomized Louvain partitions into a final consensus clustering.
Quickstart
The call below supplies edges from registered relation target_edges with canonical src and dst columns and may include weight. Substitute your own registered relations.
SELECT * FROM cugraph_ecg(edges => (SELECT src, dst FROM target_edges));
Inputs
Every relation is a named parenthesized SELECT subquery. The required edges role uses canonical src and dst columns; every role, its canonical columns, and their accepted Arrow types are listed under Relation arguments. Metadata validation resolves registered tables named in its JSON request.
Endpoint columns accept numeric Int32, Int64 vertex IDs or logical string Utf8, LargeUtf8, Utf8View vertex IDs; string vertex-identity outputs are canonicalized to Utf8 (native mapping Int64) while scores, distances, counts, coordinates, and opaque labels stay numeric. The shared vertex-ID contract is summarized in Vertex ID support; the concrete call-specific schema comes from gpu_validate_call.
Logical string side-input limitations:
- edge ID columns and edge-ID predicate side inputs are not supported for logical string graphs
Arguments and options
Relation arguments
| Argument | Required | Columns | Description |
|---|---|---|---|
edges | yes |
| edge relation with canonical src and dst columns, plus optional weight and edge_id columns |
Every edge_id column must have the integer type of src and dst; string-keyed graphs accept no edge IDs.
Named value arguments
| Option | Type | Default | Constraints | Description |
|---|---|---|---|---|
ensemble_size | integer | 10 | min 1; max 4294967295 | number of ECG ensemble iterations |
max_level | integer | 100 | min 1; max 4294967295 | maximum hierarchy level, at least 1 |
min_weight | number | 0.001 | min 0 | minimum ECG edge weight |
resolution | number | 1 | > 0 | positive community resolution |
seed | integer | 0 | min 0; max 18446744073709552000 | random initialization seed |
threshold | number | 1e-7 | min 0 | non-negative convergence threshold |
Graph construction options
This function requires directed=false (undirected/symmetric graph); all other graph construction options follow the shared defaults documented in Graph Construction Options.
Output
| Column | Type | Nullable | Description |
|---|---|---|---|
vertex | Int64|Utf8 | no | Vertex assigned to an ECG community. |
partition | Int64 | no | Community identifier assigned by ECG. |
These are generic descriptor schemas; run gpu_validate_call to get the concrete, table-specific output schema.
Examples
This example runs on the citation network demo dataset.
Benchmark the ensemble against single-run algorithms
ECG runs an ensemble of Louvain passes (ensemble_size, default 10), reweights
edges by how often their endpoints co-cluster, and clusters the consensus. Is
that worth it? Because every cugraph_* function returns a plain relation, one
statement can run all three community algorithms on the same subgraph (the
Louvain example's 2010s AI views) and score them against the human-assigned
primary_fos labels, representing the share of members in a community carrying its
dominant label:
CREATE OR REPLACE VIEW ai_nodes AS
SELECT paper_id FROM papers
WHERE year >= 2010 AND primary_fos IN (
'Deep learning', 'Artificial neural network', 'Convolutional neural network',
'Recurrent neural network', 'Natural language processing',
'Reinforcement learning', 'Image segmentation', 'Feature extraction',
'Object detection', 'Speech recognition');
CREATE OR REPLACE VIEW ai_edges AS
SELECT e.src, e.dst
FROM citation_edges e
JOIN ai_nodes a ON a.paper_id = e.src
JOIN ai_nodes b ON b.paper_id = e.dst;
WITH labeled AS (
SELECT 'louvain' AS algorithm, c."partition" AS community, p.primary_fos
FROM cugraph_louvain(edges => (SELECT src, dst FROM ai_edges)) c
JOIN papers p ON p.paper_id = c.vertex
UNION ALL
SELECT 'leiden', c."partition", p.primary_fos
FROM cugraph_leiden(edges => (SELECT src, dst FROM ai_edges)) c
JOIN papers p ON p.paper_id = c.vertex
UNION ALL
SELECT 'ecg', c."partition", p.primary_fos
FROM cugraph_ecg(edges => (SELECT src, dst FROM ai_edges)) c
JOIN papers p ON p.paper_id = c.vertex),
counts AS (
SELECT algorithm, community, primary_fos, COUNT(*) AS n
FROM labeled GROUP BY 1, 2, 3),
sized AS (
SELECT algorithm, community, SUM(n) AS members, MAX(n) AS top_label
FROM counts GROUP BY 1, 2)
SELECT algorithm,
COUNT(*) AS communities,
COUNT(*) FILTER (WHERE members >= 100) AS ge100,
ROUND(SUM(top_label) FILTER (WHERE members >= 100) * 100.0
/ SUM(members) FILTER (WHERE members >= 100), 1) AS purity_pct
FROM sized
GROUP BY algorithm
ORDER BY purity_pct DESC;
| algorithm | communities | ge100 | purity_pct |
|---|---|---|---|
| ecg | 1,932 | 41 | 47.7 |
| louvain | 1,233 | 27 | 47.1 |
| leiden | 851 | 26 | 45.9 |
In this run the three GPU graph builds plus the joins and aggregation returned
together in about one second on the capture host. ECG's
consensus is deliberately conservative: it only keeps vertices together when
most ensemble members agree, so on this subgraph it produced the finest
partition (1,932 communities, 41 of them with 100+ papers) and scored above a
single Louvain run on label purity. Determinism comes from seed (default 0);
ensemble_size trades run time for consensus stability.
Limits
No algorithm-specific limitations.
To dry-run validate relation metadata, column types, and options without execution, see gpu_validate_call.