qbiocode.apps.quvine.baselines.netmf module#

NetMF: Network Embedding as Matrix Factorization

Implementation based on: Qiu, J., Dong, Y., Ma, H., Li, J., Wang, K., & Tang, J. (2018). Network embedding as matrix factorization: Unifying deepwalk, line, pte, and node2vec. In Proceedings of the Eleventh ACM International Conference on Web Search and Data Mining (pp. 459-467).

Reference: xptree/NetMF

Summary#

Functions:

run_netmf

Run NetMF (Network Embedding as Matrix Factorization) on a graph.

Reference#

run_netmf(graph, nodes, dimensions=128, window_size=10, negative=1, rank=None, use_svd=True, seed=None)[source]#

Run NetMF (Network Embedding as Matrix Factorization) on a graph.

NetMF provides a closed-form solution for network embedding by computing the matrix factorization of a modified adjacency matrix that captures higher-order proximity.

Parameters:
  • graph (nx.Graph) – Input graph

  • nodes (list) – List of nodes (for ordering)

  • dimensions (int, default=128) – Embedding dimension

  • window_size (int, default=10) – Context window size (similar to DeepWalk/Node2Vec)

  • negative (int, default=1) – Number of negative samples (affects the matrix transformation)

  • rank (int, optional) – Rank for SVD approximation. If None, uses dimensions.

  • use_svd (bool, default=True) – Whether to use SVD (True) or eigendecomposition (False)

  • seed (int, optional) – Random seed for reproducibility

Returns:

Node embeddings matrix of shape (n_nodes, dimensions)

Return type:

np.ndarray

Notes

NetMF computes embeddings by:

  1. Computing the transition matrix P from the adjacency matrix

  2. Computing the volume (sum of degrees)

  3. Computing the DeepWalk matrix: log(vol(G) * (sum_{r=1}^T P^r) / T / b) - log(b) where b is the number of negative samples

  4. Performing SVD/eigendecomposition to get the embedding

References

Qiu et al. (2018). Network embedding as matrix factorization: Unifying deepwalk, line, pte, and node2vec. WSDM 2018.