metablox (metadata block structure exploration) is a Python library for quantifying the relationship between categorical node metadata and block structure of a network, as introduced in
Please cite the paper if you use the measure in your work.
Clone this repository to your local machine:
git clone https://github.com/lenafm/metablox.gitThen cd into the created metablox directory and use pip to install the package locally (note that you need to
have the graph-tool library installed for metablox to work).
pip install -e .
To calculate the metablox vector calculate_metadata_relevance function. Here, we show this on a co-purchasing network of political books1, which
includes a set of metadata of political leaning of the books (left, neutral, conservative), saved in a vertex property
called value.
(For a slightly more detailed demonstration of the calculate_metadata_relevance function and of the built-in plotting
method, see the example.ipynb notebook in the notebooks folder.)
import graph_tool.all as gt
from metablox.gamma import calculate_metadata_relevance
g = gt.collection.ns["polbooks"]
metadata = ['value']
gamma, edge_compression = calculate_metadata_relevance(g=g, metadata=metadata, refine_states=True)The calculate_metadata_relevance function returns a tuple with the values of gamma in the above example) contains an entry for each element in the metadata list.
For each metadata, it includes a nested dictionary with the elements of the
Notes:
- if you have a metadata partition for a network which you have not yet saved as a vertex property to the
graph-toolGraph object, you can also pass themetadataas a list ofnp.arrays - by default,
calculate_metadata_relevanceuses relevant functions from thegraph_toollibrary for the description length calculations; this can be changed by settinguse_gt = False
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
The research that was conducted to create the first version of this tool was funded by CNRS and the ERC Consolidator Grant Socsemics (grant #772743).
Footnotes
-
V. Krebs, "The political books network", unpublished, https://doi.org/10.2307/40124305 ↩

