Skip to content

Functions to compute conditional distributions of Gaussian mixture models.

License

Notifications You must be signed in to change notification settings

tmcclintock/ConditionalGMM

Repository files navigation

ConditionalGMM Build Status License: MIT Coverage Status

This repository contains helpful functions for computing conditional distributions of multivariate normal distributions and Gaussian mixture models (GMMs). It is able to return not only the conditional means (expectation values) but also the conditional covariances and conditional component weights (probabilities).

Note that this package is NOT intended for use in training GMMs. There are much better tools out there for this purpose such as those in scikit-learn.

Installation

Clone the repository

git clone https://github.com/tmcclintock/ConditionalGMM

install the requirements (only numpy and scipy) using either conda:

conda install --file requirements.txt

or pip:

pip install -r requirements.txt

Install this package

python setup.py install

Run the tests with pytest.

Usage

Suppose you had some data described by some number of Gaussians: alt text

Once you have a GMM describing the data (the lines) you can create a conditional GMM object:

import ConditionalGMM
cGMM = ConditionalGMM.CondGMM(weights, means, covs, fixed_indices)

where fixed_indices is an array of the dimensions that you will take conditionals on. In this example, we will look at y conditional on x, so we would have fixed_indices = [0].

Given some observations of x with this package you can quickly compute conditional probability distributions:

y = np.linspace(-12, 0, 200)
x_obs = np.array([-1, 4, 7])
for x in x_obs:
    y_cpdf = np.array([cGMM.conditional_pdf([yi], x) for yi in y])

alt text

This package also lets you draw random values (RVs) from the conditional PDF. For instance, here are one hundred thousand draws from each of the conditional PDFs shown above:

x_obs = np.array([-1, 4, 7])
N = 100000
for x in x_obs:
    y_rvs = cGMM.rvs(x, size=N)

alt text

About

Functions to compute conditional distributions of Gaussian mixture models.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages