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.5.dev0-cp313-cp313-win_amd64.whl (197.5 kB view details)

Uploaded CPython 3.13Windows x86-64

asbm-0.1.5.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.5.dev0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (208.0 kB view details)

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

asbm-0.1.5.dev0-cp313-cp313-macosx_11_0_arm64.whl (175.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

asbm-0.1.5.dev0-cp312-cp312-win_amd64.whl (197.5 kB view details)

Uploaded CPython 3.12Windows x86-64

asbm-0.1.5.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.5.dev0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (207.9 kB view details)

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

asbm-0.1.5.dev0-cp312-cp312-macosx_11_0_arm64.whl (175.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

asbm-0.1.5.dev0-cp311-cp311-win_amd64.whl (193.8 kB view details)

Uploaded CPython 3.11Windows x86-64

asbm-0.1.5.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.5.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.5.dev0-cp311-cp311-macosx_11_0_arm64.whl (174.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: asbm-0.1.5.dev0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 197.5 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.5.dev0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 893942471f7ce84e877c5685a9fb54e7a521a1b30219f9192322569fc2d23065
MD5 1c163c8766cda869c5bd3cf9946e7130
BLAKE2b-256 8b67ef8ac6d2dfa26e548857417333acd005a55f57824fe53d3f8fddc919290a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asbm-0.1.5.dev0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 984add0b9d266a5eec2981363c5f672a81137c7af8cdc345ab7fab8ba2f58841
MD5 c707dd199f781b91ee5a4dd29083e88c
BLAKE2b-256 25d40ce6a8f1c112ead240a5010eed216f89232a9cd93fe3977d5fe5467a7f29

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asbm-0.1.5.dev0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 260a30abcf1c430e590aa3bc44dca8ca8375ee007d81fa9a01875ba283171ed3
MD5 5bebc16a92a8c1a0fff7d1190e8b8b85
BLAKE2b-256 726cd064462404c01f8ff317f0fa8efdbcd339a064e373372c7e9758fe233f40

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asbm-0.1.5.dev0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8b476ebcb675de1cdd4f432d916e79fea9cc533da0c8b64af4184274a40a5237
MD5 38295c9cabab700a4af35e645e843c40
BLAKE2b-256 c60edfffd447b7e8c73e91df3387faa1d4f8bda506d75753ee2b211ed56ccab3

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.5.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.5.dev0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: asbm-0.1.5.dev0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 197.5 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.5.dev0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 533d0f117095f6d52ebe0058a25f0eb688c17193b5eb346dad0c6f4e388ec42b
MD5 aecbe137b840c3411034bb261ac31bf7
BLAKE2b-256 686f93043b5d8d7b09773cccd6842ac82292b4ab1936302e9f0aca556c89cf39

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asbm-0.1.5.dev0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b5765e74d84ddad8e64191bbd36d6e1355895ef30875feba077618675461c7d7
MD5 5c552945f302e0614509cbd472753d76
BLAKE2b-256 70225cdd5d01521831a705ba356d03d49bd15b4554a387d2673bd3ee0543fd02

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asbm-0.1.5.dev0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d68c6fef818c37b9e13b27bb8ce4d1ea761c2f4d83fb6999fbfbdd871a284519
MD5 4cc5ec51215e5442358a23ab01f71734
BLAKE2b-256 3ba28ffd565c500aba48c5467d3e12a0529d90ee187f4baa5e05d5ed16d8120a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asbm-0.1.5.dev0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 612cac96e33f56664c20d4c8fcb29e938ed11ede046cbeb06684a3ba30512790
MD5 29671fd2fc179992caacd14e824645d7
BLAKE2b-256 8a892cec9fcf9ad32f825dc303402f43c3cd051ce437ff6180aedb45a34905d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for asbm-0.1.5.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.5.dev0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: asbm-0.1.5.dev0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 193.8 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.5.dev0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 69f2d1460f99b98d9ee0a54ac17e0584c94111c6e0714f8a936e9677542d1df1
MD5 e097258b2debe33f98e053adb53fc1b3
BLAKE2b-256 5988c6abfa668a6bb164488929b6e987354bf81b0624091ca7b0702915c4079b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asbm-0.1.5.dev0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4c6a34c281167be10db905ce491352d7e2cd70329dda6a4f3b8187f27e57f31a
MD5 c15f81f863e34da326986acf72279ab3
BLAKE2b-256 1946c74ac75c8ae1cf2fed34c1f34b2229a3359fd03f3ed1d3335aecb2c549b8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asbm-0.1.5.dev0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9d240ef988eae5eff75ce0512e8af7adcf7096551136bf389eb5e36245dd9e33
MD5 10ffe2179d2b5ceaebd0e716da06ef9a
BLAKE2b-256 ae2d53212fab968d99264eacc096e34d217fbc8742dc0b92873133bd616750a2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asbm-0.1.5.dev0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 70a8bee1d4eda3bc2669881d340f8e673895ccb080ccd815217a06f86c0eac39
MD5 a04559f68b0284ae8f8a626d13beed17
BLAKE2b-256 8d8fc5c852c4e7a1d0f195e1398aec5a8218c4d759fe35929ff9787a1a2b7325

See more details on using hashes here.

Provenance

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