Skip to main content

BiCM package

This is a Python package for the computation of the maximum entropy bipartite configuration model (BiCM) and the projection of bipartite networks on one layer. It requires Python 3.10 or later.

You can install this package via pip:

pip install bicm

Documentation is available at https://bipartite-configuration-model.readthedocs.io/en/latest/ .

This package is also a module of NEMtropy that you can find at https://github.com/nicoloval/NEMtropy .

For more solvers of maximum entropy configuration models visit https://meh.imtlucca.it/ .

NOTE of the developer: there was an error in the projection threshold, validating less links than it should have. Please re-run your analysis after updating to the last version (>=3.1)

Basic functionalities

To install:

pip install bicm

To import the module:

import bicm

To generate a Graph object and initialize it (with a biadjacency matrix, edgelist or degree sequences):

from bicm import BipartiteGraph
myGraph = BipartiteGraph()
myGraph.set_biadjacency_matrix(my_biadjacency_matrix)
myGraph.set_adjacency_list(my_adjacency_list)
myGraph.set_edgelist(my_edgelist)
myGraph.set_degree_sequences((first_degree_sequence, second_degree_sequence))

Or alternatively, with the respective data structure as input:

from bicm import BipartiteGraph
myGraph = BipartiteGraph(biadjacency=my_biadjacency_matrix, adjacency_list=my_adjacency_list, edgelist=my_edgelist, degree_sequences=((first_degree_sequence, second_degree_sequence)))

To compute the BiCM probability matrix of the graph or the relative fitnesses coefficients as dictionaries containing the nodes names as keys:

my_probability_matrix = myGraph.get_bicm_matrix()
my_x, my_y = myGraph.get_bicm_fitnesses()

This will solve the bicm using recommended settings for the solver. To customize the solver you can alternatively use (in advance) the following method:

myGraph.solve_tool(light_mode=False, method='newton', initial_guess=None, tol=1e-8, max_steps=None, verbose=False, linsearch=True, regularise=False, print_error=True, exp=False)

To get the rows or columns projection of the graph:

myGraph.get_rows_projection()
myGraph.get_cols_projection()

Alternatively, to customize the projection:

myGraph.compute_projection(rows=True, alpha=0.05, approx_method='poisson', threads_num=4, progress_bar=True)

Warnings, logging and reproducibility

Problems found while solving or projecting (for example a solver that did not converge) are reported as Python warnings of category bicm.BiCMWarning, so they can be filtered:

import warnings
import bicm
warnings.filterwarnings("ignore", category=bicm.BiCMWarning)

Informative messages (for example "Computing the BiCM...") go to the bicm logger and are hidden by default. To show them:

import logging
logging.basicConfig()
logging.getLogger("bicm").setLevel(logging.INFO)

The sampling functions accept a seed argument (an integer or a numpy.random.Generator) to get reproducible samples, e.g. sample_bicm(avg_mat, seed=42). Without it, numpy's global random state is used as in previous versions.

Projections use several processes by default. On macOS, scripts must put their code under if __name__ == "__main__": for this to work, or pass threads_num=1. On Windows projections always run in a single process.

Now version 3 is online, and you can use the package with weighted networks as well using the BiWCM models!

See a more detailed walkthrough in tests/bicm_test or tests/biwcm_test notebooks, or check out the API in the documentation.

Development

To install the package from source together with the test dependencies and run the test suite:

pip install -e ".[test]"
pytest

The tests run automatically on GitHub Actions for every push and pull request. A new version is published to PyPI when a GitHub release is created with a tag matching the package version (e.g. v3.5.0).

How to cite

If you use the bicm module, please cite its location on Github https://github.com/mat701/BiCM and the original articles [Vallarano2021], [Saracco2015] and [Saracco2017].

If you use the weighted models (BiWCM_c or BiWCM_d), please also cite [Bruno2023].

References

[Vallarano2021] N. Vallarano, M. Bruno, E. Marchese, G. Trapani, F. Saracco, T. Squartini, G. Cimini, M. Zanon, Fast and scalable likelihood maximization for Exponential Random Graph Models with local constraints, Nature Scientific Reports

[Bruno2023] M. Bruno, D. Mazzilli, A. Patelli, T. Squartini, F. Saracco, Inferring comparative advantage via entropy maximization. J. Phys. Complex. 4, 045011 (2023), doi:10.1088/2632-072X/ad1411

[Saracco2015] F. Saracco, R. Di Clemente, A. Gabrielli, T. Squartini, Randomizing bipartite networks: the case of the World Trade Web, Scientific Reports 5, 10595 (2015).

[Saracco2017] F. Saracco, M. J. Straka, R. Di Clemente, A. Gabrielli, G. Caldarelli, and T. Squartini, Inferring monopartite projections of bipartite networks: an entropy-based approach, New J. Phys. 19, 053022 (2017)

Author:

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

Metadata

Release files for bicm 3.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bicm 3.5.0
File Size Uploaded Provenance Actions
bicm-3.5.0.tar.gz 36.3 kB With provenance Details for bicm-3.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bicm 3.5.0
File Interpreter ABI Platform Actions
bicm-3.5.0-py3-none-any.whl Python 3 none any Details for bicm-3.5.0-py3-none-any.whl

Total release size: 68.6 kB

Release files / bicm-3.5.0.tar.gz

Download URL bicm-3.5.0.tar.gz
Size 36.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6c0f570215d30ccaec59900869e1549cda820489f95b66c0f62e92183d35ca56
BLAKE2b-256 checksum
How to use checksums
7b07d092f42aaab939124399d54674979e685d97aa3c5353a4d2c3f3fef690ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / bicm-3.5.0-py3-none-any.whl

Download URL bicm-3.5.0-py3-none-any.whl
Size 32.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d3fccb9820b5023daf8a4f3a42335707ffcb982b8b1154dfe60c831216091eb
BLAKE2b-256 checksum
How to use checksums
d4a13a54a46808b0cde9c9c5aef910ad22d31c92cca8fce6d4289203443c9220
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Security for bicm 3.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bicm-3.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page