Probabilistic logit-based graph model and utilities
Project description
Logit Graph
A probabilistic logit-based graph model and utilities for fitting, simulating, and comparing random graph models to real-world networks. The package provides a simple, scikit-learn-like API to fit the Logit Graph model and benchmark it against classic random graph models (ER, WS, BA, optionally GRG), with metrics based on spectral distances and a Graph Information Criterion (GIC).
- PyPI:
logit-graph - Python: >=3.9
- License: MIT
Installation
Install the published package from PyPI:
pip install logit-graph
Or, for local development within this repo:
pip install -e .
If you prefer using the full research environment (for notebooks, plotting, etc.), use the provided requirements.txt or environment.yml.
Quickstart
Fit a Logit Graph to a network
import networkx as nx
from logit_graph import LogitGraphFitter
# Load or build your original graph (undirected)
G = nx.karate_club_graph()
# Configure and fit Logit Graph
fitter = LogitGraphFitter(d=2, n_iteration=2000, patience=500, dist_type='KL', verbose=True)
fitter = fitter.fit(G)
fitted_graph = fitter.fitted_graph
print(f"GIC: {fitter.metadata['gic_value']:.4f}, sigma: {fitter.metadata['sigma']:.4f}")
Compare models (LG vs ER/WS/BA)
import networkx as nx
from logit_graph import GraphModelComparator
G = nx.karate_club_graph()
# Grid of d for Logit Graph and generation settings
comparator = GraphModelComparator(
d_list=[0, 1, 2, 3],
lg_params={
'max_iterations': 2000,
'patience': 500,
'edge_delta': None,
'min_gic_threshold': 5,
'er_p': 0.05,
},
other_model_n_runs=2,
dist_type='KL',
verbose=True,
other_models=["ER", "WS", "BA"], # optionally include "GRG"
other_model_grid_points=5
)
comparator = comparator.compare(original_graph=G, graph_filepath="karate_club")
print(comparator.summary_df)
# Access fitted graphs and metadata
lg_graph = comparator.fitted_graphs_data['LG']['graph']
lg_meta = comparator.fitted_graphs_data['LG']['metadata']
Public API
The package exposes the following top-level entries:
-
logit_graph.LogitGraphFitter- Fits a single Logit Graph to a given
networkx.Graph. - Key init args:
d,n_iteration,warm_up,patience,dist_type,edge_delta,min_gic_threshold,verbose,er_p. - Methods:
fit(original_graph: nx.Graph) -> self
- Attributes after
fit:fitted_graph: nx.Graphmetadata: dictwithsigma,gic_value,best_iteration,spectrum_diffs,edge_diffs, and more.
- Fits a single Logit Graph to a given
-
logit_graph.GraphModelComparator- Compares Logit Graph against other random graph models.
- Init args:
d_list: list[int]: values ofdto try for LGlg_params: dict: parameters forwarded to LG generation (e.g.,max_iterations,patience,edge_delta,min_gic_threshold,er_p)other_model_n_runs: intother_model_params: list|None(optional). If omitted, sensible defaults are used per model.dist_type: str('KL', etc.)verbose: boolother_models: list[str](subset of["ER", "WS", "GRG", "BA"])other_model_grid_points: int
- Methods:
compare(original_graph: nx.Graph, graph_filepath: str) -> self
- After
compare:summary_df: pandas.DataFramewith per-model metrics and attributesfitted_graphs_data: dict[str, {graph: nx.Graph, metadata: dict, attributes: dict}]
-
logit_graph.calculate_graph_attributes(graph: nx.Graph) -> dict- Convenience function to compute basic properties (density, clustering, path length, diameter, assortativity, largest component size, etc.).
Notes:
- Internally, LG estimation uses logistic regression over local degree-based features and optimizes a spectral criterion (GIC) while generating edges.
- You can import lower-level utilities from submodules if needed (e.g.,
logit_graph.graph,logit_graph.gic,logit_graph.logit_estimator), but the high-level API above is recommended.
Data and Notebooks
- Datasets used in experiments live under
data/(many are compressed archives) and cover brain connectomes, social networks, Reddit threads, and more. - Reproducible analysis and figures are in
notebooks/, organized by dataset category. - Generated images used in the paper are in
images/.
These folders are not required for installing or using the pip package; they support reproducing the research and examples.
Troubleshooting
- Some features (plotting, notebooks) require optional dependencies present in
requirements.txt. - If
igraphorpycairofail to install on your platform, install their system packages or wheels first, thenpip install logit-graphagain. - For very large graphs, consider lowering
max_iterations/patienceor running comparisons with fewer models first.
Development
- Build from source:
python -m build
- Run tests and examples via the scripts and notebooks in
scripts/andnotebooks/. - We welcome issues and PRs. See
project.urlsfor links.
Citation
If you use this package in academic work, please cite the project and link to the repository https://github.com/maruanottoni/logit-graph. A formal citation entry will be added upon publication.
Ottoni, M. (2024). Logit Graph: probabilistic logit-based graph modeling and selection. GitHub repository. https://github.com/maruanottoni/logit-graph
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file logit_graph-0.1.1.tar.gz.
File metadata
- Download URL: logit_graph-0.1.1.tar.gz
- Upload date:
- Size: 25.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
434c14c1276a5345f11fd51590f702da98a8e262221b416da873979699f142c9
|
|
| MD5 |
0be2c6775924c598d34062b1cb275d4f
|
|
| BLAKE2b-256 |
fb2e63078d867b6ae70bba0d59afe977a03dd3c91e9c711068dc1a0b49a4c17b
|
File details
Details for the file logit_graph-0.1.1-py3-none-any.whl.
File metadata
- Download URL: logit_graph-0.1.1-py3-none-any.whl
- Upload date:
- Size: 25.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea90bc1e5abdd13a6aaa6a3e82b67e1a7e1a722b7edeb03c7a0d2246956d1cf3
|
|
| MD5 |
a0f093ec96fb2218f3ba8a026c76afdd
|
|
| BLAKE2b-256 |
7683bafde93a9aa54f5579f282fb0613e17b89ef432a9a7b992761994d95c12c
|