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.4.tar.gz (238.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.4-cp310-cp310-win_amd64.whl (192.2 kB view details)

Uploaded CPython 3.10Windows x86-64

asbm-0.1.4-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.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (205.7 kB view details)

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

asbm-0.1.4-cp310-cp310-macosx_11_0_arm64.whl (172.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: asbm-0.1.4.tar.gz
  • Upload date:
  • Size: 238.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.4.tar.gz
Algorithm Hash digest
SHA256 3ca29a615d83bf6d9e4299cb8c7c23a6de7f227f785933942cfbfb550567b94b
MD5 2de809bc194781516dcafb217f6ccd5e
BLAKE2b-256 7a1217c9dfa61b30a31f6795f0578f728abbff3fb43a55e4f69613f7ccf090db

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.4.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.4-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: asbm-0.1.4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 192.2 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.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b333f8c851941d5b6a71279b799616d21476585e5116d6ad8d3b9fcb70a5d696
MD5 e92e3253bb30bc87e5746bc9b5de1d4f
BLAKE2b-256 2c54d95e832ffdd6008e6f996f0a9e4079c2cfb410e58d91be2bfdea92108941

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.4-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.4-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for asbm-0.1.4-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 637a74bdb1cee31cd3155db7bc93bdb8b39f5fbc0dcf211984bbb285bb66cdfb
MD5 558029cf83c280844d3e69ee1004c761
BLAKE2b-256 37b7c0d0ec0b5b6da9dd1b26b641c531f3c1f102db84a024b2c70a3b5607893d

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.4-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.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for asbm-0.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0841f9f4e3e19f4f62df7fabf75db8175a0fdd2804e7ac80f491d471fe1c7834
MD5 f4a8ed62d3117d88930971fa1edf24ec
BLAKE2b-256 898d09ac21c825da4eb31b69aef347518f9b6163ffcc81883908ed9e6477d43f

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.4-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.4-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

  • Download URL: asbm-0.1.4-cp310-cp310-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 172.7 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.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 31075d7615261b22bfb66cebe049046c2c4cede4927079d7831405d45fd83a31
MD5 ec870e9c40021c344f1afd4683a7cd45
BLAKE2b-256 1949f89531dc3a9701b212ddef4a4d591a30c51cefb12efafbf528cb1ab838eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.4-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