Skip to main content

Bivariate von Mises Mixture Model for Circular Data Analysis

Project description

vonMisesMixtureModel

PyPI - License Tests

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.0.tar.gz (17.6 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.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bvvmmm-0.1.0.tar.gz
  • Upload date:
  • Size: 17.6 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.0.tar.gz
Algorithm Hash digest
SHA256 97886da99c29e4768b101a6fc4b2b35db0da91e9548a30c42f8d13756584b980
MD5 b12f819e018ec67e68feb2c30bcc4113
BLAKE2b-256 e263a36800cfa678c21c10766e559fa8f9d5f467304f4eb05f70f158a411a051

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bvvmmm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20774b1f84870423c94199332c02d8ba47f5fed1ad593e6833e8487836883ceb
MD5 aa6fce4c6e65a2123fa240899d8596f9
BLAKE2b-256 9af398c019cde3bb53d046cf0dcef8b8daa2bcc605ba90a869110e5dd238e57a

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