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.2.tar.gz (20.0 kB view details)

Uploaded Source

Built Distributions

speakeasy2-0.1.2-cp312-cp312-win_amd64.whl (334.7 kB view details)

Uploaded CPython 3.12 Windows x86-64

speakeasy2-0.1.2-cp312-cp312-manylinux_2_31_x86_64.whl (322.8 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.31+ x86-64

speakeasy2-0.1.2-cp312-cp312-macosx_14_0_arm64.whl (296.3 kB view details)

Uploaded CPython 3.12 macOS 14.0+ ARM64

speakeasy2-0.1.2-cp311-cp311-win_amd64.whl (334.7 kB view details)

Uploaded CPython 3.11 Windows x86-64

speakeasy2-0.1.2-cp311-cp311-manylinux_2_31_x86_64.whl (322.8 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.31+ x86-64

speakeasy2-0.1.2-cp311-cp311-macosx_14_0_arm64.whl (296.3 kB view details)

Uploaded CPython 3.11 macOS 14.0+ ARM64

speakeasy2-0.1.2-cp310-cp310-win_amd64.whl (334.7 kB view details)

Uploaded CPython 3.10 Windows x86-64

speakeasy2-0.1.2-cp310-cp310-manylinux_2_31_x86_64.whl (322.8 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.31+ x86-64

speakeasy2-0.1.2-cp310-cp310-macosx_14_0_arm64.whl (296.2 kB view details)

Uploaded CPython 3.10 macOS 14.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for speakeasy2-0.1.2.tar.gz
Algorithm Hash digest
SHA256 5c2f5469c97a3a8027cb2e1a8985b8a85c0cd98774e8feeb9babab422abc657b
MD5 7acdfaccc294e12e7a7439dff32bbf7c
BLAKE2b-256 c29613276bf45e9530cf1661017d5c40adb910fc97e9fda3373f300545800962

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for speakeasy2-0.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 232dac6ece5944eb45e8acfbc368283c6cf62e8ec290667ea6354615a8abc7fe
MD5 f04031df32d7c5fc8db36fa037ed9f88
BLAKE2b-256 42df21a07c6d8a686ae8d329b2bdff4264ecef147a923e91cb3b6307a65fb4bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for speakeasy2-0.1.2-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 d253877557cb510e5975488d6f1a171203647f206670b97038fcab690648bdad
MD5 e05c5e1d9f7631589fb9b444861006b6
BLAKE2b-256 9a31158b87d9bb2ad532189195b13daa058be3420ba3bce0b648b47d93552fda

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for speakeasy2-0.1.2-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f7be07f7fa6027200c042619c84892f235b0b1e27a78289a6dd69ac67df97a59
MD5 d8dbb2ad40d3c8a16d9a7cfac238e6fe
BLAKE2b-256 765d6d2d29ef907eefa7e232e6edf372f0c60e89e753a50a504a306252278a8f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for speakeasy2-0.1.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0de20d547eab690192c45fb0c89184981aae58ddf6564834706107c990c62b2c
MD5 40b497d9c15d0165838adae4a3246435
BLAKE2b-256 ae864feca630be4e07330471126c7e1bbb6548bbb75f6e112c401650545fd2a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for speakeasy2-0.1.2-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 83daf90156f8061604a68b5a9f865685279bf39b3e168f59d9da1f51fee38f02
MD5 7c4854c15f8e72dedabf0ec0f94e62b9
BLAKE2b-256 8d54b6965042dbeb6983b35262e6673650b5a41f6c4175158b6360637bc3905f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for speakeasy2-0.1.2-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8f05e9853f93752fe752821075e2d11986526a40fae7c1f5291dd9e74f13977e
MD5 93be4fd5d7bd8c7ac8a2d15f5fe29de2
BLAKE2b-256 00bc107828cde4344a3790544297f649e48d73d625d76b9d4386af3075dad72c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for speakeasy2-0.1.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 bb9b5e5e65a561810ad68651a2d88d7664e8a8dad997d154e4837cdcb66e82e2
MD5 7524217fb0f6f6e3452af7c2cebb96c8
BLAKE2b-256 dba087fe2593d3e8e9fba6cf47c732887ce9dae2a7bb378f1ef87412788e7cf4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for speakeasy2-0.1.2-cp310-cp310-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 a31b3a3c1675a03be10e22d93ca1185cc7ccfc7e552e1ce4e78c68d7293562ab
MD5 d5b08d40b369cbef8fb8f2b13f8fedde
BLAKE2b-256 8dc0e10325f935ac40e2fcc6420b5c33217f6b520087e97bbc5f277dee884223

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for speakeasy2-0.1.2-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d4d26e4a9ba7c49a98b2eea64432abb5db032ecca861155c76b9d81cb3efde31
MD5 f79eed17cc16004c666fdf5a49de58c3
BLAKE2b-256 44d82e6305337898445a6846742b05fa08d6270927fd5b94fb6e6063e797f468

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