Clustering(eps, device, max_len=1000, dist_type='cos')
Bases: object
General clustering framework with center alignment.
| Parameters: |
|
|---|
align_centers()
Align current centers with initial centers.
| Returns: |
|
|---|
Notes
Solves the linear assignment problem to find optimal matching between current and initial centers.
assign_fake_labels(feats)
Assign samples to nearest cluster centers.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
Uses specified distance metric (cos/euc) for assignment.
clustering_stop(centers)
Check clustering convergence condition.
| Parameters: |
|
|---|
Notes
Convergence is determined by:
- If centers is None: continue clustering
- If mean distance between current and previous centers < eps: stop
Prints current distance for monitoring.
collect_samples(feat, label)
Store features and labels for clustering.
| Parameters: |
|
|---|
Notes
Stores:
- Ground truth labels
- Features
- Sample indices
feature_clustering(feat, label)
Perform iterative clustering until convergence.
| Parameters: |
|
|---|
Notes
Process:
- Assign samples to nearest centers
- Update centers
- Check convergence
- Align with initial centers
set_init_centers(init_centers)
Initialize cluster centers.
| Parameters: |
|
|---|
Notes
Stores both current and initial centers for tracking changes and later alignment.
DIST(dist_type)
Bases: object
Distance metric calculator for clustering.
| Parameters: |
|
|---|
cos(pointA, pointB, cross)
Compute cosine distance.
| Parameters: |
|
|---|
| Returns: |
|
|---|
euc(pointA, pointB, cross)
Compute Euclidean distance.
| Parameters: |
|
|---|
| Returns: |
|
|---|
get_dist(pointA, pointB, cross=False)
Calculate distance between points.
| Parameters: |
|
|---|
| Returns: |
|
|---|
GMMClustering(num_class, device, dist_type='cos')
Bases: object
Gaussian Mixture Model clustering with center alignment.
| Parameters: |
|
|---|
align_centers(src_center, tgt_center)
Align target centers with source centers.
| Parameters: |
|
|---|
| Returns: |
|
|---|
forward(src_centers, emb_t, y_t, target_edge_index, target_edge_attr, smooth, smooth_r)
Perform GMM clustering and align with source centers.
| Parameters: |
|
|---|
| Returns: |
|
|---|
smooth(edge_index, v, smooth_r)
Apply label smoothing using graph structure.
| Parameters: |
|
|---|
| Returns: |
|
|---|
gcn_norm(edge_index, edge_weight=None, num_nodes=None, improved=False, add_self_loops=True, dtype=None)
Compute symmetric normalization for graph convolution.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
Features:
- Handles both sparse and dense formats
- Adds self-loops with configurable weight
- Computes symmetric normalization
- Handles numerical stability
- Supports improved GCN variant
Implementation details:
- Automatically adds self-loops if requested
- Handles infinite values in degree normalization
- Supports both SparseTensor and edge_index formats
- Memory-efficient sparse operations
get_emb_centers(embeddings, label_array, n_label)
Calculate centroids of embeddings per label.
| Parameters: |
|
|---|
| Returns: |
|
|---|
onehot(label_matrix, num_classes)
Convert labels to one-hot encoding.
| Parameters: |
|
|---|
| Returns: |
|
|---|