An attributed directed bipartite motif inference workflow in Python
Project description
attrimotif
An attributed directed bipartite motif inference workflow in Python.
attrimotif chains the four steps an empirical study of an attributed directed
bipartite network (buyer → brand, tourist → spot, user → movie) usually has to
assemble from scattered tools:
- Census — directed bipartite motif counts (size-3 fan-out / fan-in; size-4 fans and the 2×2 overlap / 4-cycle).
- Typed — stratify each motif class by a categorical node type, and apply the operator Φ to read the distribution of a numeric edge attribute over motif instances (exposing tails a count collapses).
- Nulls — a degree-preserving bipartite null with a null-identifiability diagnostic that flags statistics which are exact functions of the degree sequence (so the null cannot identify them).
- Compare — panel-level Portrait Divergence with a random-partition permutation test.
It is not a general directed-motif or colored-graph-isomorphism engine: the
scope is deliberately attributed bipartite motifs on fixed templates, which is
what the motivating empirical problems need and what keeps the package small,
permissively licensed (MIT), and dependency-light (numpy, scipy,
networkx; netrd optional).
Install
pip install attrimotif # from PyPI (planned)
pip install -e .[dev] # from a checkout, with test/plot extras
Quickstart
import attrimotif as am
d = am.datasets.synthetic_panel(seed=0)
g = d["graph"]
am.census(g) # {'fan-out':..,'fan-in':..,'overlap':..,..}
am.stratified_census(g) # counts by node category
am.phi_distributions(g) # operator Φ: per-class attribute distributions
am.null_test(g, "overlap") # identifiable → z, permutation p
am.null_test(g, "fan-out") # flagged: degree-determined, not identifiable
am.panel_permutation_test(g, d["agent_panel"]) # cross-panel Portrait Divergence
Note. A repeated arc collapses for all topological counts;
edge_attrholds one value per arc, so aggregate repeated observations (e.g. several purchases of the same brand) into a single weight before constructing the graph.
Portrait Divergence backend
The bundled implementation is dependency-light. If netrd
is installed, am.portrait_divergence(g1, g2, backend="netrd") delegates to its
reference implementation for computing Portrait Divergence. The bundled and netrd
backends agree on identity (PD(G, G) = 0) and on ordering, but may differ slightly
in how the k-axis is binned across graphs of different sizes.
Relation to existing tools
attrimotif does not claim a new algorithm. Directed motif census
(NetworkX, graph-tool, gtrieScanner), degree-preserving randomization (NetworkX,
graph-tool, xswap), and Portrait Divergence (Bagrow & Bollt 2019; netrd) all
exist separately. attrimotif's contribution is the integration of an
attributed bipartite motif census, the identifiability diagnostic, operator
Φ, and panel-level Portrait Divergence into one reproducible, installable
workflow. See CITATION.cff and the paper for the full comparison.
Data statement
The package ships only synthetic generators (attrimotif.datasets) and
reads user-supplied or public-download data. No proprietary records are included
or required; .gitignore blocks confidential source files from the repository.
Tests
pip install -e .[dev]
pytest
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file attrimotif-1.0.0.tar.gz.
File metadata
- Download URL: attrimotif-1.0.0.tar.gz
- Upload date:
- Size: 27.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9ecbcc0a3a6833bf3017552fdb9ec07e97b8d6c77bedf82c62f40f613e5fb45
|
|
| MD5 |
ce6621e9c49378f24b5122622ed21049
|
|
| BLAKE2b-256 |
81cd50eb6b58b4a9f0f758f158128308ce0ea6df528cbf4a4423d1169f108545
|
File details
Details for the file attrimotif-1.0.0-py3-none-any.whl.
File metadata
- Download URL: attrimotif-1.0.0-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a905cc50ad61bf312848f9330e1da4eefb2cb5c99592292efdcbe790ad9aef6
|
|
| MD5 |
fb995a8a677227f9070ec27d77032024
|
|
| BLAKE2b-256 |
f00b4e2f049ff4a14c3a12dd2a2f78c481bed77f76886e3bd9f0c654463b79ce
|