Metadata-Version: 2.4
Name: domino-mesoscale
Version: 0.1.0
Summary: DOMINO, Detection Of MesoscopIc structures via iNfOrmation criteria
Author-email: Mattia Marzi <mattia.marzi@imtlucca.it>
License: MIT License
        
        Copyright (c) 2025 Mattia Marzi
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://github.com/mattiamarzi/DOMINO
Project-URL: Repository, https://github.com/mattiamarzi/DOMINO
Keywords: networks,mesoscales,mesoscale-detection,sbm,leiden,bic
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.23
Requires-Dist: networkx>=3.0
Requires-Dist: scipy>=1.10
Requires-Dist: numba>=0.57
Provides-Extra: viz
Requires-Dist: matplotlib>=3.7; extra == "viz"
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: ruff>=0.5; extra == "dev"
Requires-Dist: pre-commit>=3.7; extra == "dev"
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: twine>=5; extra == "dev"
Dynamic: license-file

# DOMINO - Detection Of MesoscopIc structures via iNfOrmation criteria

DOMINO is a mesoscale detection framework that combines **Leiden optimization**
with **Bayesian Information Criterion (BIC) minimization** under several
Stochastic Block Model (SBM) likelihoods.

Supported modes:
- **binary**: SBM, dcSBM
- **signed**: signed SBM, signed dcSBM (positive, negative, absent)
- **weighted**: geometric-weight SBM, and its degree-corrected variant

The recommended public entry point is `detect`.

## Installation

Editable install (development):
```bash
python -m pip install -e ".[viz]"
```

Run tests:
```bash
python -m pip install pytest
pytest -q
```

## Quickstart

### Binary SBM (non degree-corrected)
```python
import numpy as np
import networkx as nx
from domino import detect

rng = np.random.default_rng(0)
A = (rng.random((100, 100)) < 0.05).astype(int)
A = np.triu(A, 1)
A = A + A.T
G = nx.from_numpy_array(A)

res = detect(G, A, mode="binary", degree_corrected=False, max_outer=3)
part, bic = res["partition"], res["bic"]
print("K:", len(part), "BIC:", bic)
```

### Signed SBM (non degree-corrected)
You can pass a single signed matrix `A` with negative entries.
```python
import numpy as np
import networkx as nx
from domino import detect

rng = np.random.default_rng(1)
n = 100
A = np.zeros((n, n), dtype=float)

# Two blocks with positive internal edges
A[:50, :50] = (rng.random((50, 50)) < 0.10).astype(float)
A[50:, 50:] = (rng.random((50, 50)) < 0.10).astype(float)

# Negative cross-block edges
A[:50, 50:] = -(rng.random((50, 50)) < 0.08).astype(float)
A[50:, :50] = A[:50, 50:].T
np.fill_diagonal(A, 0.0)
A = np.triu(A, 1)
A = A + A.T

G = nx.from_numpy_array((np.abs(A) > 0).astype(int))
res = detect(G, A, mode="signed", degree_corrected=False, max_outer=3)
part, bic = res["partition"], res["bic"]
print("K:", len(part), "BIC:", bic)
```

### Weighted SBM (geometric, non degree-corrected)
```python
import numpy as np
import networkx as nx
from domino import detect

rng = np.random.default_rng(2)
W = rng.poisson(2.0, size=(100, 100)).astype(float)
W = np.triu(W, 1)
W = W + W.T
np.fill_diagonal(W, 0.0)

G = nx.from_numpy_array((W > 0).astype(int))
res = detect(G, W, mode="weighted", degree_corrected=False, max_outer=3)
part, bic = res["partition"], res["bic"]
print("K:", len(part), "BIC:", bic)
```

## Documentation

- Usage notes: `docs/usage.md`
- Mathematical details: `docs/math.md`
- API quick reference: `docs/api_quick_reference.md`

## Continuous integration

GitHub Actions workflow: `.github/workflows/ci.yml`

## License

See `LICENSE`.
