Skip to content

spatialfusion.utils.gcn_utils

spatialfusion.utils.gcn_utils

Utility functions for building graphs, generating subgraphs, and plotting losses for GCN models.

This module provides: - plot_training_losses: Plot training loss curves for GCN models. - build_knn_graph: Build k-NN graph from spatial coordinates. - generate_overlapping_subgraphs: Generate overlapping subgraphs using spatial clustering. - split_index: Split index strings into sample IDs and corrected indices.

build_knn_graph(coords, k=30)

Build a k-nearest neighbors (k-NN) graph from coordinate data.

Parameters:

Name Type Description Default
coords ndarray

Node coordinates.

required
k int

Number of neighbors.

30

Returns:

Type Description
DGLGraph

dgl.DGLGraph: Constructed graph.

generate_overlapping_subgraphs(full_graph, coords, subgraph_size=5000, stride=2500)

Generate overlapping subgraphs from a large graph using spatial clustering.

Parameters:

Name Type Description Default
full_graph DGLGraph

Full input graph.

required
coords ndarray

Node coordinates.

required
subgraph_size int

Max number of nodes in each subgraph.

5000
stride int

Distance between cluster centers.

2500

Returns:

Type Description
List[DGLGraph]

List[dgl.DGLGraph]: List of subgraphs.

plot_training_losses(loss_history, title='Training Losses')

Plot total, feature, edge, and regularization losses over training epochs.

Parameters:

Name Type Description Default
loss_history dict

Dictionary with keys 'total', 'feat', 'edge', 'reg' and corresponding loss lists.

required
title str

Plot title.

'Training Losses'

split_index(index)

Splits index values into sample IDs and corrected indices.

Parameters:

Name Type Description Default
index List[str]

List of index strings.

required

Returns:

Type Description
tuple[ndarray, ndarray]

tuple[np.ndarray, np.ndarray]: Arrays of sample_ids and corrected indices.