qbiocode.apps.quvine.baselines.graphsage module#

Unsupervised GraphSAGE baseline.

Implements mean-aggregator GraphSAGE (Hamilton et al., 2017) in an unsupervised setting using a graph-context (DeepWalk-style) loss.

Two backends are provided: 1. PyTorch — full trainable GraphSAGE with unsupervised negative-sampling loss. 2. NumPy — spectral mean-aggregation fallback (no training required).

Reference: Hamilton, W., Ying, R., & Leskovec, J. (2017).

Inductive Representation Learning on Large Graphs. NeurIPS.

Summary#

Functions:

run_graphsage

Unsupervised GraphSAGE embedding.

Reference#

run_graphsage(graph, nodes, dimensions=64, hidden_dim=128, n_layers=2, epochs=50, lr=0.01, neg_samples=5, seed=42, device='cpu')[source]#

Unsupervised GraphSAGE embedding.

Uses the PyTorch backend when available; falls back to spectral mean aggregation otherwise.

Parameters:
  • graph (nx.Graph)

  • nodes (list) – Canonical node ordering; embedding rows correspond to these nodes.

  • dimensions (int) – Output embedding dimensionality.

  • hidden_dim (int) – Hidden layer width (PyTorch backend only).

  • n_layers (int) – Number of aggregation layers.

  • epochs (int) – Training epochs (PyTorch backend only).

  • lr (float) – Learning rate (PyTorch backend only).

  • neg_samples (int) – Number of negative samples per positive edge (PyTorch backend only).

  • seed (int) – Random seed.

Return type:

np.ndarray (len(nodes) × dimensions)