An implementation of Stochastic Bloc model and Latent Block model efficient with sparse matrices.
Project description
sparsebm: a python implementation for the Latent Bloc Model (LBM) and Stochastic Bloc Model (SBM) for an efficient analysis of large graphs.
Installing
From pypi:
pip3 install sparsebm
To use GPU acceleration:
pip3 install sparsebm[gpu]
Or
pip3 install sparsebm
pip3 install cupy
Example
Generate SBM Synthetic graph
- Generate a synthetic graph to analyse with SBM:
import numpy as np
from sparsebm import generate_bernouilli_SBM
#
# Define the properties of your graph
#
number_of_nodes = 10 ** 3
number_of_clusters = 4
cluster_proportions = np.ones(number_of_clusters) / number_of_clusters
connection_probabilities = np.array([[0.05, 0.018, 0.006, 0.0307], [0.018, 0.037, 0, 0], [0.006, 0, 0.055, 0.012], [0.0307, 0, 0.012, 0.043]])
#
# The graph is generated
#
data = generate_bernouilli_SBM(number_of_nodes, number_of_clusters, connection_probabilities, cluster_proportions, symetric=True)
graph, cluster_indicator, = (data["X"], data["Y"])
Infere with sparsebm SBM_bernouilli:
- Use the bernouilli Stochastic Bloc Model:
from sparsebm import SBM_bernouilli
model = SBM_bernouilli(
number_of_clusters,
gpu_number=None, # Or give the desired GPU index.
symetric=True,
)
model.fit(graph)
print("Labels:")
print(model.labels)
To use GPU acceleration, CUPY needs to be installed and replace gpu_number to the desired GPU index.
Generate LBM Synthetic graph
- Generate a synthetic graph to analyse with LBM:
from sparsebm import generate_bernouilli_LBM
import numpy as np
#
# Define the properties of your graph
#
number_of_rows = 10 ** 3
number_of_columns = 2* number_of_rows
nb_row_clusters, nb_column_clusters = 3, 4
row_cluster_proportions = np.ones(nb_row_clusters) / nb_row_clusters
column_cluster_proportions = np.ones(nb_column_clusters) / nb_column_clusters
connection_probabilities = np.array([[0.1, 0.0125, 0.0125, 0.05], [0.0125, 0.1, 0.0125, 0.05], [0, 0.0125, 0.1, 0]])
#
# The graph is generated
#
data = generate_bernouilli_LBM(
number_of_rows,
number_of_columns,
nb_row_clusters,
nb_column_clusters,
connection_probabilities,
row_cluster_proportions,
column_cluster_proportions
)
graph, row_cluster_indicator, column_cluster_indicator, = (data["X"], data["Y1"], data["Y2"])
Infere with sparsebm LBM_bernouilli:
- Use the bernouilli Latent Bloc Model:
from sparsebm import LBM_bernouilli
model = LBM_bernouilli(
nb_row_clusters,
nb_column_clusters,
gpu_number=None, # Or give the desired GPU index.
)
model.fit(graph)
print("Row labels:")
print(model.row_labels)
print("Column labels:")
print(model.column_labels)
To use GPU acceleration, CUPY needs to be installed and set gpu_number the desired GPU index.
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
sparsebm-0.2.tar.gz
(11.2 kB
view details)
Built Distribution
sparsebm-0.2-py3-none-any.whl
(13.3 kB
view details)
File details
Details for the file sparsebm-0.2.tar.gz
.
File metadata
- Download URL: sparsebm-0.2.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a96088d12e76c107cd244c078c17ce7ca8d2c6b18cb2d12001827ba013ca9d27 |
|
MD5 | 88a4597af1dab74fa1d2dc3b708d3eed |
|
BLAKE2b-256 | 8b533e15bf9021e78eb83599322200d3c757d0c006fcac98d1786df8915e4fd6 |
File details
Details for the file sparsebm-0.2-py3-none-any.whl
.
File metadata
- Download URL: sparsebm-0.2-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce0938a450b4a6f4dc07590b484006ce18b1456f05db08fb6fc2a3a1c3ecb8d8 |
|
MD5 | 26749cbeb0ca29198e8624914ba6e4f6 |
|
BLAKE2b-256 | 746d6b89548f0ede27650a4d80c4bcf4f7261a323e9b95e31d23e04c8105e2f3 |