Name | sparsebm JSON |
Version |
1.6.7
JSON |
| download |
home_page | |
Summary | An implementation of Stochastic Bloc model and Latent Block model efficient with sparse matrices |
upload_time | 2023-07-17 13:50:33 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.7 |
license | MIT License |
keywords |
datamining
graph
lbm
sbm
variationnal
sparse
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Getting started with SparseBM
SparseBM is a python module for handling sparse graphs with Block Models.
The module is an implementation of the variational inference algorithm for the Stochastic Block Model (SBM) and the Latent Block Model (LBM) for sparse graphs, which leverages the sparsity of edges to scale to very large numbers of nodes. The module can use [Cupy] to take advantage of the hardware acceleration provided by graphics processing units (GPU).
## Installing
The SparseBM module is distributed through the [PyPI repository](https://pypi.org/project/sparsebm/) and the documentation is available [here](https://jbleger.gitlab.io/sparsebm).
### With GPU acceleration (recommended if GPUs are available)
This option is recommended if GPUs are available to speedup computation.
With the package installer pip:
```
pip3 install sparsebm[gpu]
```
The [Cupy] module will be installed as a dependency.
[Cupy]: https://cupy.dev/
Alternatively [Cupy] can be installed separately, and will be used by `sparsebm`
if available.
```
pip3 install sparsebm
pip3 install cupy
```
### Without GPU acceleration
Without GPU acceleration, only CPUs are used. The infererence process still uses
sparsity, but no GPU linear algebra operations.
```
pip3 install sparsebm
```
For users who do not have GPU, we recommend the free serverless Jupyter notebook
environment provided by [Google Colab] where the Cupy module is already
installed and ready to be used with a GPU.
Complete examples (notebook for [Google Colab] and scripts) are given in the
Examples section (and in the `examples/` of the repository).
[Google Colab]: https://colab.research.google.com/
## Quick example with the Stochastic Block Model
- Generate a synthetic graph for analysis with SBM:
```python
from sparsebm import generate_SBM_dataset
dataset = generate_SBM_dataset(symmetric=True)
```
- Infer with the Bernoulli Stochastic Bloc Model:
```python
from sparsebm import SBM
# A number of classes must be specified. Otherwise see model selection.
model = SBM(dataset.clusters)
model.fit(dataset.data, symmetric=True)
print("Labels:", model.labels)
```
- Compute performance:
```python
from sparsebm.utils import ARI
ari = ARI(dataset.labels, model.labels)
print("Adjusted Rand index is {:.2f}".format(ari))
```
- Model selection: Infer with the Bernoulli Stochastic Bloc Model with an unknown number of groups:
```python
from sparsebm import ModelSelection
model_selection = ModelSelection("SBM")
models = model_selection.fit(dataset.data, symmetric=True)
print("Labels:", models.best.labels)
from sparsebm.utils import ARI
ari = ARI(dataset.labels, models.best.labels)
print("Adjusted Rand index is {:.2f}".format(ari))
```
## Quick example with the Latent Block Model
- Generate a synthetic graph for analysis with LBM:
```python
from sparsebm import generate_LBM_dataset
dataset = generate_LBM_dataset()
```
- Use the Bernoulli Latent Bloc Model:
```python
from sparsebm import LBM
# A number of classes must be specified. Otherwise see model selection.
model = LBM(
dataset.row_clusters,
dataset.column_clusters,
n_init_total_run=1,
)
model.fit(dataset.data)
print("Row Labels:", model.row_labels)
print("Column Labels:", model.column_labels)
```
- Compute performance:
```python
from sparsebm.utils import CARI
cari = CARI(
dataset.row_labels,
dataset.column_labels,
model.row_labels,
model.column_labels,
)
print("Co-Adjusted Rand index is {:.2f}".format(cari))
```
- Model selection: Infer with the Bernoulli Latent Bloc Model with an unknown number of groups:
```python
from sparsebm import ModelSelection
model_selection = ModelSelection("LBM")
models = model_selection.fit(dataset.data)
print("Row Labels:", models.best.row_labels)
print("Column Labels:", models.best.column_labels)
from sparsebm.utils import CARI
cari = CARI(
dataset.row_labels,
dataset.column_labels,
models.best.row_labels,
models.best.column_labels,
)
print("Co-Adjusted Rand index is {:.2f}".format(cari))
```
Raw data
{
"_id": null,
"home_page": "",
"name": "sparsebm",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "Jean-Benoist Leger <jbleger@hds.utc.fr>",
"keywords": "datamining,graph,LBM,SBM,variationnal,sparse",
"author": "",
"author_email": "Gabriel Frisch <gabriel.frisch@hds.utc.fr>, Jean-Benoist Leger <jbleger@hds.utc.fr>",
"download_url": "https://files.pythonhosted.org/packages/a7/9e/ec5313de29f1aed3f6ea26725172326d0aefcd67fa3701876bebe49eba79/sparsebm-1.6.7.tar.gz",
"platform": null,
"description": "# Getting started with SparseBM\n\nSparseBM is a python module for handling sparse graphs with Block Models.\nThe module is an implementation of the variational inference algorithm for the Stochastic Block Model (SBM) and the Latent Block Model (LBM) for sparse graphs, which leverages the sparsity of edges to scale to very large numbers of nodes. The module can use [Cupy] to take advantage of the hardware acceleration provided by graphics processing units (GPU).\n\n## Installing\n\nThe SparseBM module is distributed through the [PyPI repository](https://pypi.org/project/sparsebm/) and the documentation is available [here](https://jbleger.gitlab.io/sparsebm).\n\n\n### With GPU acceleration (recommended if GPUs are available)\n\nThis option is recommended if GPUs are available to speedup computation.\n\nWith the package installer pip:\n\n```\npip3 install sparsebm[gpu]\n```\n\nThe [Cupy] module will be installed as a dependency.\n\n[Cupy]: https://cupy.dev/\n\nAlternatively [Cupy] can be installed separately, and will be used by `sparsebm`\nif available.\n\n```\npip3 install sparsebm\npip3 install cupy\n```\n\n### Without GPU acceleration\n\nWithout GPU acceleration, only CPUs are used. The infererence process still uses\nsparsity, but no GPU linear algebra operations.\n\n```\npip3 install sparsebm\n```\n\nFor users who do not have GPU, we recommend the free serverless Jupyter notebook\nenvironment provided by [Google Colab] where the Cupy module is already\ninstalled and ready to be used with a GPU.\n\nComplete examples (notebook for [Google Colab] and scripts) are given in the\nExamples section (and in the `examples/` of the repository).\n\n[Google Colab]: https://colab.research.google.com/\n\n## Quick example with the Stochastic Block Model\n\n- Generate a synthetic graph for analysis with SBM:\n\n ```python\n from sparsebm import generate_SBM_dataset\n\n dataset = generate_SBM_dataset(symmetric=True)\n ```\n\n\n- Infer with the Bernoulli Stochastic Bloc Model:\n\n ```python\n from sparsebm import SBM\n\n # A number of classes must be specified. Otherwise see model selection.\n model = SBM(dataset.clusters)\n model.fit(dataset.data, symmetric=True)\n print(\"Labels:\", model.labels)\n ```\n\n- Compute performance:\n\n ```python\n from sparsebm.utils import ARI\n ari = ARI(dataset.labels, model.labels)\n print(\"Adjusted Rand index is {:.2f}\".format(ari))\n ```\n\n- Model selection: Infer with the Bernoulli Stochastic Bloc Model with an unknown number of groups:\n ```python\n from sparsebm import ModelSelection\n\n model_selection = ModelSelection(\"SBM\")\n models = model_selection.fit(dataset.data, symmetric=True)\n print(\"Labels:\", models.best.labels)\n\n from sparsebm.utils import ARI\n ari = ARI(dataset.labels, models.best.labels)\n print(\"Adjusted Rand index is {:.2f}\".format(ari))\n ```\n\n## Quick example with the Latent Block Model\n\n- Generate a synthetic graph for analysis with LBM:\n\n ```python\n from sparsebm import generate_LBM_dataset\n\n dataset = generate_LBM_dataset()\n ```\n\n - Use the Bernoulli Latent Bloc Model:\n\n ```python\n from sparsebm import LBM\n\n # A number of classes must be specified. Otherwise see model selection.\n model = LBM(\n dataset.row_clusters,\n dataset.column_clusters,\n n_init_total_run=1,\n )\n model.fit(dataset.data)\n print(\"Row Labels:\", model.row_labels)\n print(\"Column Labels:\", model.column_labels)\n ```\n\n- Compute performance:\n\n ```python\n from sparsebm.utils import CARI\n cari = CARI(\n dataset.row_labels,\n dataset.column_labels,\n model.row_labels,\n model.column_labels,\n )\n print(\"Co-Adjusted Rand index is {:.2f}\".format(cari))\n ```\n\n- Model selection: Infer with the Bernoulli Latent Bloc Model with an unknown number of groups:\n ```python\n from sparsebm import ModelSelection\n\n model_selection = ModelSelection(\"LBM\")\n models = model_selection.fit(dataset.data)\n print(\"Row Labels:\", models.best.row_labels)\n print(\"Column Labels:\", models.best.column_labels)\n\n from sparsebm.utils import CARI\n cari = CARI(\n dataset.row_labels,\n dataset.column_labels,\n models.best.row_labels,\n models.best.column_labels,\n )\n print(\"Co-Adjusted Rand index is {:.2f}\".format(cari))\n ```\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "An implementation of Stochastic Bloc model and Latent Block model efficient with sparse matrices",
"version": "1.6.7",
"project_urls": {
"Documentation": "https://jbleger.gitlab.io/sparsebm",
"Repository": "https://gitlab.com/jbleger/sparsebm"
},
"split_keywords": [
"datamining",
"graph",
"lbm",
"sbm",
"variationnal",
"sparse"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "716bb724c8f7053beac85bef72dbe2e46b6cbc1becad348902915fce3f117c8e",
"md5": "f1e44f00bef977230b51ee3253c370dc",
"sha256": "f4ba270ccd74edbde6bdf6845db6fb78c72e084893ad2524b665659038b40123"
},
"downloads": -1,
"filename": "sparsebm-1.6.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f1e44f00bef977230b51ee3253c370dc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 37884,
"upload_time": "2023-07-17T13:50:31",
"upload_time_iso_8601": "2023-07-17T13:50:31.458593Z",
"url": "https://files.pythonhosted.org/packages/71/6b/b724c8f7053beac85bef72dbe2e46b6cbc1becad348902915fce3f117c8e/sparsebm-1.6.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a79eec5313de29f1aed3f6ea26725172326d0aefcd67fa3701876bebe49eba79",
"md5": "204c63d01ba38ce5cc48a5bb9b63ff72",
"sha256": "a0d12f395b580e96bc0cc2ede93ea792adbb1b3228159705f11556cdb67dd4d8"
},
"downloads": -1,
"filename": "sparsebm-1.6.7.tar.gz",
"has_sig": false,
"md5_digest": "204c63d01ba38ce5cc48a5bb9b63ff72",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 140022,
"upload_time": "2023-07-17T13:50:33",
"upload_time_iso_8601": "2023-07-17T13:50:33.092110Z",
"url": "https://files.pythonhosted.org/packages/a7/9e/ec5313de29f1aed3f6ea26725172326d0aefcd67fa3701876bebe49eba79/sparsebm-1.6.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-17 13:50:33",
"github": false,
"gitlab": true,
"bitbucket": false,
"codeberg": false,
"gitlab_user": "jbleger",
"gitlab_project": "sparsebm",
"lcname": "sparsebm"
}