Hi
Greetings. I have a simple problem and will appreciate your help.
I am trying to plot the bimodal Gaussian distribution. The space is [0:0.1:20] and there are two means in one dimension.
I expect to obtain two peaks (one is an image of course) at the means [6;14], however, that's not what I get. I think I am going wrong somewhere, but am unable to figure out.
Yeah, I neglected the covariance matrix and the normalization constant, because I am normalizing at the complete function in the next step.
My implementation is here
mu=[6;14];
space=[0:.1:20];
x=[space;space];
L=exp(-((x-repmat(mu,1,size(T,2)))'*(x-repmat(mu,1,size(T,2))))/2);
L=L/sum(sum(L));
mesh(space,space,L);
P

 Réponse acceptée

Tom Lane
Tom Lane le 2 Oct 2012
Modifié(e) : KSSV le 19 Juin 2022
One more try. Check this out:
mu=[6;14];
space=[0:.1:20];
x = repmat(space,201,1);
y = repmat(space',1,201);
L = .5 * (1/(2*pi)) * exp(-.5 * ((x-mu(1)).^2 + (y-mu(2)).^2)) ...
+ .5 * (1/(2*pi)) * exp(-.5 * ((x-mu(2)).^2 + (y-mu(1)).^2));
mesh(space,space,L);
This creates arrays of x/y values so that each (i,j) index defines a point in the 2D space. Then it computes a thing L that is a mixture of two bivariate normal distributions. Their means are mirror images.

1 commentaire

PChoppala
PChoppala le 2 Oct 2012
Yeah, thanks a lot. This is what I wanted to do.

Connectez-vous pour commenter.

Plus de réponses (1)

Tom Lane
Tom Lane le 29 Sep 2012
Is this what you want?
F = (1/sqrt(2*pi)) * .5*(exp(-.5*(space-mu(1)).^2) + exp(-.5*(space-mu(2)).^2));
plot(space,F)

3 commentaires

PChoppala
PChoppala le 1 Oct 2012
Hi
Sorry for the delay. No, that was not what I meant.
I wanted F to be a 2-D surface that can be plotted using mesh. P(mu(1)) would take the x-axis, and P(mu(2)) would take the y-axis.
What you gave plotted both P(mu(1)) and P(mu(2)) on one single space. I think I made my problem clear!
P
This is still not completely clear to me.This:
p1 = (1/sqrt(2*pi)) * exp(-.5*(x(1,:)-mu(1)).^2);
p2 = (1/sqrt(2*pi)) * exp(-.5*(x(2,:)-mu(2)).^2);
L = p1'*p2;
gives you a density in two-dimensional space with a single mode. Your original question specified a bimodal distribution with "two means in one dimension."
PChoppala
PChoppala le 1 Oct 2012
Hmm, you are right. I think I framed the question wrong.
I meant that the dimension of the mean is a single number (one dimension) and so its pdf is a 1-d function. Its not that both means lie in one space.
I want a 2-d function, one for pdf of mu(1) along x-axis and another for pdf of mu(2) along y-axis.
Along the x-axis, we find 6 and 14. Similarly on y-axis.
So I suppose the pdf in the joint space should have two peaks, one at (6,14) and the other at (14,6).
Oh yeah, to make it more clear, if I have 3 means, the joint space of the resulting pdf 'F' has to be 3-d and so on.
I am looking for a Matlab implementation that can do this.
I am not sure whether this idea of two peaks is correct or not, but that was what I was told.
Cheers P

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by