Skip to main content

Bivariate von Mises Mixture Model for Circular Data Analysis

Project description

vonMisesMixtureModel

PyPI version Python package Examples

A PyTorch-based implementation of an Expectation-Maximization (EM) algorithm for fitting mixtures of independent Sine Bivariate von Mises (BVM) distributions. This package is designed for analyzing circular data, such as pairs of phi/psi dihedral angles in biomolecules or other angular systems.


📜 Overview

This model fits mixtures of Bivariate von Mises Sine distributions on angular data pairs $(\phi, \psi)$ using a flexible and GPU-accelerated EM algorithm.

Features:

  • EM algorithm for clustering angular data
  • Supports independent phi/psi angle pairs
  • GPU acceleration via PyTorch
  • Analytic and numeric M-step updates
  • Model scoring: AIC, BIC, ICL
  • Visualization tools for fitted models

📦 Installation

Clone the repo and install:

git clone https://github.com/mccullaghlab/vonMisesMixtureModel.git
cd vonMisesMixtureModel
pip install .

Dependencies:

  • torch
  • numpy
  • scipy
  • matplotlib
  • pytest (for running tests)

🧐 Usage

from bvvmmm.core import SineBVvMMM
import numpy as np

# Example: Generate synthetic (phi, psi) data
N = 1000  # number of samples
data = np.random.uniform(-np.pi, np.pi, size=(N, 2))  # synthetic (phi, psi) data

# Initialize model
model = SineBVvMMM(n_components=3, max_iter=100, tol=1e-5, verbose=True)

# Fit the model
model.fit(data)

# Predict cluster assignments
clusters, log_likelihood = model.predict(data)

# Evaluate log-probabilities
log_probs = model.ln_pdf(data)

# Visualize clustering (for 2D data)
model.plot_scatter_clusters(data)

🧠 API Overview

SineBVvMMM(...)

Initialize the mixture model.

Parameter Description
n_components Number of clusters
small_lambda Use small lambda approximation (default True)
max_iter Maximum EM iterations
tol Convergence threshold for log-likelihood
device 'cuda' or 'cpu'
verbose Print progress during fitting

🔧 Key Methods

Method Description
fit(data) Fit model to angular data of shape (N, 2)
predict(data) Predict cluster assignments and compute log-likelihood
ln_pdf(data) Log-density under the fitted model
pdf(data) Probability density under the fitted model
aic(data) Akaike Information Criterion
bic(data) Bayesian Information Criterion
icl(data) Integrated Complete Likelihood
plot_scatter_clusters(data) Visualize 2D clusters

🧬 Applications

  • Protein backbone conformational clustering (Ramachandran analysis)
  • Directional data clustering (meteorology, geosciences)
  • Robotics joint angle analysis
  • Wind, wave, or cyclic time series clustering
  • Directional statistics in social and behavioral sciences

🛠️ Testing

To run the unit tests:

pytest tests/

📚 References

  • Mardia & Jupp (2009), Directional Statistics
  • Boomsma et al. (2008), Bivariate von Mises for protein geometry
  • Dobson (1978), Estimating concentration in von Mises distributions

🙌 Contributing

Contributions are welcome! Please open an issue or pull request if you'd like to contribute. A CONTRIBUTING.md will be added soon.


📄 License

This project is licensed under the MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bvvmmm-0.1.1.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bvvmmm-0.1.1-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file bvvmmm-0.1.1.tar.gz.

File metadata

  • Download URL: bvvmmm-0.1.1.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for bvvmmm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 54ec08c910ce7dc47897a31e73c4570e989f692f89afaceca05b2cb29e0918b4
MD5 27f9db225545bf02e01fb0d3f6171ba9
BLAKE2b-256 f0aa13bf0e430adf8fe624a98aae2eef7f401a37644c1d8c85ebb8ec0b1cd2aa

See more details on using hashes here.

File details

Details for the file bvvmmm-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: bvvmmm-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for bvvmmm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8d3a9c0100d6df3dd3bc3c2872ff938539f84fbd419c64e64730c54621842b08
MD5 d335eed57d6f4ae01aeac8557155dd19
BLAKE2b-256 06dd8f7fc74382f8868d2d5d9f7356cd99676803e0d55cb5ffbb704ff93ab586

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page