CDCGS (Community Detection Clustering via Gumbel Softmax) Documentation๏ƒ

๐Ÿ” Overview๏ƒ

CDCGS is a graph clustering algorithm that applies the Gumbel-Softmax trick to learn soft assignments of nodes to communities. It computes a community relationship matrix R using these assignments and applies softmax to normalize interactions between clusters.


โš™๏ธ Class Definition๏ƒ

Class Name: CDCGS This class implements the Gumbel-Softmax based community clustering model.

class CDCGS(nn.Module):
    def __init__(self, num_nodes: int, n_clusters: int, tau: float = 1.0):
        ...

๐Ÿ“‹ Parameters๏ƒ

Parameter

Type

Default

Description

num_nodes

int

โ€”

Number of graph nodes

n_clusters

int

โ€”

Number of target communities

tau

float

1.0

Gumbel-Softmax temperature


๐Ÿš€ Usage Examples๏ƒ

from soft_clustering._cdcgs._cdcgs import CDCGS
import torch

adj = torch.tensor([
    [0, 1, 0, 0, 0, 0],
    [1, 0, 1, 0, 0, 0],
    [0, 1, 0, 1, 0, 0],
    [0, 0, 1, 0, 1, 0],
    [0, 0, 0, 1, 0, 1],
    [0, 0, 0, 0, 1, 0]
], dtype=torch.float)

model = CDCGS(num_nodes=6, n_clusters=2, tau=1.0)
R, soft_assign = model(adj)
loss = model.loss(R)

print("Loss:", loss.item())

๐Ÿ› ๏ธ Methods๏ƒ

  • forward(adj): Computes community assignments and relation matrix

  • loss(output): Encourages the relation matrix to be close to identity


๐Ÿ“ Implementation Notes๏ƒ

  • Learns soft cluster assignments via Gumbel-Softmax

  • Encourages orthogonal (independent) clusters via identity loss

  • Simple and fully unsupervised


๐Ÿ“š Reference๏ƒ

This implementation is based on:
โ€œCommunity Detection Clustering via Gumbel Softmaxโ€
by H. Zhang, J. Bu, Y. Wang, and C. Chen.