spamosaic.build_graph.build_mnn_graph

spamosaic.build_graph.make_Ahat_sparse(A, improved=False, symm=False)[source]

Build a normalized adjacency matrix A_hat suitable for GNN layers.

Given a sparse adjacency A (N×N), this function optionally symmetrizes it, adds self-loops, and applies the symmetric normalization \(D^{-1/2} A D^{-1/2}\).

Parameters:
  • A (scipy.sparse.spmatrix) – Sparse adjacency matrix of shape (N, N).

  • improved (bool, optional) – If True, use a self-loop weight of 2.0 (as in “improved” GCN).

  • symm (bool, optional) – If True, force symmetry by replacing A with (A + A.T) before normalization.

Returns:

Normalized sparse matrix A_hat of shape (N, N).

Return type:

scipy.sparse.csr_matrix