Skip to main content

SpeakEasy2 community detection algorithm

Project description

Python SpeakEasy2 package

PyPI - Version PyPI - Python Version

Provides the SpeakEasy2 community detection algorithm to cluster graph's stored as igraph's data type. The algorithm is described in the Genome Biology article.

Example:

 import igraph as ig
 import speakeasy2 as se2

 g = ig.Graph.Famous("Zachary")
 memb = se2.cluster(g)

From the results, a node ordering can be computed to group nodes in a community together. This can be used as an index and works to display the community structure using a heatmap to view the adjacency matrix.

ordering = se2.order_nodes(g, memb)

SpeakEasy 2 can work with weighted graphs by either passing weights as a list with length equal to the number of edges or by using the igraph attribute table.

g.es["weight"] = [1 for _ in range(g.ecount())]
memb = se2.cluster(g)

By default, SpeakEasy 2 will check if there is an edge attribute associated with the graph named weight and use those as weights. If you want to use a different edge attribute, pass the name of the attribute.

memb = se2.cluster(g, weights="tie_strength")

Or if a graph has a weight edge attribute but you don't want to use them, explicitly pass None to the weights keyword argument.

Subclustering can be used to detect hierarchical community structure.

memb = se2.cluster(g, subcluster=2)

The number determines how many levels to perform community detection at. The default 1 means only to perform community detection at the top level (i.e. no subclustering). When subclustering, membership will be a list of igraph.VertexClustering objects, the top level membership will be the object at index 0.

A few other useful keywords arguments are max_threads, verbose, and seed. The max_thread keyword determines how many processors SpeakEasy 2 is allowed to use. By default the value returned by OpenMP is used. To prevent parallel processing, explicitly pass max_threads = 1 to the method.

The verbose option will cause the algorithm to print out some information about the process.

For reproducible results, the seed option sets the seed of the random number generator. Note: this is a random number generator managed by the underlying C library and is independent of other random number generators that might have been set in python.

Installation

speakeasy2 is available from pypi so it can be installed with pip or other package managers.

pip install --user speakeasy2

Building from source

This package can be built using CMake. It requires the flex, bison, and libxml2 dependencies for building igraph and poetry for managing python dependencies.

Since the igraph package is supplied by the vendored SE2 C library, after cloning the source directory, submodules most be recursively initialized.

git clone "https://github.com/SpeakEasy-2/python-speakeasy2"
cd python-speakeasy2
git submodule update --init --recursive

Then build the package using cmake:

cmake -B build
camke --build build

Since the compiled python shared libraries are built in the build directory, to use the local python package, link the shared libs to the python package:

cd speakeasy2
ln -s ../build/_speakeasy2.so
cd ..

Use poetry to install dependencies in a virtual env:

poetry install

It should now be possible to run scripts through poetry:

poetry run ipython path/to/script.py

Or enter a python repository with the private environment activate in the same way.

poetry run ipython

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

speakeasy2-0.1.1.tar.gz (20.0 kB view details)

Uploaded Source

Built Distributions

speakeasy2-0.1.1-cp312-cp312-win_amd64.whl (332.0 kB view details)

Uploaded CPython 3.12 Windows x86-64

speakeasy2-0.1.1-cp312-cp312-manylinux_2_31_x86_64.whl (320.3 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.31+ x86-64

speakeasy2-0.1.1-cp312-cp312-macosx_14_0_arm64.whl (294.8 kB view details)

Uploaded CPython 3.12 macOS 14.0+ ARM64

speakeasy2-0.1.1-cp311-cp311-win_amd64.whl (332.0 kB view details)

Uploaded CPython 3.11 Windows x86-64

speakeasy2-0.1.1-cp311-cp311-manylinux_2_31_x86_64.whl (320.3 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.31+ x86-64

speakeasy2-0.1.1-cp311-cp311-macosx_14_0_arm64.whl (294.8 kB view details)

Uploaded CPython 3.11 macOS 14.0+ ARM64

speakeasy2-0.1.1-cp310-cp310-win_amd64.whl (331.9 kB view details)

Uploaded CPython 3.10 Windows x86-64

speakeasy2-0.1.1-cp310-cp310-manylinux_2_31_x86_64.whl (320.3 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.31+ x86-64

speakeasy2-0.1.1-cp310-cp310-macosx_14_0_arm64.whl (294.7 kB view details)

Uploaded CPython 3.10 macOS 14.0+ ARM64

File details

Details for the file speakeasy2-0.1.1.tar.gz.

File metadata

  • Download URL: speakeasy2-0.1.1.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for speakeasy2-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ebc5520b378b31c0d796fd343217af69cb54b31f1c67bbf0944dc4284aebbe7a
MD5 a325385b02ee5c2dd4770190b74a73e2
BLAKE2b-256 dd57d7d4604babecab847cd243f461033377d31d1588391908e4da2c7a474003

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 088128ae8eec24cb369d075a54940fe272152059637c439096b113d615ec486a
MD5 cee83fc7a45ec54038a76064766bfcc4
BLAKE2b-256 3ca4ff0110375a5c0f43b7d9fbbdd1d9a2a5e5aa7071008de7d9349aa8d696ce

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.1-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.1-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 c2e193df0a1cc7fe8ad79e1ccd4c75d8d2f3757c878198de52a8e9d58f600e94
MD5 1a62861789c17689551f8e72a25b203d
BLAKE2b-256 ec027626ecda78b61af398e9b5d1b4abebf7d7013b576c00978fefb3f8df3b33

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.1-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.1-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 91801a864347e32e4646f10918c0fa5a86a854d2b3877c3940577d29ecd02ca7
MD5 36e80c26e8e7fc181901dcc9940d56aa
BLAKE2b-256 3fab665ef87bf40f1fc20a2181f20c8e1661d48104607a93c493a00b19fa8002

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fbe061fb06f9603e4eec49462f3fceb32c48df12da65ea492e36ed6362b7b27b
MD5 8052785a2d9a92fcd0bc4f82ed30b374
BLAKE2b-256 126811145e500afc077eaa5acf0292a294e1338ea2d5d86d19055809deba93b0

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.1-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.1-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 93cbc07fcc6cf3c787dd4dbbf9b1060b2e9ef7edb6da32fdd25080312e8c1d64
MD5 6fcec7724563c2dac9bc3120ed7ad2b2
BLAKE2b-256 6aa27d939190538fe92c51a020bd8e61b6eba17875c714e6200e20c82e66a63a

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.1-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.1-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f233d2dd326a0549c7d9ab6f8a6c6e9bce5434cb359cdadf80ef007081c8b742
MD5 29e7b029466248f7ec874401c93e55ab
BLAKE2b-256 95e168f83d93609e1a4b0cb10331d00a408a37867f72013f95a3499480d9f916

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b990804b40814eab34aeeae4aa5e2e0b5db5986ba4861a7e37d39795138f6b3f
MD5 27e7062f292c6f31363052923b1ed372
BLAKE2b-256 0dfd756ae4211756da76f11899787a9bd51fb9ec07150be4d191adafd51fb5eb

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.1-cp310-cp310-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.1-cp310-cp310-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 63d70de13dd03d7b76ab4d55582879cf42768b4838e9d1a37e4059684ef8179a
MD5 f2f31ce2bdbcd1ca04f0e8415e95d9f8
BLAKE2b-256 c9f307048397971d8f3f87313bd637e3c8d85970a0b7819eb3cb0c98e8316bbd

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.1-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.1-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f4dfb2e4987d6228854de7de7e3a4b767fe9a680e42f58656e07e6141a3f863e
MD5 d5b46d2613c7dd8dd9f876b5cd966546
BLAKE2b-256 569bbf903b6d6103c48e467d8fa8d62e62b9b523ea86fc9d92fcf1a09cc97885

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page