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.

This uses a rewrite of the algorithm used in the publication, to see a comparison to the original implementation see the benchmarks

Example:

 import igraph as ig
 import speakeasy2 as se2

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

Membership is returned as an igraph.clustering.VertexClustering object. Use print to view the membership:

print(memb)
Clustering with 34 elements and 9 clusters
[0] 0, 1, 2, 3, 7, 12, 13, 17, 19, 21
[1] 14, 15, 18, 20, 22, 32, 33
[2] 8, 30
[3] 26, 29
[4] 11
[5] 23, 24, 25, 27, 31
[6] 9
[7] 28
[8] 4, 5, 6, 10, 16

Or to convert to a python list for use outside of igraph run memb.membership.

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

Compilation depends on a C compiler, CMake, and (optionally) ninja.

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

The CMake calls are wrapped into the python build logic in the build_script.py (this is a poetry specific method for building C extensions). This allows the package to be built using various python build backends. Since this package uses poetry, the suggested way to build the package is invoking poetry build and poetry install, which will install in development mode.

For convenience, the provided Makefile defines the install target to do this and clean-dist to clear all generated files (as well as other targets, see the file for more).

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

If you don't want to use poetry, it's possible to build with other method in their standard way. For example python -m build or pip install --editable . should both work.

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.3.tar.gz (2.7 MB view details)

Uploaded Source

Built Distributions

speakeasy2-0.1.3-cp313-cp313-manylinux_2_35_x86_64.whl (336.5 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.35+ x86-64

speakeasy2-0.1.3-cp313-cp313-macosx_14_0_arm64.whl (301.6 kB view details)

Uploaded CPython 3.13 macOS 14.0+ ARM64

speakeasy2-0.1.3-cp313-cp313-macosx_13_0_x86_64.whl (299.9 kB view details)

Uploaded CPython 3.13 macOS 13.0+ x86-64

speakeasy2-0.1.3-cp312-cp312-manylinux_2_35_x86_64.whl (336.4 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.35+ x86-64

speakeasy2-0.1.3-cp312-cp312-macosx_14_0_arm64.whl (301.6 kB view details)

Uploaded CPython 3.12 macOS 14.0+ ARM64

speakeasy2-0.1.3-cp312-cp312-macosx_13_0_x86_64.whl (299.9 kB view details)

Uploaded CPython 3.12 macOS 13.0+ x86-64

speakeasy2-0.1.3-cp311-cp311-manylinux_2_35_x86_64.whl (336.3 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.35+ x86-64

speakeasy2-0.1.3-cp311-cp311-macosx_14_0_arm64.whl (301.6 kB view details)

Uploaded CPython 3.11 macOS 14.0+ ARM64

speakeasy2-0.1.3-cp311-cp311-macosx_13_0_x86_64.whl (299.9 kB view details)

Uploaded CPython 3.11 macOS 13.0+ x86-64

speakeasy2-0.1.3-cp310-cp310-manylinux_2_35_x86_64.whl (336.2 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.35+ x86-64

speakeasy2-0.1.3-cp310-cp310-macosx_14_0_arm64.whl (301.6 kB view details)

Uploaded CPython 3.10 macOS 14.0+ ARM64

speakeasy2-0.1.3-cp310-cp310-macosx_13_0_x86_64.whl (294.5 kB view details)

Uploaded CPython 3.10 macOS 13.0+ x86-64

File details

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

File metadata

  • Download URL: speakeasy2-0.1.3.tar.gz
  • Upload date:
  • Size: 2.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for speakeasy2-0.1.3.tar.gz
Algorithm Hash digest
SHA256 2c4cf24e8d3ec2fac465fab0eaf25247789e1ca0272da23098e57268681a46d1
MD5 eaba53befb7ab5eeb4cb8c460a57d791
BLAKE2b-256 fc84df5281482af575f368d9e279279f2929b9c9b000c4419d1d52e1d925c020

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.3-cp313-cp313-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.3-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 948d3b864fd19e0f3b889cd40f0346d67d95f6fa9c62f34e4469ab3dbae7ea8e
MD5 c495f89e5d19e250d83cd4d6a38d79c3
BLAKE2b-256 77daf34ff0a76af464402c13f839aef35a0cd94e464148210016e532287c21cd

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.3-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.3-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 517af9ada55bcc704d57c8fe847c6a952c798149889c7710226867cd15dd22a8
MD5 d0e5494a901e7e2f43a6f1fdcd1de59c
BLAKE2b-256 3a0f659fc6cf5c97fb865db85cf191b45f05bca8d41d15af481979c322e923eb

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.3-cp313-cp313-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.3-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 2a2063e2568d2cbf531b5630e0810ef648e8362921a67c1d148a06d0af516fb5
MD5 da5dd60e0df78fb3356777bd52787962
BLAKE2b-256 8de6eb50846299b035511237a78686ab69955c9c682461c6bcea23e38ab28ec4

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.3-cp312-cp312-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.3-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 f5fdc90489c165d8b6d33d9faf6fbf2defb763bdcd9dd361d231a9efd8df47ee
MD5 e9756036938eafa9555e405438d1aaf6
BLAKE2b-256 21f8455c11ae72e13dc39127b6e2303901b346ef30c3fb39fd408d7b6e63d702

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for speakeasy2-0.1.3-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c79d6a2e9c8dff19d5421ca3a9f9754ae2a584256449d6216d6264a77c8283ea
MD5 627f20d0fdd008dad1a68fa4884a6ec8
BLAKE2b-256 e10e497102bfd99d141099b323177b27daabdd12e39bc453fb4302c67c5ff9b1

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.3-cp312-cp312-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.3-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 2f0d714c144699d55513491701ac16dccaa0197e7a8b89aa4f1a7cc2a1b7724a
MD5 a711287b256204688c4ea794e5420020
BLAKE2b-256 95f4c591cd2cb14234ed3505b584bb92a642e0f5e7c9c7af81988c0f382e0f5c

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.3-cp311-cp311-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.3-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 4b5bb89e42c4fcf4cd8f2c585f6378c214087add9b7f6cdf8017b59018c8b15e
MD5 a32dd1ea3b9d74a9a7730c7920b3a829
BLAKE2b-256 3432ec3b84b74f8b464c2ef1279971e65d2fd38544f629be3c5d846df9c3c217

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for speakeasy2-0.1.3-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 56bfba53d78681ad04b8450547ea7554a62c877fc404c6e8d6b1a266ab132067
MD5 28d5c0afdab2b90b55a3386064909c64
BLAKE2b-256 5a14996f0cb61c05bf35176acb5a393200ffb79e513937df8df64eb02eb72889

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.3-cp311-cp311-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.3-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 ccec32ac584520b6cf14a440906f572b9200d8f5309f456ab196302809e6544a
MD5 5c80beec29a80e3a04252b022a48874e
BLAKE2b-256 5304b4f240db70c2ea58854d836a4cec0d71ce5cb7e86f526031cfd7b7a79d8b

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.3-cp310-cp310-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.3-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 ae3d6f18684d4990aa2da5196f51fa1493bb02e70ae4c1a33e8b0f6c232d1eed
MD5 1003d76a202e02d485a560454cfa1b82
BLAKE2b-256 925b858ea04c8db9125c7b8108b756f4daf68b134d9b7bb3b97604929874b57c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for speakeasy2-0.1.3-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6bba57f6d06f08097d8ff3f41ed5367b86d76234deecd97c021d298ae4933d27
MD5 2bde3cb76c61fb717573eb9d4ca7cd0a
BLAKE2b-256 b1b39f5cd95cc9833dd4cacded5bf643cc945c49695ad8f28c7d511c04308902

See more details on using hashes here.

File details

Details for the file speakeasy2-0.1.3-cp310-cp310-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for speakeasy2-0.1.3-cp310-cp310-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 db738637763c302c1fbb547f2a5a70ba9a34f6dacb09ed1ebda9a19d3346f57b
MD5 b463a8d1ef7a59a09d5cd89fc21f93cf
BLAKE2b-256 a80a69938a036d6c4281bc82790880ef97fd55aa10963944a46512faed29b6f5

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