Skip to main content

Add your description here

Project description

Truncated Gaussian Mixtures

DOI PyPI version Documentation

Fit data to mixtures of truncated multivariate gaussians

   p(x) = \sum_k w_k\  \phi_{[{\bf a}, {\bf b}]}({\bf x} | \boldsymbol{\mu}_k, \boldsymbol{\Sigma}_k)

where ${\bf a}$ and ${\bf b}$ are the bounding corners of the hypercube we would like to truncate the gaussian in. This package supports

  • Full, Diagonal and Block diagonal covariances for each component
  • Inteface to allow one to perform the fit in some latent space given by a user-defined transformation, and carry along any target labels
  • Sampling and pdf evaluation from the resultant fit

Quick Start

You can install this library using

pip install truncatedgaussianmixtures

You can then import truncatedgaussianmixtures. At the first import it may take a while, since this will create a local julia installation. This will only happen once at the first ever import.

The main function to use is fit_gmm. The following is a simple example use case.

import pandas as pd
from truncatedgaussianmixtures import fit_gmm
import numpy as np

# Generate some data
df = pd.DataFrame(np.random.randn(80_000, 2), columns=["x", "y"])

# Truncated it to the unit square
cond = (df['x'] < 1) & (df['x'] > 0)  
cond &= (df['y'] < 1) & (df['y'] > 0)
df = df[cond]

# Fit it a truncated gaussian mixture model to it
gmm = fit_gmm(data = df,      # data to fit to
             N    = 1,       # Number of components of the mixture model
             a    = [0,0],   # lower corner of the truncation
             b    = [1,1],   # upper corner of the truncation
             cov  = "diag"   # covariance structure: any of ("diag", "full")
      )

# Sample from the gmm
df_fit = gmm.sample(len(df));

gmm.pdf(np.array([0, 0]).reshape(1,2)) ## Dimension index needs to be the last index

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

truncatedgaussianmixtures-0.1.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

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

truncatedgaussianmixtures-0.1.0-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for truncatedgaussianmixtures-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6b8ba7b9573c76aee85138d92111a85192e7a48dbffefdaced0cda5faa86b19a
MD5 96dd220a172b2491211d3855484c6a11
BLAKE2b-256 b0b8a37e4404f8e65fc2895f01808f610677496aef9d265799eb15d963f43169

See more details on using hashes here.

Provenance

The following attestation bundles were made for truncatedgaussianmixtures-0.1.0.tar.gz:

Publisher: python-publish.yml on Potatoasad/truncatedgaussianmixtures

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for truncatedgaussianmixtures-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9031781f1ec367057769fef33ba797a87c670efed1d0cae3457fd3fa66b295f3
MD5 853d033d3e088caae3c61297aa65e324
BLAKE2b-256 baaaf19e2192c64fd858f51105e8d74ebc9b51f3e50d256aa3460f28720b000d

See more details on using hashes here.

Provenance

The following attestation bundles were made for truncatedgaussianmixtures-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on Potatoasad/truncatedgaussianmixtures

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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