Holes in a Gaussian Mixture Plot


Alex Gaspare

I am trying to plot a Gaussian mixture model using Matlab. I am using the following code/data:

p = [0.048544095760874664 , 0.23086205172287944 , 0.43286598287228106 ,0.1825503345829704 , 0.10517753506099443];

meanVectors(:,1) = [1.3564375381318807 , 5.93145751073734];
meanVectors(:,2) = [3.047518052924292 , 3.0165339699001463];
meanVectors(:,3) = [7.002335595122265 , 6.02432823594635];
meanVectors(:,4) = [6.990841095715846 , 3.5056707068971438];
meanVectors(:,5) = [6.878912868397179 , 1.1054191293515965];

covarianceMatrices(:,:,1) = [1.3075839191466305 0.07843065902827488; 0.07843065902827488 0.3167448334937619];
covarianceMatrices(:,:,2) = [0.642914957488056 0.15638677636129855; 0.15638677636129852 0.382240356677974];
covarianceMatrices(:,:,3) = [0.8216051423486987 0.15225179380145448; 0.15225179380145445 0.37030472711188295];
covarianceMatrices(:,:,4) = [1.064002437166605 0.11798234162403692; 0.11798234162403692 0.2687495955430368];
covarianceMatrices(:,:,5) = [0.6445011493286044 0.15295220981440236; 0.1529522098144023 0.5231676196736254];

obj = gmdistribution(meanVectors', covarianceMatrices, p);

figure(1);
ezcontour(@(x,y)pdf(obj,[x y]), [-10 10], [-10 10]);

figure(2);
ezsurf(@(x,y)pdf(obj,[x y]), [-10 10], [-10 10]);

But the final surface does look "spiky". Am I doing something wrong?

Sebas

Seems the problem is with the draw function this code is much slower, but works for me

p = [0.048544095760874664 , 0.23086205172287944 , 0.43286598287228106 ,0.1825503345829704 , 0.10517753506099443];

meanVectors(:,1) = [1.3564375381318807 , 5.93145751073734];
meanVectors(:,2) = [3.047518052924292 , 3.0165339699001463];
meanVectors(:,3) = [7.002335595122265 , 6.02432823594635];
meanVectors(:,4) = [6.990841095715846 , 3.5056707068971438];
meanVectors(:,5) = [6.878912868397179 , 1.1054191293515965];

covarianceMatrices(:,:,1) = [1.3075839191466305 0.07843065902827488; 0.07843065902827488 0.3167448334937619];
covarianceMatrices(:,:,2) = [0.642914957488056 0.15638677636129855; 0.15638677636129852 0.382240356677974];
covarianceMatrices(:,:,3) = [0.8216051423486987 0.15225179380145448; 0.15225179380145445 0.37030472711188295];
covarianceMatrices(:,:,4) = [1.064002437166605 0.11798234162403692; 0.11798234162403692 0.2687495955430368];
covarianceMatrices(:,:,5) = [0.6445011493286044 0.15295220981440236; 0.1529522098144023 0.5231676196736254];

obj = gmdistribution(meanVectors', covarianceMatrices, p);

x = -10:.2:10; y = x; n=length(x); a=zeros(n,n);
for i = 1:n, for j = 1:n, a(i,j) = pdf(obj,[x(i) y(j)]); end, end;
surf(x,y,a,'FaceColor','interp','EdgeColor','none','FaceLighting','phong')

Related


Convert plot in Matlab from Gaussian mixture to uniform

username Consider the following vector plotted 2x1in Matlab whose probability distribution is a mixture of two Gaussian components. P=10^3; %number draws v=1; %First component mu_a = [0,0.5]; sigma_a = [v,0;0,v]; %Second component mu_b = [0,8.2]; sigma_b = [

Plot Gaussian mixture in R with ggplot2

Mr. Zen I'm approximating a distribution with a mixture of Gaussians, and was wondering if there was an easy way to automatically plot the estimated kernel density of the entire (1D) dataset as the sum of the component densities, similar to this way using ggpl

Convert plot in Matlab from Gaussian mixture to uniform

username Consider the following vector plotted 2x1in Matlab whose probability distribution is a mixture of two Gaussian components. P=10^3; %number draws v=1; %First component mu_a = [0,0.5]; sigma_a = [v,0;0,v]; %Second component mu_b = [0,8.2]; sigma_b = [

Convert plot in Matlab from Gaussian mixture to uniform

username Consider the following vector plotted 2x1in Matlab whose probability distribution is a mixture of two Gaussian components. P=10^3; %number draws v=1; %First component mu_a = [0,0.5]; sigma_a = [v,0;0,v]; %Second component mu_b = [0,8.2]; sigma_b = [

Plot Gaussian mixture in R with ggplot2

Mr. Zen I'm approximating a distribution with a mixture of Gaussians, and was wondering if there was an easy way to automatically plot the estimated kernel density of the entire (1D) dataset as the sum of the component densities, similar to this way using ggpl

Plot Gaussian mixture in R with ggplot2

Mr. Zen I'm approximating a distribution with a mixture of Gaussians, and was wondering if there was an easy way to automatically plot the estimated kernel density of the entire (1D) dataset as the sum of the component densities, similar to this way using ggpl

Plot Gaussian mixture in R with ggplot2

Mr. Zen I'm approximating a distribution with a mixture of Gaussians, and was wondering if there was an easy way to automatically plot the estimated kernel density of the entire (1D) dataset as the sum of the component densities, similar to this way using ggpl

Convert plot in Matlab from Gaussian mixture to uniform

username Consider the following vector plotted 2x1in Matlab whose probability distribution is a mixture of two Gaussian components. P=10^3; %number draws v=1; %First component mu_a = [0,0.5]; sigma_a = [v,0;0,v]; %Second component mu_b = [0,8.2]; sigma_b = [

Convert plot in Matlab from Gaussian mixture to uniform

username Consider the following vector plotted 2x1in Matlab whose probability distribution is a mixture of two Gaussian components. P=10^3; %number draws v=1; %First component mu_a = [0,0.5]; sigma_a = [v,0;0,v]; %Second component mu_b = [0,8.2]; sigma_b = [

Plot Gaussian mixture in R with ggplot2

Mr. Zen I'm approximating a distribution with a mixture of Gaussians and was wondering if there was an easy way to automatically plot the estimated kernel density for the entire (1D) dataset as the sum of the component densities, similar to this way using ggpl

Plot Gaussian mixture in R with ggplot2

Mr. Zen I'm approximating a distribution with a mixture of Gaussians and was wondering if there was an easy way to automatically plot the estimated kernel density for the entire (1D) dataset as the sum of the component densities, similar to this way using ggpl

Plot Gaussian mixture in R with ggplot2

Mr. Zen I'm approximating a distribution with a mixture of Gaussians and was wondering if there was an easy way to automatically plot the estimated kernel density for the entire (1D) dataset as the sum of the component densities, similar to this way using ggpl

Plot Gaussian mixture in R with ggplot2

Mr. Zen I'm approximating a distribution with a mixture of Gaussians and was wondering if there was an easy way to automatically plot the estimated kernel density for the entire (1D) dataset as the sum of the component densities, similar to this way using ggpl

Understanding Gaussian Mixture Models

Hansner I'm trying to understand the results of the scikit-learn Gaussian Mixture Model implementation. See the example below: #!/opt/local/bin/python import numpy as np import matplotlib.pyplot as plt from sklearn.mixture import GaussianMixture # Define simp

Understanding Gaussian Mixture Models

Hansner I'm trying to understand the results of the scikit-learn Gaussian Mixture Model implementation. See the example below: #!/opt/local/bin/python import numpy as np import matplotlib.pyplot as plt from sklearn.mixture import GaussianMixture # Define simp

Understanding Gaussian Mixture Models

Hansner I'm trying to understand the results of the scikit-learn Gaussian Mixture Model implementation. See the example below: #!/opt/local/bin/python import numpy as np import matplotlib.pyplot as plt from sklearn.mixture import GaussianMixture # Define simp

Understanding Gaussian Mixture Models

Hansner I'm trying to understand the results of the scikit-learn Gaussian Mixture Model implementation. See the example below: #!/opt/local/bin/python import numpy as np import matplotlib.pyplot as plt from sklearn.mixture import GaussianMixture # Define simp

Gaussian Mixture Modeling Matlab

Ashwin Shank Im using a Gaussian mixture model to estimate the log-likelihood function (parameters are estimated by the EM algorithm) Im using Matlab ... My data size is: 17991402*1...17991402 1D data points: When I run gmdistribution.fit(X, 2) I get the desir

Gaussian Mixture Modeling Matlab

Ashwin Shank Im using a Gaussian mixture model to estimate the log-likelihood function (parameters are estimated by the EM algorithm) Im using Matlab ... My data size is: 17991402*1...17991402 1D data points: When I run gmdistribution.fit(X, 2) I get the desir

Understanding Gaussian Mixture Models

Hansner I'm trying to understand the results of the scikit-learn Gaussian Mixture Model implementation. See the example below: #!/opt/local/bin/python import numpy as np import matplotlib.pyplot as plt from sklearn.mixture import GaussianMixture # Define simp

Understanding Gaussian Mixture Models

Hansner I'm trying to understand the results of the scikit-learn Gaussian Mixture Model implementation. See the example below: #!/opt/local/bin/python import numpy as np import matplotlib.pyplot as plt from sklearn.mixture import GaussianMixture # Define simp

Understand the concept of Gaussian mixture models

StuckInPhD I am trying to understand GMM by reading online resources. I have implemented clustering using K-Means and am looking at GMM vs K-means comparison. This is what I understand, please let me know if my concept is wrong: GMM is like KNN in the sense th

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_

Estimating mixture of Gaussian models in Pytorch

www3 I actually want to estimate the normalized flow with a Gaussian mixture as the base distribution, so I'm a bit torch bound. However, you can reproduce my error in code just by estimating the mixture of Gaussian models in torch. My code is as follows: impo

Understand the concept of Gaussian mixture models

StuckInPhD I am trying to understand GMM by reading online resources. I have implemented clustering using K-Means and am looking at GMM vs K-means comparison. This is what I understand, please let me know if my concept is wrong: GMM is like KNN in the sense th