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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

asbm-0.1.6.dev0-cp313-cp313-win_amd64.whl (198.1 kB view details)

Uploaded CPython 3.13Windows x86-64

asbm-0.1.6.dev0-cp313-cp313-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

asbm-0.1.6.dev0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (208.2 kB view details)

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

asbm-0.1.6.dev0-cp313-cp313-macosx_11_0_arm64.whl (175.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

asbm-0.1.6.dev0-cp312-cp312-win_amd64.whl (198.1 kB view details)

Uploaded CPython 3.12Windows x86-64

asbm-0.1.6.dev0-cp312-cp312-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

asbm-0.1.6.dev0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (208.3 kB view details)

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

asbm-0.1.6.dev0-cp312-cp312-macosx_11_0_arm64.whl (175.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

asbm-0.1.6.dev0-cp311-cp311-win_amd64.whl (194.2 kB view details)

Uploaded CPython 3.11Windows x86-64

asbm-0.1.6.dev0-cp311-cp311-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

asbm-0.1.6.dev0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (207.0 kB view details)

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

asbm-0.1.6.dev0-cp311-cp311-macosx_11_0_arm64.whl (174.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file asbm-0.1.6.dev0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: asbm-0.1.6.dev0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 198.1 kB
  • Tags: CPython 3.13, 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.6.dev0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 49593cd521352b5b5cdc49a4540329013c0601fb55d69cbc447bff27bc89ca30
MD5 fc70638f83f87d0a68a2c2e1e12afd90
BLAKE2b-256 2dec97f3daeff10d47060ca29e659687ab6d39b4c8b1dfd36dde3cee4faa7eea

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.6.dev0-cp313-cp313-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.6.dev0-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for asbm-0.1.6.dev0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f7c019301159e026252423731ccd39509db37af8f710b0af48fbb343951e57ea
MD5 39ffb6ba5d48a35f66c494fb44d62f9d
BLAKE2b-256 56722c93e2ed33821f64741a056bed76bac77bad728449ba79499cacd627de7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.6.dev0-cp313-cp313-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.6.dev0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for asbm-0.1.6.dev0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d63c6c727603d2b6278d405edb651537be21e0b67363a09dc80cebdf6a33f639
MD5 0715fcb8fd274de38b2ce7efebecbe05
BLAKE2b-256 9f3e5b149b66af9bc0429b318641d8b055363efd420edbe6e203c7a7796e3979

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.6.dev0-cp313-cp313-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.6.dev0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for asbm-0.1.6.dev0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 471423ceda78f9858ca004751860744c45ea9c9afdb33eeac7e0464e0073c981
MD5 3be87aaa00cb016c60f9150a0c2858fe
BLAKE2b-256 dae3e7bb1a64707ac981efc74d28d900965ec7b46d6f11263c4dc0ee0114c721

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.6.dev0-cp313-cp313-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.

File details

Details for the file asbm-0.1.6.dev0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: asbm-0.1.6.dev0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 198.1 kB
  • Tags: CPython 3.12, 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.6.dev0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b61daf2abd744e87443a88c7e207244076dc4937a353f8777973a63246e2b196
MD5 f3bdc7c8612a0bbb4fba78afcd31c2f0
BLAKE2b-256 86da88de23e19a4272d031453ee471318c1cd075613fea02448a646bbb9361f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.6.dev0-cp312-cp312-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.6.dev0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for asbm-0.1.6.dev0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 575d0307df781c1821b4a514a3ae2e82eb4c868bde81b1b951a235739228d16a
MD5 74350bbd51819816ade0e96455d3b6eb
BLAKE2b-256 f5aed9baabf4d7683ccb1eb1e3abeab3f95b8be8562f5d75c799a6705078e4d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.6.dev0-cp312-cp312-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.6.dev0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for asbm-0.1.6.dev0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9978709e59e5de3ffedf93e17f8584949fe24e84696ca52e3b921b318097bf54
MD5 e932f710d8156d651ac0c87bca6a1809
BLAKE2b-256 5d32c27b405a51e5178bf78e89b1800fda5cb325cb26f59d399c0fedc1976780

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.6.dev0-cp312-cp312-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.6.dev0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for asbm-0.1.6.dev0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0591800a64e4b34f6266cffa6f65a8aa260af57decb8e545a6c963586f0c1c97
MD5 23243f3f42617215b0ae462932caa1c0
BLAKE2b-256 3f580f64f6e8fe355da42d2bfb1ab379432d7fe08d98d350c8c3b578f5a583ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.6.dev0-cp312-cp312-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.

File details

Details for the file asbm-0.1.6.dev0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: asbm-0.1.6.dev0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 194.2 kB
  • Tags: CPython 3.11, 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.6.dev0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4e19c640d6a5f1730dee06d33ebac5b0b608facc175b955dfe22f294bd04aea6
MD5 110e126379afd99a21cfb628c48942b3
BLAKE2b-256 1c77d0c461fc39dc40b666e9b874a97ccaa6b5c8ed28eea95544668ed03c1120

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.6.dev0-cp311-cp311-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.6.dev0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for asbm-0.1.6.dev0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1e4807f575aa968d5d09731fbd1d2a470097558c9384b5549b3655d35004a8f3
MD5 b20e9b14e2044c83a9b6bc0699b62a1f
BLAKE2b-256 c541d42ed778ad0b9a916c42c40f8183f9030e325a51296525febd9e1a0865d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.6.dev0-cp311-cp311-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.6.dev0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for asbm-0.1.6.dev0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 017f961932a805228701832f79621585ea9d7f165b36ecd483eb019b409bfc67
MD5 adc2a67fe821bf731302fcd1e2befcf0
BLAKE2b-256 028a918741c3efc0f9fa72606f638772ecdfd7bbf437b481a790d9ff53d354b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.6.dev0-cp311-cp311-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.6.dev0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for asbm-0.1.6.dev0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2b4b50333793b80d364a92cf5976d52d9e7ff5bad14a68c77869bfc8fffe77b2
MD5 9d9aaf8df330884c4e25c529cbc1650d
BLAKE2b-256 093dc25f423187b6656f969e4615262b2af70792cd514770ecb6adabb68033be

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.6.dev0-cp311-cp311-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