Skip to main content

NEMtropy is a Maximum-Entropy toolbox for networks, it provides the user with a state of the art solver for a range variety of Maximum Entropy Networks models derived from the ERGM family. This module allows you to solve the desired model and generate a number of randomized graphs from the original one: the so-called graphs ensemble.

Project description

PyPI Python License: GPL v3 Scientific Reports

NEMtropy: Network Entropy Maximization, a Toolbox Running On PYthon

NEMtropy is a Maximum-Entropy toolbox for networks, released as a python3 module.

NEMtropy provides the user with a state of the art solver for a range variety of Maximum Entropy Networks models derived from the ERGM family. This module allows you to solve the desired model and generate a number of randomized graphs from the original one: the so-called graphs ensemble.

NEMtropy builds on the current literature on the matter, improving both in speed of convergence and in the scale of the feasible networks. To explore Maximum-Entropy modeling on networks, checkout Maximum Entropy Hub.

If you use the module for your scientific research, please consider citing us:

@article{vallarano2021fast,
  title={Fast and scalable likelihood maximization for exponential random graph models with local constraints},
  author={Vallarano, Nicol{\`o} and Bruno, Matteo and Marchese, Emiliano and Trapani, Giuseppe and Saracco, Fabio and Cimini, Giulio and Zanon, Mario and Squartini, Tiziano},
  journal={Scientific Reports},
  volume={11},
  number={1},
  pages={15227},
  year={2021},
  publisher={Nature Publishing Group UK London}
}

Table Of Contents

Currently Implemented Models

The main feature of NEMtropy is (but not limited to) network randomization. The specific kind of network to randomize and property to preserve defines the model you need:

  • UBCM Undirected Binary Configuration Model [1]
  • UECM Undirected Enhanced Configuration Model [1]
  • DBCM Directed Binary Configuration Model [1]
  • DECM Directed Enhanced Configuration Model [1]
  • CReMa [2]
  • BiCM Bipartite Configuration Model [3]
  • BiWCM Bipartite Weighted Configuration Model [4]

The following table may helps you identify the model that fits your needs in function of the type of network you are working with; for in-depth discussion please see the references.

[...] Undirected Graph Directed Graph Bipartite Graph
Binary Graph UBCM DBCM BiCM
Weighted Graph UECM, CReMa DECM, CReMa BiWCM

The BiCM module is now (NEMtropy>=3.0.0) imported and it is mantained as a a standalone package, find its docs here.

References

  • [1] Squartini, Tiziano, Rossana Mastrandrea, and Diego Garlaschelli. "Unbiased sampling of network ensembles." New Journal of Physics 17.2 (2015): 023052. https://arxiv.org/abs/1406.1197
  • [2] Parisi, Federica, Tiziano Squartini, and Diego Garlaschelli. "A faster horse on a safer trail: generalized inference for the efficient reconstruction of weighted networks." New Journal of Physics 22.5 (2020): 053053. https://arxiv.org/abs/1811.09829
  • [3] Saracco, Fabio, Riccardo Di Clemente, Andrea Gabrielli, and Tiziano Squartini. "Randomizing bipartite networks: the case of the World Trade Web." Scientific reports 5, no. 1 (2015): 1-18. https://doi.org/10.1038/srep10595
  • [4] Bruno, Matteo, Dario Mazzilli, Aurelio Patelli, Tiziano Squartini, and Fabio Saracco. "Inferring comparative advantage via entropy maximization." Journal of Physics: Complexity, Volume 4, Number 4 (2023). https://doi.org/10.1088/2632-072X/ad1411

Installation

NEMtropy requires Python 3.10 or newer.

NEMtropy can be installed via pip. You can get it from your terminal:

    $ pip install NEMtropy

If you already install the package and wish to upgrade it, you can simply type from your terminal:

    $ pip install NEMtropy --upgrade

Dependencies

NEMtropy requires Python 3.10+. Runtime dependencies (numpy, scipy, networkx, powerlaw, tqdm, bicm, and transitively numba) are installed automatically with the package. To install them manually:

    $ pip install numba powerlaw networkx scipy tqdm bicm

Simple Example

As an example we solve the UBCM for zachary karate club network.

    import numpy as np
    import networkx as nx
    from NEMtropy import UndirectedGraph

    G = nx.karate_club_graph()
    adj_kar = nx.to_numpy_array(G)
    graph = UndirectedGraph(adj_kar)

    graph.solve_tool(model="cm_exp",
                 method="newton",
                 initial_guess="random")

Given the UBCM model, we can generate ten random copies of zachary's karate club.

    graph.ensemble_sampler(10, cpu_n=2, output_dir="sample/")

These copies are saved as an edgelist, each edgelist can be converted to an adjacency matrix by running the NEMtropy build graph function.

    from NEMtropy.network_functions import build_adjacency_from_edgelist

    edgelist_ens = np.loadtxt("sample/0.txt")
    ens_adj = build_adjacency_from_edgelist(edgelist = edgelist_ens,
                                            is_directed = False,
                                            is_sparse = False,
                                            is_weighted = False)

These collections of random adjacency matrices can be used as a null model: it is enough to compute the expected value of the selected network feature on the ensemble of matrices and to compare it with its original value.

To learn more, please read the ipython notebooks in the examples directory:

Documentation

You can find complete documentation about NEMtropy library in docs.

Development

Please work on a feature branch and create a pull request to the development branch. If necessary to merge manually do so without fast-forward:

    $ git merge --no-ff myfeature

To build a development environment (Python 3.10+):

    $ python3 -m venv venv 
    $ source venv/bin/activate 
    $ pip install -e '.[dev]'

Testing

See TESTING.md for the full guide. Quick start (Python 3.10+):

    $ pip install -e ".[dev]"
    $ pytest

By default, slow tests are skipped (~30s). To run everything:

    $ pytest --override-ini 'addopts='

P.S. at the moment there may be some problems with the DECM solver functions

Credits

Authors:

Nicolò Vallarano (a.k.a. nicoloval)

Emiliano Marchese (a.k.a. EmilianoMarchese)

Matteo Bruno (BiCM) (a.k.a. mat701)

Acknowledgements:

The module was developed under the supervision of Tiziano Squartini, Fabio Saracco, Mario Zanon, and Giulio Cimini. It was developed at IMT school of advanced studies Lucca, and financed by the research project Optimized Reconstruction of Complex networkS - ORCS.

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

nemtropy-4.0.0.tar.gz (51.5 kB view details)

Uploaded Source

Built Distribution

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

nemtropy-4.0.0-py3-none-any.whl (49.2 kB view details)

Uploaded Python 3

File details

Details for the file nemtropy-4.0.0.tar.gz.

File metadata

  • Download URL: nemtropy-4.0.0.tar.gz
  • Upload date:
  • Size: 51.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for nemtropy-4.0.0.tar.gz
Algorithm Hash digest
SHA256 66836ba39f7f7898c8599fbf6f60bc7d2ae3934161431482a4c288386194ee60
MD5 271b5fae78eea114bb0886ab5272aa9f
BLAKE2b-256 5198255fbfc08b3d2102d9344ee6ef2b4072edb00e127e79dc88337724ac4263

See more details on using hashes here.

File details

Details for the file nemtropy-4.0.0-py3-none-any.whl.

File metadata

  • Download URL: nemtropy-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 49.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for nemtropy-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4041d482e1d22cf13f864fb5882acfc5be89ac663975ca65e7c6c4c6139f971
MD5 1dd2a80b2db56b2f101bc4ada976480a
BLAKE2b-256 17669a08796f39b0158bb11f7c15d94a91f59ffa9a92d65df3a03bb75ee6376d

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