Skip to main content

wMSM, weighted MultiScale Model for multiscale network reconstruction

Project description

wMSM

wmsm is a research package for reconstructing weighted networks across aggregation levels with the weighted MultiScale Model (wMSM).

The package is designed for settings in which the binary density is observable only at a coarse scale, while node strengths are available at the finer scale where the network must be reconstructed. The key idea is to calibrate the binary parameter on the aggregate layer and transfer it unchanged to the target layer, because the wMSM probability law is closed under coarse graining with additive strengths.

The repository also includes CReMB, a fine-scale benchmark based on the density-corrected Gravity Model topology and the Conditional Reconstruction Method for weights.

Installation

pip install wmsm

For development:

git clone https://github.com/mattiamarzi/wmsm
cd wmsm
pip install -e ".[dev,notebooks]"
pytest -q

Quick start

import numpy as np

from wmsm import load_synthetic_itn_like, link_count
from wmsm import wmsm, cremb
from wmsm.metrics import reconstruction_summary

# Bundled anonymized ITN-like example.
data = load_synthetic_itn_like()
W_country = data["W_country"]
W_macro = data["W_macro"]

A_country = (W_country > 0).astype(float)
A_macro = (W_macro > 0).astype(float)

s_country = W_country.sum(axis=1)
s_macro = W_macro.sum(axis=1)
W_total = W_country.sum()

# wMSM, calibrated on macro-regions and transferred to countries.
L_macro = link_count(A_macro, directed=False, include_diagonal=True)
delta = wmsm.fit_delta_from_strengths(
    s_macro,
    None,
    L_macro,
    directed=False,
    include_diagonal=True,
)
rho = wmsm.rho_from_total_weight(delta, W_total)
P_wmsm = wmsm.probability_matrix_from_strengths(
    s_country,
    None,
    delta=delta,
    directed=False,
    include_diagonal=False,
)
Wexp_wmsm = wmsm.expected_weights_matrix_from_strengths(
    s_country,
    None,
    delta=delta,
    rho=rho,
    directed=False,
    include_diagonal=False,
)

# CReMB, calibrated directly on the country layer.
L_country = link_count(A_country, directed=False, include_diagonal=False)
z = cremb.fit_delta_from_strengths(
    s_country,
    None,
    L_country,
    directed=False,
    include_diagonal=False,
)
P_cremb = cremb.probability_matrix_from_strengths(
    s_country,
    None,
    delta=z,
    directed=False,
    include_diagonal=False,
)
Wexp_cremb = cremb.expected_weights_matrix_from_strengths(
    s_country,
    None,
    directed=False,
    include_diagonal=False,
)

summary_wmsm = reconstruction_summary(
    A_country,
    W_country,
    P_wmsm,
    Wexp_wmsm,
    directed=False,
    include_diagonal=False,
)
summary_cremb = reconstruction_summary(
    A_country,
    W_country,
    P_cremb,
    Wexp_cremb,
    directed=False,
    include_diagonal=False,
)

print(summary_wmsm["ARE_k"], summary_wmsm["MRE_k"], summary_wmsm["TPR"])
print(summary_cremb["ARE_k"], summary_cremb["MRE_k"], summary_cremb["TPR"])

Repository layout

src/wmsm/wmsm.py      wMSM calibration and first moments
src/wmsm/cremb.py      CReMB benchmark calibration and first moments
src/wmsm/metrics.py    diagnostics used in the paper
datasets/               anonymized synthetic example dataset
notebooks/              end-to-end reproducible examples
docs/                   usage notes, API reference, and equations
tests/                  automated tests for the package workflow

Documentation

See:

  • docs/usage.md
  • docs/api_quick_reference.md
  • docs/math.md

Citation

The companion paper is currently in preparation. Until the public bibliographic record is available, please cite the repository and use the placeholder CITATION.cff file.

License

MIT, see LICENSE.

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

wmsm-0.1.0.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

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

wmsm-0.1.0-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wmsm-0.1.0.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.13

File hashes

Hashes for wmsm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c681024c89b54eef3f48d792576b8296e51ae879ac83670c5f7b9d78a77c9137
MD5 a43f3b6255615658a5910b0025ba0613
BLAKE2b-256 15cbbf4cd3a1e24e0583b2ac57676eded6b7aefaee491acabc8274dbe709a78a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wmsm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.13

File hashes

Hashes for wmsm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e1b8ec73bc7507c91f8c58abb8ab0b71945832e574c3825f64f67c9aea42a1c2
MD5 d57915a1b528036b345b9fccd844a0f7
BLAKE2b-256 33ccb799e56b1870d970c897ef3ef0d7071dedf1f95955579ed8f8576c0406e2

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