Skip to main content

Find group structures in networks

Project description

asbm

Documentation Status PyPI version PyPI platforms

Infer network groups and properties with assortative stochastic block models

Maximilian Jerdee

This Python package uses Bayesian inference to find meaningful groupings of nodes in networks.

We implement a general assortative SBM that unifies the standard SBM and the planted partition model under a common framework. Its parameters directly measure the violation of each model's assumptions: the assortative preference ρ_in/ρ_out captures departure from in/out symmetry, while per-group variation coefficients v_in and v_out measure heterogeneity across groups. The standard SBM, planted partition model, and the Zhang–Peixoto hybrid emerge as special cases, enabling exact Bayesian model comparison between them.

For each model, the package includes algorithms to:

  • Find consensus estimates of the group structure
  • Infer global network parameters (assortativity, group sizes)
  • Score held-out edges via posterior predictive likelihood

Installation

Implementations are available for Python, R, and Julia.

Python

pip install asbm

Or build locally from the repository root:

pip install .

R

install.packages("asbm", repos = "https://maxjerdee.r-universe.dev")

Julia

using Pkg
Pkg.add(url="https://github.com/maxjerdee/asbm", subdir="bindings/julia")

Building from source requires CMake and a C++17 compiler. Run Pkg.build("ASBM") after installation to compile the native library.

Quickstart

Python

import asbm
import networkx as nx

G = nx.read_gml("examples/data/dolphins.gml", label="id")

config = asbm.Config(
    model="general_asbm",
    degree_correction=True,
)

result = asbm.fit(config, G)

print(result.mdl_partition)
print(result.mdl_value)
print(result.consensus_partition())

To score held-out edges:

G_train = nx.read_gml("examples/data/train.gml")
G_test  = nx.read_gml("examples/data/test.gml")

result = asbm.fit(asbm.Config(model="general_asbm"), G_train)
score  = result.log_posterior_predictive(G_test)

R

library(asbm)
library(igraph)

G <- read_graph("examples/data/dolphins.gml", format = "gml")

result <- fit(G,
              model             = "general_asbm",
              degree_correction = TRUE,
              num_chains        = 4,
              samples_per_chain = 100,
              seed              = 42)

print(result$mdl_value)
print(result$mdl_partition)
print(result$consensus_partition)

Julia

using ASBM, Graphs

g = cycle_graph(62)  # or load via GraphIO

result = fit(g;
    model             = "general_asbm",
    degree_correction = true,
    num_chains        = 4,
    samples_per_chain = 100,
    seed              = 42)

println(result.mdl_value)
println(result.mdl_partition)
println(result.consensus_partition)

For the full API, including posterior predictive evaluation and the samples schema, see the package documentation.

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

asbm-0.1.5.tar.gz (227.5 kB view details)

Uploaded Source

Built Distributions

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

asbm-0.1.5-cp310-cp310-win_amd64.whl (192.6 kB view details)

Uploaded CPython 3.10Windows x86-64

asbm-0.1.5-cp310-cp310-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

asbm-0.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (206.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

asbm-0.1.5-cp310-cp310-macosx_11_0_arm64.whl (172.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file asbm-0.1.5.tar.gz.

File metadata

  • Download URL: asbm-0.1.5.tar.gz
  • Upload date:
  • Size: 227.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asbm-0.1.5.tar.gz
Algorithm Hash digest
SHA256 a5b94bba0c417ca8182fe8445da19766274d2bd7e9ccb86a8b52bff71ab81e42
MD5 ba40518de9d682d12a0c52b2552a2b06
BLAKE2b-256 8be4924d803740bd121a971f77f651c11c4b662e0c190d627cd36e1be1754df6

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.5.tar.gz:

Publisher: release.yml on maxjerdee/asbm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file asbm-0.1.5-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: asbm-0.1.5-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 192.6 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asbm-0.1.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8aeb2de4c1b57b80bbfe19df07622f2c695c18f71dbb8766c77fd49816c4e108
MD5 4618d28c3ae5cc6d8b7ca4c5eb161db0
BLAKE2b-256 f4c2a50ed160e185478d2ae59f792718350ba8af8db83f867eabcdcaa9c01694

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.5-cp310-cp310-win_amd64.whl:

Publisher: release.yml on maxjerdee/asbm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file asbm-0.1.5-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for asbm-0.1.5-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a04a3fd5339df88bd834b49c37f8174de0a39bf12dc2f74b1266c17b350209d8
MD5 cbff89905e514fe5cfd83d2ff420625c
BLAKE2b-256 52e607636c1827f1cb36de4ab14fb3c1b2fed944d4091187698e148c0b008de3

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.5-cp310-cp310-musllinux_1_2_x86_64.whl:

Publisher: release.yml on maxjerdee/asbm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file asbm-0.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for asbm-0.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f704f77954c3d4c8f6e57f5d6854b0bc083fa7ee9ee3f297ae620e580d981fa2
MD5 7fd50c4f7dba58596772a4fa54443855
BLAKE2b-256 b16ad7da29614f13df08d88fb430925523691e55120b611fd29df89186f60607

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on maxjerdee/asbm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file asbm-0.1.5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

  • Download URL: asbm-0.1.5-cp310-cp310-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 172.9 kB
  • Tags: CPython 3.10, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asbm-0.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 365f4761338b1921bf6f07236392b3b21d775ab67fb0e558d8a766f2461105f9
MD5 fca9da7b770d7546380c2eefeca63c35
BLAKE2b-256 b47b3c797ebe66761817e84b5fc9a89130067abc1ed5c61b937a1de0d61e5d32

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.5-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: release.yml on maxjerdee/asbm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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