PyMC3 Gaussian Mixture Model


Anjum Sayed

I've been following the Gaussian Mixture Model example for PyMC3 here: https://github.com/pymc-devs/pymc3/blob/master/pymc3/examples/gaussian_mixture_model.ipynb , and got it working perfectly with the artificial dataset .enter image description here

I've tried using real datasets, but I'm struggling to get meaningful results:enter image description here

What parameters should I consider shrinking/extending/changing to get a better fit? Traces appear to be stable. Here is a snippet of my example, adapted from the example:

model = pm.Model()
with model:
    # cluster sizes
    a = pm.constant(np.array([1., 1., 1.]))
    p = pm.Dirichlet('p', a=a, shape=k)
    # ensure all clusters have some points
    p_min_potential = pm.Potential('p_min_potential', tt.switch(tt.min(p) < .1, -np.inf, 0))


    # cluster centers
    means = pm.Normal('means', mu=[0, 1.5, 3], sd=1, shape=k)
    # break symmetry
    order_means_potential = pm.Potential('order_means_potential',
                                     tt.switch(means[1]-means[0] < 0, -np.inf, 0)
                                     + tt.switch(means[2]-means[1] < 0, -np.inf, 0))

    # measurement error
    sd = pm.Uniform('sd', lower=0, upper=2, shape=k)

    # latent cluster of each observation
    category = pm.Categorical('category', p=p, shape=ndata)

    # likelihood for each observed value
    points = pm.Normal('obs', mu=means[category], sd=sd[category], observed=data)
Anjum Sayed

As it turns out, there is an excellent blog post on the subject here : http://austinrochford.com/posts/2016-02-25-density-estimation-dpm.html

Related


PyMC3 Gaussian Mixture Model

Anjum Sayed I've been following PyMC3's Gaussian Mixture Model example here: https://github.com/pymc-devs/pymc3/blob/master/pymc3/examples/gaussian_mixture_model.ipynb , and it works perfectly with artificial datasets . I've tried using real datasets, but I'm

PyMC3 Gaussian Mixture Model

Anjum Sayed I've been following the Gaussian Mixture Model example for PyMC3 here: https://github.com/pymc-devs/pymc3/blob/master/pymc3/examples/gaussian_mixture_model.ipynb , and it works perfectly with the artificial dataset . I've tried using real datasets,

PyMC3 Gaussian Mixture Model

Anjum Sayed I've been following the Gaussian Mixture Model example for PyMC3 here: https://github.com/pymc-devs/pymc3/blob/master/pymc3/examples/gaussian_mixture_model.ipynb , and got it working perfectly with the artificial dataset . I've tried using real dat

PyMC3 Gaussian Mixture Model

Anjum Sayed I've been following the Gaussian Mixture Model example for PyMC3 here: https://github.com/pymc-devs/pymc3/blob/master/pymc3/examples/gaussian_mixture_model.ipynb , and got it working perfectly with the artificial dataset . I've tried using real dat

PyMC3 Gaussian Mixture Model

Anjum Sayed I've been following the Gaussian Mixture Model example for PyMC3 here: https://github.com/pymc-devs/pymc3/blob/master/pymc3/examples/gaussian_mixture_model.ipynb , and got it working perfectly with the artificial dataset . I've tried using real dat

PyMC3 Gaussian Mixture Model

Anjum Sayed I've been following the Gaussian Mixture Model example for PyMC3 here: https://github.com/pymc-devs/pymc3/blob/master/pymc3/examples/gaussian_mixture_model.ipynb , and it works perfectly with the artificial dataset . I've tried using real datasets,

PyMC3 Gaussian Mixture Model

Anjum Sayed I've been following the Gaussian Mixture Model example for PyMC3 here: https://github.com/pymc-devs/pymc3/blob/master/pymc3/examples/gaussian_mixture_model.ipynb , and it works perfectly with the artificial dataset . I've tried using real datasets,

PyMC3 Gaussian Mixture Model

Anjum Sayed I've been following the Gaussian Mixture Model example for PyMC3 here: https://github.com/pymc-devs/pymc3/blob/master/pymc3/examples/gaussian_mixture_model.ipynb , and it works perfectly with the artificial dataset . I've tried using real datasets,

PyMC3 Gaussian Mixture Model

Anjum Sayed I've been following the Gaussian Mixture Model example for PyMC3 here: https://github.com/pymc-devs/pymc3/blob/master/pymc3/examples/gaussian_mixture_model.ipynb , and it works perfectly with the artificial dataset . I've tried using real datasets,

Porting mixture model to pymc3

saxtax I'm trying to port a Gaussian mixture model, as defined here: How to model a mixture of 3 normals in PyMC? to pymc3 code import numpy as np from pymc import Model, Gamma, Normal, Dirichlet from pymc import Multinomial from pymc import sample, Metropolis

Porting mixture model to pymc3

saxtax I'm trying to port a Gaussian mixture model, as defined here: How to model a mixture of 3 normals in PyMC? to pymc3 code import numpy as np from pymc import Model, Gamma, Normal, Dirichlet from pymc import Multinomial from pymc import sample, Metropolis

Gaussian Mixture Model for Image Histogram

Dotted glass I am trying to do automatic image segmentation of different regions of a 2D MR image based on pixel intensity values. The first step is to implement a Gaussian mixture model on the histogram of the image. I need to plot the resulting Gaussian obta

Gaussian Mixture Model for Image Histogram

Dotted glass I am trying to do automatic image segmentation of different regions of a 2D MR image based on pixel intensity values. The first step is to implement a Gaussian mixture model on the histogram of the image. I need to plot the resulting Gaussian obta

Gaussian Mixture Model Cross Validation

Newkid I want to perform cross validation on my Gaussian mixture model. Currently, my cross_validationapproach using sklearn is as follows. clf = GaussianMixture(n_components=len(np.unique(y)), covariance_type='full') cv_ortho = cross_validate(clf, parameters_

Gaussian Mixture Model for Image Histogram

Dotted glass I am trying to do automatic image segmentation of different regions of a 2D MR image based on pixel intensity values. The first step is to implement a Gaussian mixture model on the histogram of the image. I need to plot the resulting Gaussian obta

Gaussian Mixture Model Cross Validation

Newkid I want to perform cross validation on my Gaussian mixture model. Currently, my cross_validationapproach using sklearn is as follows. clf = GaussianMixture(n_components=len(np.unique(y)), covariance_type='full') cv_ortho = cross_validate(clf, parameters_

Gaussian Mixture Model (GMM) is not suitable

Book I've been using Scikit-learn's GMM function. First, I created a distribution along the line x=y. from sklearn import mixture import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D line_model = mixture.GMM(n_components

Gaussian Mixture Model (GMM) is not suitable

BenB I've been using Scikit-learn's GMM function. First, I created a distribution along the line x=y. from sklearn import mixture import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D line_model = mixture.GMM(n_components

Number of parameters in a Gaussian mixture model

golden_truth I have D-dimensional data with K components. How many parameters do I need if I use a model with a full covariance matrix? and if I use the diagonal covariance matrix how many? golden_truth xyLe_ 's answer in CrossValidated https://stats.stackexch

Gaussian Mixture Model Cross Validation

Newkid I want to perform cross validation on my Gaussian mixture model. Currently, my cross_validationapproach using sklearn is as follows. clf = GaussianMixture(n_components=len(np.unique(y)), covariance_type='full') cv_ortho = cross_validate(clf, parameters_

Gaussian Mixture Model for Image Histogram

Dotted glass I am trying to do automatic image segmentation of different regions of a 2D MR image based on pixel intensity values. The first step is to implement a Gaussian mixture model on the histogram of the image. I need to plot the resulting Gaussian obta

Gaussian Mixture Model for Image Histogram

Dotted glass I am trying to do automatic image segmentation of different regions of a 2D MR image based on pixel intensity values. The first step is to implement a Gaussian mixture model on the histogram of the image. I need to plot the resulting Gaussian obta

Gaussian Mixture Model Cross Validation

Newkid I want to perform cross validation on my Gaussian mixture model. Currently, my cross_validationapproach using sklearn is as follows. clf = GaussianMixture(n_components=len(np.unique(y)), covariance_type='full') cv_ortho = cross_validate(clf, parameters_

Gaussian Mixture Model (GMM) is not suitable

BenB I've been using Scikit-learn's GMM function. First, I created a distribution along the line x=y. from sklearn import mixture import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D line_model = mixture.GMM(n_components

Problems with sklearn.mixture.GMM (Gaussian Mixture Model)

Gabriele Pompa I'm fairly new to scikit-lear and GMM in general...I have some questions about the fit quality of Gaussian mixture models in python (scikit-learn). I have an array of data that you can find in DATA HERE to match a GMM of n=2 components . As a be

Clustering images using a Gaussian mixture model

ninja I want to cluster a binary image using GMM (Gaussian Mixture Model) and also want to plot the cluster centroids on the binary image itself. I used this as a reference : http://in.mathworks.com/help/stats/gaussian-mixture-models.html Here is my initial co

Clustering images using a Gaussian mixture model

ninja I want to cluster a binary image using GMM (Gaussian Mixture Model) and also want to plot the cluster centroids on the binary image itself. I used this as a reference : http://in.mathworks.com/help/stats/gaussian-mixture-models.html Here is my initial co

Equivalent of Matlab "fit" of Gaussian mixture model in R?

Dentist_Not edible I have some time series data that looks like this: x <- c(0.5833, 0.95041, 1.722, 3.1928, 3.941, 5.1202, 6.2125, 5.8828, 4.3406, 5.1353, 3.8468, 4.233, 5.8468, 6.1872, 6.1245, 7.6262, 8.6887, 7.7549, 6.9805, 4.3217, 3.0347, 2.4026, 1.9317,

How to evaluate samples in a weighted Gaussian mixture model?

kind Lite: If I have a MoG model with n components, each component has its own weight w^n. I have a sample. I wish to calculate the probability of drawing samples from the MoG. I can easily evaluate individual Gaussians, but I don't know how to consider their