tgmm 0.1.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tgmm-0.1.5/PKG-INFO +123 -0
- tgmm-0.1.5/README.md +94 -0
- tgmm-0.1.5/setup.cfg +4 -0
- tgmm-0.1.5/setup.py +30 -0
- tgmm-0.1.5/tests/test_gmm.py +21 -0
- tgmm-0.1.5/tgmm/__init__.py +4 -0
- tgmm-0.1.5/tgmm/gmm.py +1275 -0
- tgmm-0.1.5/tgmm/gmm_init.py +247 -0
- tgmm-0.1.5/tgmm/metrics.py +937 -0
- tgmm-0.1.5/tgmm/plotting.py +289 -0
- tgmm-0.1.5/tgmm.egg-info/PKG-INFO +123 -0
- tgmm-0.1.5/tgmm.egg-info/SOURCES.txt +13 -0
- tgmm-0.1.5/tgmm.egg-info/dependency_links.txt +1 -0
- tgmm-0.1.5/tgmm.egg-info/requires.txt +7 -0
- tgmm-0.1.5/tgmm.egg-info/top_level.txt +1 -0
tgmm-0.1.5/PKG-INFO
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: tgmm
|
|
3
|
+
Version: 0.1.5
|
|
4
|
+
Summary: A Gaussian Mixture Model (GMM) based on Expectation-Maximisation (EM) implemented in PyTorch
|
|
5
|
+
Home-page: https://github.com/adriansousapoza/TorchGMM
|
|
6
|
+
Author: Your Name
|
|
7
|
+
Author-email: adrian.sousapoza@gmail.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: torch>=2.5.1
|
|
14
|
+
Requires-Dist: numpy>=1.23.0
|
|
15
|
+
Requires-Dist: matplotlib>=3.10.1
|
|
16
|
+
Provides-Extra: docs
|
|
17
|
+
Requires-Dist: Sphinx>=8.2.3; extra == "docs"
|
|
18
|
+
Requires-Dist: Pygments>=2.19.1; extra == "docs"
|
|
19
|
+
Dynamic: author
|
|
20
|
+
Dynamic: author-email
|
|
21
|
+
Dynamic: classifier
|
|
22
|
+
Dynamic: description
|
|
23
|
+
Dynamic: description-content-type
|
|
24
|
+
Dynamic: home-page
|
|
25
|
+
Dynamic: provides-extra
|
|
26
|
+
Dynamic: requires-dist
|
|
27
|
+
Dynamic: requires-python
|
|
28
|
+
Dynamic: summary
|
|
29
|
+
|
|
30
|
+
# TorchGMM: A Gaussian Mixture Model Implementation with PyTorch
|
|
31
|
+
|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
**TorchGMM** is a flexible implementation of Gaussian Mixture Models in PyTorch, supporting:
|
|
35
|
+
|
|
36
|
+
- EM Algorithm
|
|
37
|
+
- MAP Estimation with Priors
|
|
38
|
+
- Multiple Covariance Types
|
|
39
|
+
- Various Initialization Methods
|
|
40
|
+
- Comprehensive Clustering & Evaluation Metrics
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
1. **GaussianMixture**
|
|
45
|
+
- Full, diag, spherical, tied covariances
|
|
46
|
+
- MLE or MAP estimation with weight, mean, or covariance priors
|
|
47
|
+
|
|
48
|
+
2. **GMMInitializer**
|
|
49
|
+
- `kmeans`, `kpp` (k-means++), `random`, `points`, `maxdist`
|
|
50
|
+
|
|
51
|
+
3. **ClusteringMetrics**
|
|
52
|
+
- Unsupervised metrics (Silhouette, Davies-Bouldin, etc.)
|
|
53
|
+
- Supervised metrics (ARI, NMI, Purity, Confusion Matrix, etc.)
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
git clone https://github.com/YourUser/TorchGMM.git
|
|
59
|
+
cd TorchGMM
|
|
60
|
+
pip install -r requirements.txt
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Make sure you have PyTorch installed. For GPU usage, install the CUDA-enabled version of PyTorch as per the official instructions.
|
|
64
|
+
|
|
65
|
+
## Documentation
|
|
66
|
+
We use Sphinx to build documentation. The generated HTML pages live under docs/_build/html/. You can also read them online if you host them (e.g., on GitHub Pages).
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
cd docs
|
|
70
|
+
make clean
|
|
71
|
+
make html
|
|
72
|
+
# Open _build/html/index.html in a browser
|
|
73
|
+
# Linux
|
|
74
|
+
xdg-open _build/html/index.html
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The docs include:
|
|
78
|
+
|
|
79
|
+
API Reference for all modules (see GaussianMixture, GMMInitializer, and ClusteringMetrics).
|
|
80
|
+
Tutorials that walk through different usage scenarios (basic GMM, metrics, using priors).
|
|
81
|
+
Tutorials
|
|
82
|
+
We provide three Jupyter notebooks in the tutorials/ folder:
|
|
83
|
+
|
|
84
|
+
GMM Tutorial: Basic usage of the GaussianMixture class.
|
|
85
|
+
Metrics Tutorial: Demonstrates ClusteringMetrics and how to compare models.
|
|
86
|
+
Priors Tutorial: Shows how to use weight/mean/covariance priors (MAP).
|
|
87
|
+
To view or run them locally, just open them in Jupyter or VS Code.
|
|
88
|
+
|
|
89
|
+
## Basic Usage Example
|
|
90
|
+
Here’s a short snippet:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
import torch
|
|
94
|
+
from utils.gmm import GaussianMixture
|
|
95
|
+
|
|
96
|
+
# Generate random 2D data
|
|
97
|
+
X = torch.randn(500, 2)
|
|
98
|
+
|
|
99
|
+
# Create and fit the GMM
|
|
100
|
+
gmm = GaussianMixture(
|
|
101
|
+
n_features=2,
|
|
102
|
+
n_components=3,
|
|
103
|
+
covariance_type='full',
|
|
104
|
+
max_iter=200
|
|
105
|
+
)
|
|
106
|
+
gmm.fit(X)
|
|
107
|
+
|
|
108
|
+
print("Converged?:", gmm.converged_)
|
|
109
|
+
print("Cluster Weights:", gmm.weights_)
|
|
110
|
+
print("Cluster Means:", gmm.means_)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
You can also run on GPU by specifying device='cuda' in the GaussianMixture constructor (assuming a CUDA-capable device).
|
|
114
|
+
|
|
115
|
+
## Contributing
|
|
116
|
+
Fork the repository and create your feature branch.
|
|
117
|
+
Make changes and add tests or notebooks as appropriate.
|
|
118
|
+
Submit a pull request (PR) for review.
|
|
119
|
+
We welcome improvements to both the code and the documentation.
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
Released under the MIT License.
|
|
123
|
+
© 2025, Adrián A. Sousa-Poza
|
tgmm-0.1.5/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# TorchGMM: A Gaussian Mixture Model Implementation with PyTorch
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
**TorchGMM** is a flexible implementation of Gaussian Mixture Models in PyTorch, supporting:
|
|
6
|
+
|
|
7
|
+
- EM Algorithm
|
|
8
|
+
- MAP Estimation with Priors
|
|
9
|
+
- Multiple Covariance Types
|
|
10
|
+
- Various Initialization Methods
|
|
11
|
+
- Comprehensive Clustering & Evaluation Metrics
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
1. **GaussianMixture**
|
|
16
|
+
- Full, diag, spherical, tied covariances
|
|
17
|
+
- MLE or MAP estimation with weight, mean, or covariance priors
|
|
18
|
+
|
|
19
|
+
2. **GMMInitializer**
|
|
20
|
+
- `kmeans`, `kpp` (k-means++), `random`, `points`, `maxdist`
|
|
21
|
+
|
|
22
|
+
3. **ClusteringMetrics**
|
|
23
|
+
- Unsupervised metrics (Silhouette, Davies-Bouldin, etc.)
|
|
24
|
+
- Supervised metrics (ARI, NMI, Purity, Confusion Matrix, etc.)
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
git clone https://github.com/YourUser/TorchGMM.git
|
|
30
|
+
cd TorchGMM
|
|
31
|
+
pip install -r requirements.txt
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Make sure you have PyTorch installed. For GPU usage, install the CUDA-enabled version of PyTorch as per the official instructions.
|
|
35
|
+
|
|
36
|
+
## Documentation
|
|
37
|
+
We use Sphinx to build documentation. The generated HTML pages live under docs/_build/html/. You can also read them online if you host them (e.g., on GitHub Pages).
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
cd docs
|
|
41
|
+
make clean
|
|
42
|
+
make html
|
|
43
|
+
# Open _build/html/index.html in a browser
|
|
44
|
+
# Linux
|
|
45
|
+
xdg-open _build/html/index.html
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The docs include:
|
|
49
|
+
|
|
50
|
+
API Reference for all modules (see GaussianMixture, GMMInitializer, and ClusteringMetrics).
|
|
51
|
+
Tutorials that walk through different usage scenarios (basic GMM, metrics, using priors).
|
|
52
|
+
Tutorials
|
|
53
|
+
We provide three Jupyter notebooks in the tutorials/ folder:
|
|
54
|
+
|
|
55
|
+
GMM Tutorial: Basic usage of the GaussianMixture class.
|
|
56
|
+
Metrics Tutorial: Demonstrates ClusteringMetrics and how to compare models.
|
|
57
|
+
Priors Tutorial: Shows how to use weight/mean/covariance priors (MAP).
|
|
58
|
+
To view or run them locally, just open them in Jupyter or VS Code.
|
|
59
|
+
|
|
60
|
+
## Basic Usage Example
|
|
61
|
+
Here’s a short snippet:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import torch
|
|
65
|
+
from utils.gmm import GaussianMixture
|
|
66
|
+
|
|
67
|
+
# Generate random 2D data
|
|
68
|
+
X = torch.randn(500, 2)
|
|
69
|
+
|
|
70
|
+
# Create and fit the GMM
|
|
71
|
+
gmm = GaussianMixture(
|
|
72
|
+
n_features=2,
|
|
73
|
+
n_components=3,
|
|
74
|
+
covariance_type='full',
|
|
75
|
+
max_iter=200
|
|
76
|
+
)
|
|
77
|
+
gmm.fit(X)
|
|
78
|
+
|
|
79
|
+
print("Converged?:", gmm.converged_)
|
|
80
|
+
print("Cluster Weights:", gmm.weights_)
|
|
81
|
+
print("Cluster Means:", gmm.means_)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
You can also run on GPU by specifying device='cuda' in the GaussianMixture constructor (assuming a CUDA-capable device).
|
|
85
|
+
|
|
86
|
+
## Contributing
|
|
87
|
+
Fork the repository and create your feature branch.
|
|
88
|
+
Make changes and add tests or notebooks as appropriate.
|
|
89
|
+
Submit a pull request (PR) for review.
|
|
90
|
+
We welcome improvements to both the code and the documentation.
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
Released under the MIT License.
|
|
94
|
+
© 2025, Adrián A. Sousa-Poza
|
tgmm-0.1.5/setup.cfg
ADDED
tgmm-0.1.5/setup.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="tgmm",
|
|
5
|
+
version="0.1.5",
|
|
6
|
+
author="Your Name",
|
|
7
|
+
author_email="adrian.sousapoza@gmail.com",
|
|
8
|
+
description="A Gaussian Mixture Model (GMM) based on Expectation-Maximisation (EM) implemented in PyTorch",
|
|
9
|
+
long_description=open('README.md').read(),
|
|
10
|
+
long_description_content_type="text/markdown",
|
|
11
|
+
url="https://github.com/adriansousapoza/TorchGMM",
|
|
12
|
+
packages=find_packages(),
|
|
13
|
+
install_requires=[
|
|
14
|
+
"torch>=2.5.1",
|
|
15
|
+
"numpy>=1.23.0",
|
|
16
|
+
"matplotlib>=3.10.1"
|
|
17
|
+
],
|
|
18
|
+
extras_require={
|
|
19
|
+
"docs": [
|
|
20
|
+
"Sphinx>=8.2.3",
|
|
21
|
+
"Pygments>=2.19.1",
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
classifiers=[
|
|
25
|
+
"Programming Language :: Python :: 3",
|
|
26
|
+
"License :: OSI Approved :: MIT License",
|
|
27
|
+
"Operating System :: OS Independent",
|
|
28
|
+
],
|
|
29
|
+
python_requires='>=3.6',
|
|
30
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
import pytest
|
|
3
|
+
from tgmm import GaussianMixture
|
|
4
|
+
|
|
5
|
+
def test_gaussian_mixture_fit_predict():
|
|
6
|
+
# Generate a synthetic dataset
|
|
7
|
+
X = torch.randn(100, 2)
|
|
8
|
+
|
|
9
|
+
# Instantiate a GMM with 3 components
|
|
10
|
+
gmm = GaussianMixture(n_components=3, n_features=2)
|
|
11
|
+
gmm.fit(X)
|
|
12
|
+
|
|
13
|
+
# Predict cluster labels
|
|
14
|
+
labels = gmm.predict(X)
|
|
15
|
+
|
|
16
|
+
# Check that labels have the correct shape and values in the expected range
|
|
17
|
+
assert labels.shape == (100,)
|
|
18
|
+
assert labels.max() < 3 and labels.min() >= 0
|
|
19
|
+
|
|
20
|
+
if __name__ == '__main__':
|
|
21
|
+
pytest.main([__file__])
|