why change in mean and covariance doesnot effect gmdistribution

Hello,
Below I have given 5 points. In each point mu, sigma and mixp is given. Gmdistribution is calculated for each . Changing of mu and sigma values do not make any change in the answer. But if I change the mixp values then the distribution value changes. Why does the change in mean and sigma doesnot affect the gmdistribution?
1. mu = [1 2;-3 -5]; Sigma = [2 0; 0 .5],[1 0; 0 1]; mixp = ones(1,2)/2; gm = gmdistribution(mu,Sigma,mixp) ans= Sigma = 2.0000 0 0 0.5000 gm = Gaussian mixture distribution with 2 components in 2 dimensions Component 1: Mixing proportion: 0.500000 Mean: 1 2
Component 2: Mixing proportion: 0.500000 Mean: -3 -5
2. I have changed the value of mixp
mu = [1 2;-3 -5]; Sigma = [2 0; 0 .5],[1 0; 0 1]; mixp = ones(1,2); gm = gmdistribution(mu,Sigma,mixp) ans= Sigma = 2.0000 0 0 0.5000 gm = Gaussian mixture distribution with 2 components in 2 dimensions Component 1: Mixing proportion: 0.500000 Mean: 1 2
Component 2: Mixing proportion: 0.500000 Mean: -3 -5
3. I have changed the value of mixp again
mu = [1 2;-3 -5]; Sigma = [2 0; 0 .5],[1 0; 0 1]; mixp = [3 4]; gm = gmdistribution(mu,Sigma,mixp) ans= Sigma = 2.0000 0 0 0.5000 gm = Gaussian mixture distribution with 2 components in 2 dimensions Component 1: Mixing proportion: 0.428571 Mean: 1 2
Component 2: Mixing proportion: 0.571429 Mean: -3 -5
4. I have changed the value of sigma. The mixing proportion remains the same as above.
mu = [1 2;-3 -5]; Sigma = [8 0; 0 .5],[1 0; 0 1]; mixp = [3 4]; gm = gmdistribution(mu,Sigma,mixp) Sigma = 8.0000 0 0 0.5000 gm = Gaussian mixture distribution with 2 components in 2 dimensions Component 1: Mixing proportion: 0.428571 Mean: 1 2
Component 2: Mixing proportion: 0.571429 Mean: -3 -5 5. I have changed the value of mean but the mixing proportion doesnot change.
mu = [7 2;-3 -5]; Sigma = [8 0; 0 .5],[1 0; 0 1]; mixp = [3 4]; gm = gmdistribution(mu,Sigma,mixp)
Sigma =
8.0000 0
0 0.5000
gm =
Gaussian mixture distribution with 2 components in 2 dimensions Component 1: Mixing proportion: 0.428571 Mean: 7 2
Component 2: Mixing proportion: 0.571429 Mean: -3 -5
Thanks,
Nidhi

 採用された回答

Tom Lane
Tom Lane 2012 年 6 月 25 日

0 投票

There are two ways to create a gmdistribution. One is by specifying the mean, covariance, and mixing proportion. The result is a distribution with the parameters you specified. That seems to be what is happening in your case. The resulting objects have the means that you specify. The mixing proportions are also the same as the ones you provided, but they are normalized to sum to 1 (so they are real proportions, not just relative sizes.
The other way is to fit to data using the gmdistribution.fit function.
So what is confusing about the output you quote? It may be the normalization of the mixing proportions. My only other idea is that you seem to be trying to specify two covariance matrices, but that's not working. You have
Sigma = [8 0; 0 .5],[1 0; 0 1];
This is actually two statements, one assigning a 2-by-2 matrix to Sigma and the other simply creating a second matrix and discarding it. You may be intending this:
>> Sigma = cat(3,[8 0; 0 .5],[1 0; 0 1])
Sigma(:,:,1) =
8.0000 0
0 0.5000
Sigma(:,:,2) =
1 0
0 1

その他の回答 (1 件)

Nidhi
Nidhi 2012 年 6 月 26 日

0 投票

Thanks a lot. Actually the reason for asking about gmdistribution was that I was making a program using gmdistribution. But, it is giving error at the gmdistribution command. So, I wanted to clear the concept. I saw the algo of this on internet itself and tried it.
The program is :
frame20 = double(imread('image6.jpg'));
[rows,cols,bands] = size(frame20);
skin_detection = zeros(rows, cols);
for row = 1:rows
for col = 1:cols
red = frame20(row, col, 1);
green = frame20(row, col, 2);
blue = frame20(row, col, 3);
r = gmdistribution(red_mean, red_std, red); red_pr=pdf(r,red);
g = gmdistribution(green_mean, green_std, green) green_pr=pdf(g,green);
b = gmdistribution(blue_mean, blue_std, blue); blue_pr=pdf(b,blue);
prob = red_pr .* green_pr .* blue_pr; skin_detection(row, col)= prob;
end
end
This is giving error:
??? Error using ==> gmdistribution.gmdistribution>gmdistribution.gmdistribution at 158 The mixing proportions must be positive.
Error in ==> trial_gauss_fullimage at 51 g = gmdistribution(green_mean, green_std, green); Error in ==> trial_gauss_fullimage at 52 green_pr=pdf(g,green);
The name of my file is trial_gauss_fullimage.
In this the mean and std values of red, green and blue it calculated and these are 1*1 matrix i.e. constant one value eg. red_mean is 237.2865 and red_std is 13.8627. Same holds for red also.
I hope I have been able to explain my problem. If you can help me out it would be great.
Thanks,
Nidhi

6 件のコメント

Tom Lane
Tom Lane 2012 年 6 月 26 日
In the code " g = gmdistribution(green_mean, green_std, green)" you are creating a gaussian mixture distribution with mean green_mean, variance (not standard deviation) green_std, and mixing proportion green. This would not work if green=0, for instance. Also, it looks like green is a scalar rather than a vector of proportions. Can you explain what you would like the command to do? Then maybe I can suggest something.
Nidhi
Nidhi 2012 年 6 月 27 日
THANKS .
Actually, i am writing the program for skin likelihood region selection using gaussian probability.
I am rewriting the code . In this the first image img1.jpg the image is of skin color only. First I have calculated the mean and std of red, green and blue colors of the img1 image. Then, I have taken the full image, image6.jpg and here i am trying to calculate the skin likelihood of the image6 by using the above means and std. I have used this command gmdistribution myself. It is not given in the algo. In the algo they say calculate gaussian probability density function. When I researched I found this command which i have used. Hope now you are clear on what the program is doing.
Below i sthe full code I have used:
im=double(imread('img1.jpg'));
figure, imshow('img1.jpg');
sample_red = im(:, :, 1);
sample_green = im(:, :, 2);
sample_blue = im(:, :, 3);
sample_red = sample_red(:);
sample_green = sample_green(:);
sample_blue=sample_blue(:);
red_mean = mean(sample_red);
green_mean = mean(sample_green);
blue_mean = mean(sample_blue);
red_std = std(sample_red);
green_std = std(sample_green);
blue_std = std(sample_blue);
frame20 = double(imread('image6.jpg'));
figure, imshow('image6.jpg');
[rows,cols,bands] = size(frame20);
% VALUES OF RED GREEN BLUE ARE DIFFERNET IN THE BELOW FOR LOOP.
for row = 1:rows
for col = 1:cols
red = frame20(row, col, 1);
green = frame20(row, col, 2);
blue = frame20(row, col, 3);
end
end
%VALUE OF RED, GREEN, BLUE ARE DIFFERENT IN THE BELOW LOOP AS COMPARED TO
%VALUES IN ABOVE LOOP. HERE THE GREEN VALUE AT ONE POINT BECOMES ZERO. %ALTHOUGH IN THE ABOVE LOOP THE VALUE OF GREEN IS NOT ZERO AT ANY POINT.
frame20 = double(imread('image6.jpg'));
[rows,cols,bands] = size(frame20);
skin_detection = zeros(rows, cols);
for row = 1:rows
for col = 1:cols
red = frame20(row, col, 1);
green = frame20(row, col, 2)
blue = frame20(row, col, 3);
r = gmdistribution.fit(red_mean, red_std, red);
red_pr=pdf(r,red);
g = gmdistribution(green_mean, green_std, green)
green_pr=pdf(g,green);
b = gmdistribution(blue_mean, blue_std, blue);
blue_pr=pdf(b,blue);
prob = red_pr .* green_pr .* blue_pr;
skin_detection(row, col)= prob;
end
end
imshow(skin_detection)
Tom Lane
Tom Lane 2012 年 6 月 27 日
You write "In the algo they say calculate gaussian probability density function." If you intend to calculate three separate normal densities, you probably want either to use normpdf three times, or use gmdistribution.pdf once. You would use gmdistribution only if you wanted to create a single distribution that is a specified mixture of multiple normal distributions.
Nidhi
Nidhi 2012 年 6 月 30 日
Thanks a lot. You have been very cooperative. Please see the link below: http://vlm1.uta.edu/~athitsos/courses/cse6367_spring2012/lectures/07_skin/skin_detection.pdf
I have used the this algo.
I am getting confused between gmdistribution, normalpdf and cdf. whichh one do I have to use in this program.
Can you pl. identify this from the algo given on this link.
Thanks,
Nidhi
Tom Lane
Tom Lane 2012 年 6 月 30 日
The gaussian_probability function isn't a Statistics Toolbox function. At just a quick look, it appears to be something like normpdf but with arguments in a different order. My guess is normpdf(x,mu,sigma) is like gaussian_probability(mu,sigma,x). But that's a guess. Maybe you could try writing to the author.
Nidhi
Nidhi 2012 年 7 月 2 日
Thanks a lot. You have been very helpful, although my problem didnot get solved as i do not have the email id of this person. Anyways, once again thanks a lot for your cooperation.
Nidhi

サインインしてコメントする。

質問済み:

2012 年 6 月 25 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by