Skip to main content

Library to infer disentangled communities (Louvain-like) and disentangled embeddings

Project description

disentangled-net

A Python library designed for disentangled structure inferences on networks (communities and embeddings). It provides advanced topological tools to purge networks of spatial (given nodes position) or custom null model effects, allowing the extraction of unbiased communities and node embeddings.

Citation Note: If you use this code or repository for your research paper, please cite: [Insert Citation Here Upon Publication].

Installation

To install the official release via PyPI:

pip install disentangled-net

To install in development mode from the cloned repository root:

pip install -e .

Repository Structure & Core Modules

The library is modularly designed around five key components inside the src/ directory:

  • disentangled_louvain_communities.py: Exposes the public API for community detection. It includes two callable functions: infer_spatial_disentangled_louvain_communities to extract communities using node coordinates, and infer_custom_disentangled_louvain_communities to infer communities using a user-provided probability matrix of size $N \times N$ representing a custom Null Model.

  • disentangled_embeddings.py: Implements a custom PyTorch-based signed network embedding algorithm. It optimizes a continuous node representation space based on network residual intensities, leveraging either spatial positions or a custom $N \times N$ external Null Model matrix. Available functions : infer_spatial_disentangled_embeddings and infer_custom_disentangled_embeddings.

  • SpatialNullModelInference.py: Handles the maximum likelihood estimation (MLE) of the Degree-Corrected Spatial Null Model. It infers coordinate-based $\alpha$ and $\beta$ parameters to generate the background spatial probability matrix.

  • MetaLouvain.py: Contains the core modularity optimization algorithms tailored for the inference of Null-Model disentangled network partitions.

  • utils.py: Provides mathematical and structural validation utilities, such as checking partition robustness across different resolution scales.

Quick Start

import networkx as nx
import numpy as np
from disentangled_net import infer_spatial_disentangled_louvain_communities, infer_spatial_disentangled_embeddings

# 1. Load a NetworkX Graph with a spatial position attribute
G = nx.erdos_renyi_graph(n=50, p=0.1)

# Example : a random 2D position in [0;1] is assigned to every node
for node in G.nodes:
    G.nodes[node]['GT_pos'] = np.random.rand(2)

# 2. Extract spatially disentangled communities (modifies G in place)
G = infer_spatial_disentangled_louvain_communities(
    G=G, 
    pos_attr="GT_pos", 
    attr_name="spatially_disentangled_louvain_id"
)

# 3. Generate spatially disentangled continuous embeddings (modifies G in place)
G = infer_spatial_disentangled_embeddings(
    G=G, 
    pos_attr="GT_pos", 
    attr_name= "spatially_disentangled_embedding",
    embedding_dim=64
)

# Nodes now contain both disentangled attributes
print(G.nodes[0])

If you want to infer disentangled communities and embeddings from something else than node positions, you can do so by using your own NullModel matrix, of size N_nodes * N_nodes :

import networkx as nx
import numpy as np
from disentangled_net import infer_custom_disentangled_louvain_communities, infer_custom_disentangled_embeddings

G = nx.erdos_renyi_graph(n=50, p=0.1)
nodes_list = list(G.nodes())

# Example: a dummy 50x50 probability matrix
customNullModel = np.full((50, 50), 0.05)

# 2. Extract custom disentangled communities (modifies G in place)
G = infer_custom_disentangled_louvain_communities(
    G=G, 
    null_model_matrix=customNullModel, 
    ordered_nodes=nodes_list,
    attr_name="custom_disentangled_louvain_id"
)

# 3. Generate custom disentangled continuous embeddings (modifies G in place)
G = infer_custom_disentangled_embeddings(
    G=G, 
    null_model_matrix=customNullModel, 
    ordered_nodes=nodes_list,
    attr_name="custom_disentangled_embedding",
    embedding_dim=64
)

# Nodes now contain both custom disentangled attributes
print(G.nodes[0])

Authors

DUPUY Guilhem - guilhempds@gmail.com CAZABET Rémy - remy.cazabet@gmail.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

disentangled_net-0.1.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

disentangled_net-0.1.0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file disentangled_net-0.1.0.tar.gz.

File metadata

  • Download URL: disentangled_net-0.1.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.17.1 {"ci":null,"cpu":"x86_64","distro":{"name":"macOS","version":"15.7.7"},"implementation":{"name":"CPython","version":"3.10.15"},"installer":{"name":"hatch","version":"1.17.1"},"openssl_version":"OpenSSL 3.6.1 27 Jan 2026","python":"3.10.15","system":{"name":"Darwin","release":"24.6.0"}} HTTPX2/2.7.0

File hashes

Hashes for disentangled_net-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9affa57a05fcb47f5cbb94c923ec778bbb39af2ca28e19d8d2b17a35c0b67d81
MD5 9b02f26ac74c593c4bed28bf735b2cac
BLAKE2b-256 a07f8ae17c93576bfadd8153348f4fd7c9774d7cb894228c353ccbc2aed8742e

See more details on using hashes here.

File details

Details for the file disentangled_net-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: disentangled_net-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.17.1 {"ci":null,"cpu":"x86_64","distro":{"name":"macOS","version":"15.7.7"},"implementation":{"name":"CPython","version":"3.10.15"},"installer":{"name":"hatch","version":"1.17.1"},"openssl_version":"OpenSSL 3.6.1 27 Jan 2026","python":"3.10.15","system":{"name":"Darwin","release":"24.6.0"}} HTTPX2/2.7.0

File hashes

Hashes for disentangled_net-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8983c4205952b8186282c335fae94d5e1c4eab91b84094f6cd48dcc2385d5004
MD5 345f55cd94ef76573e60323cfadf3a8b
BLAKE2b-256 bd5460b7893ac1adfe0a7bd30c61cad626239fd98a1b956d5831bd3efd71d2fb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page