wikillm

Paper · 2022-09-01 · stat.ML, cs.AI, cs.LG, cs.SI

MSGNN: A Spectral Graph Neural Network Based on a Novel Magnetic Signed Laplacian

MSGNN is a spectral GNN for signed, directed graphs. It builds a Hermitian magnetic signed Laplacian that carries edge sign and direction, then applies complex Chebyshev filters (K=1, two layers). Author-reported: highest or tied-highest link-prediction accuracy in all 25 cells of five signed/directed tasks (one tie), and generally faster than six baselines.

Graph neural networkSpectral methodsStochastic block modelsigned-graphdirected-graphspectral-gnngraph-laplacianlink-predictionnode-clustering

arXivPDFCodeMarkdown14 min read

AI-compiled by claude-haiku-5-5 on 2026-11-01, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.

In plain words

Many real networks have edges that are not just "connected or not". An edge can be friendly or hostile (a sign), and it can point one way (a direction). A graph neural network (GNN) learns node representations from such a graph, but most GNNs assume plain undirected, unsigned edges.

This paper gives the graph a matrix, the "magnetic signed Laplacian", that carries both kinds of information at once. Each entry keeps the sign in its real value and the direction in its angle, so the matrix uses complex numbers. Spectral GNNs filter node signals through this matrix, much as a sound filter works on frequencies. The paper's network, MSGNN, does that filtering with two small layers.

The authors test it on two jobs: sorting nodes into groups, and predicting what kind of link joins two nodes (its sign, its direction, or both). They also add a synthetic graph generator and new datasets built from lead-lag relationships between stock returns.

TL;DR

  • Defines a Hermitian "magnetic signed Laplacian" that generalises the signed Laplacian and the magnetic (directed) Laplacian §3.2.
  • MSGNN is a two-layer spectral GNN with first-order Chebyshev filters and complex weights §3.3, §3.4.
  • Author-reported: highest accuracy on all 25 link-prediction cells (24 outright, one tie) and generally the fastest runtime §4.4.2, tab. 1, app. B.
  • Relevant if you need a GNN for signed, directed graphs; check the Pitfalls, since the paper and code differ on several settings.

Problem

Spectral GNNs need a graph Laplacian. For signed and directed graphs, that Laplacian should be positive semidefinite, have a bounded spectrum after normalisation, and encode both sign and direction §1. Earlier work covered only unsigned directed graphs (the magnetic Laplacian) or only signed undirected graphs (the signed Laplacian) §2. A concurrent signed magnetic Laplacian (SigMaNet) gives a node degree zero when its positive and negative unweighted links balance; the authors argue this is undesirable §3.2. The paper also notes that most earlier signed-graph GNNs were spatial and were evaluated mainly on link sign prediction §1, §2.

Method

Setting §3.1. The input is a weighted graph with signed edge weights w(e) that are nonzero, possibly directed, with optional node features X of shape n × d_in. Self-loops are allowed; multi-edges are not. The signed adjacency matrix is A, with A_ij = w(i→j) if the edge exists, else 0.

Magnetic signed Laplacian §3.2.

  1. Symmetrise the signed adjacency: Ã_ij = (A_ij + A_ji) / 2.
  2. Build the absolute-value degree D̃_ii = ½ Σ_j (|A_ij| + |A_ji|). Absolute values keep D̃ positive on connected graphs.
  3. Build the phase matrix Θ^(q)_ij = 2πq (A_ij − A_ji). q is the "charge" parameter.
  4. Form the Hermitian matrix H^(q) = Ã ⊙ exp(iΘ^(q)). For q = 0, H is just Ã.
  5. Unnormalised Laplacian: L_U^(q) = D̃ − H^(q) eq. 1.
  6. Normalised Laplacian: L_N^(q) = I − (D̃^(−1/2) Ã D̃^(−1/2)) ⊙ exp(iΘ^(q)) eq. 2. Because D̃ is diagonal, this equals D̃^(−1/2) L_U D̃^(−1/2) §3.2, app. A.
  7. Theorem 1: L_U and L_N are positive semidefinite for every real q §3.2. Theorem 2: the eigenvalues of L_N lie in [0, 2] for every real q §3.2.
  8. Reduction: with no signs, the matrix becomes the magnetic Laplacian. With no direction (q = 0 or undirected), it becomes the signed Laplacian. With neither, it becomes the standard normalised Laplacian §3.2.
  9. Edge flip: reversing an edge conjugates its entry in H^(q) §3.2.

Spectral convolution §3.3. Given an eigendecomposition L = U Λ U†, a signal x has Fourier transform x̂ = U† x, and a filter is a diagonal matrix Σ in that basis eq. 4. Following Defferrard et al. (cited as Defferrard2018), the authors take Σ as a Chebyshev polynomial in the rescaled eigenvalues Λ̃ = (2/λ_max) Λ − I eq. 5. The resulting filter Σ_k θ_k T_k(L̃) involves only products with L̃, so it avoids computing eigenvectors and has about one parameter per polynomial order. The filter is permutation-invariant and reaches K hops in the undirected, unsigned version of the graph; it treats out-neighbours and in-neighbours symmetrically §3.3. The authors state that the cost is that of the unsigned undirected counterpart, since only the entries on existing edges are computed §3.3.

MSGNN architecture §3.4.

  • A layer is X^(ℓ) = σ(Σ_i Y_ij^(ℓ) x_i^(ℓ−1) + b_j^(ℓ)) eq. 6, where σ is a complex ReLU and Y is a Chebyshev filter.
  • The authors use K = 1 and L = L_N^(q). Then X^(ℓ) = σ(X^(ℓ−1) W_self + L̃ X^(ℓ−1) W_neigh + B) §3.4.
  • Biases satisfy Re(b) = Im(b) eq. 6.
  • The complex ReLU keeps z when −π/2 ≤ arg(z) < π/2 and sets it to 0 otherwise §3.4.
  • The default is L = 2 layers §3.4, app. B.
  • The output is unwound into a real n × 2F matrix §3.4.
  • Node clustering: a linear layer with softmax over the unwound features §3.4.
  • Link prediction: concatenate the pair's rows of the unwound features, then a linear layer and softmax §3.4.

Pseudocode. The official code computes the same quantities; see Paper vs code for the differences.

Pseudocode
# Magnetic signed Laplacian, normalised  [§3.2] [eq. 2]
# Input:  A (n, n) signed weighted adjacency, A[i, j] = weight of i -> j
# Input:  q (scalar) charge; 0 for undirected graphs
# Output: L (n, n) complex Hermitian, eigenvalues in [0, 2]  [§3.2, Thm. 2]

def magnetic_signed_laplacian(A, q):
    # Self-loops: the paper allows them, the official code removes them
    # [§3.1] [code: src/get_magnetic_signed_Laplacian.py#L46]
    A = A with its diagonal set to zero
    # Symmetrised signed adjacency  [§3.2]
    A_sym = (A + transpose(A)) / 2
    # Absolute-value degree, one entry per node  [§3.2]
    degree = sum over j of (abs(A[i, j]) + abs(A[j, i])) / 2   # (n,)
    # Phase matrix, skew-symmetric  [§3.2]
    theta = 2 * pi * q * (A - transpose(A))
    # Hermitian matrix carrying sign and direction  [§3.2]
    H = A_sym * exp(1j * theta)                 # elementwise product
    # Isolated nodes: 1/sqrt(0) is replaced by 0  [code: src/MSConv.py#L178]
    D_inv_sqrt = diag(1 / sqrt(degree)), with 0 where degree is 0
    # L = I - D^-1/2 H D^-1/2 equals eq. 2 because D is diagonal  [eq. 2]
    return identity - D_inv_sqrt @ H @ D_inv_sqrt
Pseudocode
# MSGNN convolution with K = 1  [§3.3] [§3.4] [eq. 5] [eq. 6]
# Input:  X (n, F_in) complex node signal (real and imaginary parts)
# Input:  L (n, n) complex, from magnetic_signed_laplacian
# Output: (n, F_out) complex

def msgnn_layer(X, L, W_self, W_neigh, bias_real):
    # Rescale the spectrum to [-1, 1]: L_tilde = 2 L / lambda_max - I
    # [eq. 5]. For sym normalisation, lambda_max is fixed to 2 in code
    # [code: src/MSConv.py#L178], so L_tilde = L - I. See Pitfalls.
    L_tilde = L - identity
    # Real weight matrices applied to complex signals  [eq. 6]
    out = X @ W_self + L_tilde @ X @ W_neigh
    # Complex bias with equal real and imaginary parts  [eq. 6]
    out = out + (bias_real + 1j * bias_real)
    # Complex ReLU: keep entries with Re >= 0, zero the rest  [§3.4]
    # [code: src/complex_relu.py#L19]
    keep = real(out) >= 0
    return out * keep
Pseudocode
# Link head for a candidate pair (i, j)  [§3.4] [code: src/MSGNN.py#L85-L91]
# Input:  H_real, H_imag (n, hidden) from the last layer
# Output: log-probabilities over link classes

def link_log_probs(H_real, H_imag, i, j):
    # Concatenate both endpoints' real and imaginary parts: 4 * hidden
    feats = concat(H_real[i], H_real[j], H_imag[i], H_imag[j])
    # Dropout on the pair features during training; rate not stated in paper
    # [code: src/parser_link.py#L14]
    feats = dropout(feats, p=0.5)
    # Linear layer to the classes, then log-softmax  [code: src/MSGNN.py#L59]
    return log_softmax(linear(feats))

Hyperparameters

NameValueWhereNotes
Chebyshev order K1§3.4 parser_link.pyfilter has K + 1 = 2 terms
layers L2§3.4 app. B parser_link.py
optimizerAdamapp. B
learning rate0.01app. B parser_link.pysame in node clustering parser_node.py
weight decay (L2)5e-4app. B parser_link.py
epochs, link prediction300app. B parser_link.pyno early stopping; see Pitfalls
epochs, node clusteringat most 1000, early stop after 200app. B parser_node.py parser_node.pyselected on validation loss
loss, link predictionnegative log-likelihood on log-softmax (cross-entropy)app. B main_signed_directed_link.py
loss weight, node clusteringL_2 = L_vol_sum^sort + L_1app. B parser_node.pyimbalance ratio 1
L_1, node clusteringL_PBNC + γs (L_CE + γt L_triplet), γs = 50, γt = 0.1app. B parser_node.py parser_node.pysame as in SSSNET; PBNC is probabilistic balanced normalised cut
hidden channelsnot stated for MSGNN—code default 16 parser_link.py parser_node.py; paper gives 16 only for SSSNET
dropoutnot stated for MSGNN—code default 0.5 parser_link.py
charge q, undirected or unrelated to direction0§3.2 app. Beffect of q is nil on undirected graphs §4.4.1
charge q, directed taskssee Pitfalls: stated as q0, 0.25, or swept§3.2 app. B §4.4.3
q01 / (2 max_ij (A_ij − A_ji))§3.2gives Θ entries in [−π, π] (arXiv version); see Pitfalls
link split80% train, 20% test, 5 random splitsapp. B parser_link.py parser_link.pyno validation split by default
node split80% train, 10% validation, 10% testapp. B parser_node.py parser_node.pytest share is the remainder
seed nodes10% of the training nodes, with known labelsapp. B parser_node.pyhow the code applies the seed ratio was not checked
link input featuresin- and out-degree split by sign, 4-dimapp. Bcode default is 2-dim; flag needed, see Pitfalls
node input features, undirected signedtop-C eigenvectors of a regularised Ãapp. Bnot checked in code
node input features, SDSBMsigned in/out degrees, 4-dimapp. B
FiLL sparsificationkeep 20% of edges with largest magnitude§4.3the repo ships sparsified files; rule not checked in code
hardwaretwo compute nodes, 8 Tesla T4 eachapp. B

Results

Author-reported. Link prediction accuracy (%), mean ± standard deviation over five random splits, compared with six baselines §4.4.2, tab. 1. For FiLL, the "avg." row averages over 42 yearly networks and then reports mean ± SD over five runs §4.4.2. Datasets: BitCoin-Alpha and BitCoin-OTC §4.3, Slashdot and Epinions §4.3, and FiLL-pvCLCL and FiLL-OPCL (financial lead-lag, 2000–2020) §4.3. Tasks: sign prediction (SP), direction prediction (DP), and the 3-, 4- and 5-class tasks that need both §4.1.

DatasetTaskSGCNSDGNNSiGATSNEASSSNETSigMaNetMSGNN
BitCoin-AlphaSP64.7±0.964.5±1.162.9±0.964.1±1.367.4±1.147.8±3.971.3±1.2
BitCoin-AlphaDP60.4±1.761.5±1.061.9±1.960.9±1.768.1±2.349.4±3.172.5±1.5
BitCoin-Alpha3C81.4±0.579.2±0.977.1±0.783.2±0.578.3±4.737.4±16.784.4±0.6
BitCoin-Alpha4C51.1±0.852.5±1.149.3±0.752.4±1.854.3±2.920.6±6.358.5±0.7
BitCoin-Alpha5C79.5±0.378.2±0.576.5±0.381.1±0.377.9±0.334.2±6.581.9±0.9
BitCoin-OTCSP65.6±0.965.3±1.262.8±1.367.7±0.570.1±1.250.0±2.373.0±1.4
BitCoin-OTCDP63.8±1.263.2±1.564.0±2.065.3±1.269.6±1.048.4±4.971.8±1.1
BitCoin-OTC3C79.0±0.777.3±0.773.6±0.782.2±0.476.9±1.126.8±10.983.3±0.7
BitCoin-OTC4C51.5±0.455.3±0.851.2±1.856.9±0.757.0±2.023.3±7.459.8±0.7
BitCoin-OTC5C77.4±0.777.3±0.874.1±0.580.5±0.574.0±1.625.9±6.280.9±0.9
SlashdotSP74.7±0.574.1±0.764.0±1.370.6±1.086.6±2.257.9±5.392.4±0.2
SlashdotDP74.8±0.974.2±1.462.8±0.971.1±1.187.8±1.053.0±4.093.1±0.1
Slashdot3C69.7±0.366.3±1.849.1±1.272.5±0.779.3±1.242.0±7.986.1±0.3
Slashdot4C63.2±0.364.0±0.753.4±0.260.5±0.672.7±0.625.7±8.978.2±0.3
Slashdot5C64.4±0.362.6±2.044.4±1.466.4±0.570.4±0.719.3±8.676.8±0.6
EpinionsSP62.9±0.567.7±0.863.6±0.566.5±1.078.5±2.153.3±10.685.4±0.5
EpinionsDP61.7±0.567.9±0.663.6±0.866.4±1.273.9±6.249.0±3.286.3±0.3
Epinions3C70.3±0.873.2±0.852.3±1.372.8±0.272.7±2.030.5±8.383.1±0.5
Epinions4C66.7±1.271.0±0.662.3±0.569.5±0.770.2±5.229.9±6.478.7±0.9
Epinions5C73.5±0.876.6±0.752.9±0.774.2±0.170.3±4.622.1±6.180.5±0.5
FiLL (avg.)SP88.4±0.082.0±0.376.9±0.190.0±0.088.7±0.350.4±1.890.8±0.0
FiLL (avg.)DP88.5±0.182.0±0.276.9±0.190.0±0.088.8±0.348.0±2.790.9±0.0
FiLL (avg.)3C63.0±0.159.3±0.055.3±0.164.3±0.162.2±0.333.7±1.366.1±0.1
FiLL (avg.)4C81.7±0.078.8±0.170.5±0.183.2±0.180.0±0.324.9±0.983.3±0.0
FiLL (avg.)5C63.8±0.061.1±0.155.5±0.164.8±0.160.4±0.419.8±1.164.8±0.1

Bold marks MSGNN. On FiLL 5C, SNEA and MSGNN both reach 64.8±0.1 tab. 1.

  • Runtime (seconds, link tasks, after preprocessing) is in app. B. MSGNN is fastest in most rows; for example, on Slashdot SP it takes 227 s, against 342 s for SSSNET and 5792 s for SNEA. On Epinions 3C, SSSNET is fastest (471 s) and MSGNN second (510 s).
  • Node clustering §4.4.1, fig. 2: synthetic data only (SSBM, Pol-SSBM and SDSBM). Metric is ARI over ten runs (five networks, two splits each). The authors report MSGNN ahead of SigMaNet on every synthetic dataset and competitive with SSSNET. SSSNET is slightly ahead on SSBM and Pol-SSBM. Error bars are one standard error. The figure's values are not tabulated.
  • Ablation §4.4.3, app. C: nonzero q usually helps the directional tasks (DP, 3C, 4C, 5C), and the authors recommend q0. Signed input features help sign tasks. Building features from positive and negative subgraphs separately helps. Treating weights as unit magnitude helps or hurts depending on the dataset; edge weights matter for FiLL.
  • Layers app. C: going from 2 to 4 layers gives small gains, which often fall within one SD; performance falls slightly at 10 layers. Normalised and unnormalised variants differ by less than one SD in most cases.

Paper vs code

Code: official repository SherylHYX/MSGNN at da5cfd40ba10f21d3843b6c00e3ab29773d5f042, MIT, copyright Yixuan He LICENSE. The paper links this repo in §4.4 §4.4, so no further search was needed. The paper also says the code is in the PyTorch Geometric Signed Directed library §4.4.

  • Self-loops. The paper allows self-loops §3.1. The code removes them before building the Laplacian get_magnetic_signed_Laplacian.py and again inside the layer MSConv.py.
  • Phase sign and degree. The code's phase is w_ij − w_ji, which matches Θ = 2πq(A_ij − A_ji) §3.2 get_magnetic_signed_Laplacian.py get_magnetic_signed_Laplacian.py. The symmetrisation and absolute-value degree match the paper's definitions §3.2 get_magnetic_signed_Laplacian.py. Consistent.
  • λ_max for sym normalisation. The paper gives L̃ = (2/λ_max) L − I eq. 5 but does not say which λ_max is used with normalised Laplacians. The code computes λ_max only for non-sym normalisation and otherwise fixes it to 2 MSConv.py. Since Theorem 2 bounds the spectrum by 2 §3.2, this is the upper bound, not necessarily the largest eigenvalue of each graph.
  • Charge q, three statements. §3.2 sets q to q0 = 1/(2 max_ij (A_ij − A_ji)) for the directed tasks other than the ones with q = 0 §3.2. It then says q = 0.25 is used "for simplicity" in most experiments §3.2. The SDSBM node runs use q = 0.25 app. B. The link-prediction ablation recommends q0 §4.4.3. The code's link scripts run q as 55 (= q0), 0, and 11–44 (fractions of q0) a0.sh main_signed_directed_link.py. The code's SDSBM ablation sweeps q over 0–0.25 and 55 a5.sh. Which q produced the main link table is not stated in the paper.
  • q0 is computed once, from the first split. In main_signed_directed_link.py, q is converted from the 55 flag inside a loop over splits main_signed_directed_link.py main_signed_directed_link.py. After the first split, args.q is a float, so the test args.q in [11, 22, 33, 44, 55] is false for later splits. As written, every split after the first keeps the q0 computed on the first split's graph. This reading is from the code; I did not run it.
  • Input features default. The paper uses 4-dim in/out-degree features split by sign app. B. The code's default is 2-dim unsigned degrees; the 4-dim variant needs --sd_input_feat main_signed_directed_link.py. The execution scripts pass that flag in the variants labelled A and C a0.sh.
  • Complex ReLU boundary. The paper keeps z when −π/2 ≤ arg z < π/2 §3.4. The code keeps entries with Re ≥ 0 and applies the same mask to both parts complex_relu.py. They differ only on the imaginary axis: the code keeps points with Re = 0 and Im > 0, which the paper zeroes.
  • Link head dropout. The paper does not state dropout; the code applies dropout 0.5 to the concatenated pair features MSGNN.py parser_link.py.
  • Hidden size. The paper gives no MSGNN hidden size; the code default is 16 parser_link.py.
  • Epochs and model selection. The paper says 300 epochs for link prediction app. B. The code trains for that many epochs and reports test accuracy at the last epoch, with no validation split by default main_signed_directed_link.py parser_link.py.
  • Node loss. L_2 and L_1 as written app. B match the code's loss: sup × (CE + triplet ratio × triplet) + PBNC + imbalance main_SDSBM_node.py. Defaults match parser_node.py parser_node.py parser_node.py.
  • Undirected node features and the SSBM runs are described in app. B; the code for those runs was not checked.
  • Consistent: the K = 1 Chebyshev layer with real weights, the complex bias with Re = Im, and the concatenated pair head eq. 5, eq. 6, §3.4 MSConv.py MSConv.py MSGNN.py.

Pitfalls

  • Self-loops. The paper's formulas keep self-loops in Ã; the official code removes them. A graph with self-loops will give different results from the paper's text.
  • λ_max. The rescaling constant for sym normalisation is not stated. The code uses 2, the bound from Theorem 2, so the Chebyshev filter is L − I. A different λ_max rescales the filter.
  • q is data-dependent. q0 = 1/(2 max(A_ij − A_ji)). With unit-magnitude signed weights, the max is 2 only if some pair has A_ij = 1 and A_ji = −1; otherwise q0 differs from 0.25 §3.2. The code computes it from the split's graph main_signed_directed_link.py.
  • Setting q. The q behind the main link table is not stated. Any reproduction must pick a q and report it. The code's link scripts sweep q0 (flag 55), 0, and fractions 11–44 of q0. The formula gives 0.2, 0.4, 0.6 and 0.8 of q0 for flags 11, 22, 33 and 44 main_signed_directed_link.py. The parser's help text lists 1/5, 1/5, 3/5 and 4/5 parser_link.py, which disagrees with the formula. The paper's q-ablation table uses 0.2q0 to 0.8q0 app. C.
  • Feature flags. Without --sd_input_feat, the code's link model has 2-dim input, not the 4-dim input described in the paper main_signed_directed_link.py.
  • Ties in the claim. The paper says MSGNN has the highest accuracy in all 25 cases §4.4.2. Table 1 shows a tie on FiLL 5C (both 64.8 ± 0.1) tab. 1. The claim holds for 24 cells only.
  • Evaluation timing. The code's link-prediction numbers come from the last epoch, with no validation split by default main_signed_directed_link.py. The paper gives no early-stopping rule for link prediction app. B.
  • Complex arithmetic. The filter and biases are complex. The code keeps real and imaginary parts of the output separately and returns both MSConv.py; implementations need the same split.
  • Theorem constant. The LoG version gives Θ entries in [0, π]; the arXiv version gives [−π, π] and says a different constant gives [−π/2, π/2] §3.2 footnote. The code uses q0 = 0.5/max, which matches the arXiv range.
  • Cost. The paper states that the convolution computes only entries on existing edges, so its cost matches the unsigned undirected version §3.3. The Chebyshev form avoids the eigendecomposition §3.3. The paper gives no separate runtime figure beyond the table in app. B.
  • Dataset access. FiLL is built from CRSP prices accessed via WRDS §4.3. The paper says the lead-lag matrices are public. Rebuilding them from raw prices needs CRSP data. The repo ships data/Lead_Lag files Lead_Lag.
  • Sparsification. FiLL graphs keep the 20% largest-magnitude edges §4.3. The repo ships *_10p2.npz files; I did not check their sparsification in code.

Lineage

  • Builds on: Chebyshev spectral filters of Defferrard et al. (cited as Defferrard2018) §3.3; the magnetic Laplacian GNN "MagNet" (cited as zhang2021magnet). With positive weights, the paper's GNN reduces to MagNet's §2. The MagNet arXiv identifier is 2102.11391 per the code docstring complex_relu.py.
  • Signed-graph baseline: SSSNET (cited as he2022sssnet), whose loss and hyperparameters are reused app. B.
  • Compared against: SGCN, SDGNN, SiGAT, SNEA, SSSNET, SigMaNet §4.4. SigMaNet is a concurrent signed magnetic Laplacian GNN §2, §3.2.
  • Concurrent work: a signed-network GNN developed independently (cited as singh2022signed) §2 footnote.
  • Superseded by: not stated.

Source and license

Adapted from “MSGNN: A Spectral Graph Neural Network Based on a Novel Magnetic Signed Laplacian” by Yixuan He, Michael Perlmutter, Gesine Reinert, Mihai Cucuringu (arXiv:2209.00546), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/SherylHYX/MSGNN at commit da5cfd40ba10 (MIT). Any quoted code is shown under that license.