Skip to main content

Mixture-Models

codecov License: MIT

A one-stop Python library for fitting a wide range of mixture models such as Mixture of Gaussians, Students'-T, Factor-Analyzers, Parsimonious Gaussians, MCLUST, etc.

Table of Contents

Why this library

While there are several packages in R and Python which support various kinds of mixture-models, each one of them has their own API and syntax. Further, in almost all those libraries, the inference proceeds via Expectation-Maximization (a Quasi first order method) which makes them unsuitable for high-dimensional data.

This library attempts to provide a seamless and unified interface for fitting a wide-range of mixture models. Unlike many existing packages that rely on Expectation-Maximization for inference, our approach leverages Automatic Differentiation tools and gradient-based optimization which makes it well equipped to handle high-dimensional data and second order optimization routines.

Installation and Quick Start

Installation is straightforward:

pip install Mixture-Models

Quick Start

The estimation procedure consists of 3 simple steps:

### Simulate some dummy data using the built-in function make_pinwheel
data = make_pinwheel(radial_std=0.3, tangential_std=0.05, num_classes=3,
                    num_per_class=100, rate=0.4,rs=npr.RandomState(0))

### Plot the three clusters
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(data[:, 0], data[:, 1], 'k.')
plt.show()

### STEP 1 - Choose a mixture model to fit on your data
my_model = GMM(data)

### STEP 2 - Initialize your model with some parameters    
init_params = my_model.init_params(num_components = 3,scale = 0.5)

### STEP 3 - Learn the parameters using some optimization routine
params_store = my_model.fit(init_params,"Newton-CG")

Once the model is trained on the data (which is a numpy matrix of shape (num_datapoints, num_dim)), post-hoc analysis can be performed:

for params in params_store:
    print("likelihood",my_model.likelihood(params))
    print("aic,bic",my_model.aic(params),my_model.bic(params))

np.array(my_model.labels(data,params_store[-1])) ## final predicted labels

Example notebooks are available on the project Github repo.

Supported models and optimization routines

There are more than 30+ different mixture-models, spread across five model families, currently supported by the library. Here is a brief overview of the different model families supported:

The project repo 'Examples' folder includes more detailed illustrations for all these models, as well as a README.md for advanced users who want to fit custom mixture models, or tinker with the settings for the above procedure.

Currently, four main gradient based optimizers are available:

  • "grad_descent": Stochastic Gradient Descent (SGD) with momentum
  • "rms_prop": Root-mean-squared propagation (RMS-Prop)
  • "adam": Adaptive moments (ADAM)
  • "Newton-CG": Newton-Conjugate Gradient (Newton CG)

The details about each optimizer and its optional input parameters are given in the PDF in the 'Examples' folder. The output of fit method is the set of all points in the parameter space that the optimizer has traversed during the optimization i.e. list of parameters with the final entry in the list being the final fitted solution. We have a detailed notebook Optimizers_illustration.ipynb in the 'Examples' folder on Github.

Contributing

We welcome contributions to our library. Our code base is highly modularized, making it easy for new contributors to extend its capabilities and add support for additional models. If you are interested in contributing to the library, check out the contribution guide.

If you're unsure where to start, check out our open issues for inspiration on the kind of problems you can work on. Alternately, you could also open a new issue so we can discuss the best strategy for integrating your work.


If you use this package, please consider citing our research as

@article{kasa2020model, title={Model-based Clustering using Automatic Differentiation: Confronting Misspecification and High-Dimensional Data}, author={Kasa, Siva Rajesh and Rajan, Vaibhav}, journal={arXiv preprint arXiv:2007.12786}, year={2020} }

Metadata

Release files for Mixture-Models 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Mixture-Models 0.0.8
File Size Uploaded Provenance Actions
Mixture_Models-0.0.8.tar.gz 49.2 kB Without provenance Details for Mixture_Models-0.0.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for Mixture-Models 0.0.8
File Interpreter ABI Platform Actions
Mixture_Models-0.0.8-py3-none-any.whl Python 3 none any Details for Mixture_Models-0.0.8-py3-none-any.whl

Total release size: 95.8 kB

Release files / Mixture_Models-0.0.8.tar.gz

Download URL Mixture_Models-0.0.8.tar.gz
Size 49.2 kB
Tags Source
SHA-256 checksum
How to use checksums
23605474b22f93bafc2b70455c9276eaa185dca8086d7b47f46854e3cacbeca6
BLAKE2b-256 checksum
How to use checksums
b00cb5716daa9a1ae211c2233c3f4b2c0e51a3c594861ea974da2b532fc8e516
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.10

Release files / Mixture_Models-0.0.8-py3-none-any.whl

Download URL Mixture_Models-0.0.8-py3-none-any.whl
Size 46.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3000f8a552cfdb3581ce65db4f7b1f90b6d431fe3cf0bf5fbb2167d973a1d3be
BLAKE2b-256 checksum
How to use checksums
efffb1568d8b4749409c1dbd75adf7e0390bcfbc9c0433eb66354eb1658058d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.10

Security for Mixture-Models 0.0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page