问题描述
我有一个从两个单独的未知高斯分布绘制的 x
和 y
坐标的向量。我希望将这些点适合于三维高斯函数,并在任何 x
和 y
下评估此函数。
到目前为止,我发现这样做的唯一方式是使用最大为1个组件的高斯混合模型(参见下面的代码),并进入 ezcontour
取出X,Y和Z数据。
这个方法的问题首先是它的一个非常丑陋的方式来完成这个工作,其次是ezcontour命令只给了我一个60x60的网格,但我需要一个很多分辨率更高。
有谁知道一个更优雅和有用的方法,它可以让我找到潜在的Gauss函数,并在任何 x
和 y
?
代码:
GaussDistribution = fitgmdist([varX varY], 1); %不完全是fitgmdist的意图,但它完成了工作。
h = ezcontour(@(x,y)pdf(GaussDistributions,[x y]),[ - 500 -400],[-40 40]);
一般形式的高斯分布如下所示: p>
我不允许上传图片,但高斯公式为:
1 /((2 * PI)^(d / 2)×SQRT(DET(Sigma公司)))* EXP( - 1/2 *(X-亩)*西格玛^ -1 *(X-亩)') ;
其中D是数据维度(因为您是2);
西格玛是协方差矩阵;
和Mu是每个数据向量的均值。
这里是一个例子。在这个例子中,高斯拟合为两个具有参数N1(4,7)和N2(-2,4)的正态分布随机生成样本的向量:
<$ p $数据= [random('norm',4,7,30,1),random('norm', - 2,4,30,1)];
X = -25:.2:25;
Y = -25:.2:25;
D =长度(Data(1,:));
Mu =均值(数据);
Sigma = cov(Data);
P_Gaussian =零(长度(X),长度(Y));
for i = 1:length(X)
for j = 1:length(Y)
x = [X(i),Y(j)];
P_Gaussian(i,j)= 1 /((2 * pi)^(D / 2)* sqrt(det(Sigma)))...
* exp(-1 / 2 *的x亩)*西格玛^ -1 *(X-亩)');
end
end
mesh(P_Gaussian)
在matlab中运行代码。为了清晰起见,我编写了这样的代码,从编程的角度来看,它可以更高效地编写。
I have a vector of x
and y
coordinates drawn from two separate unknown Gaussian distributions. I would like to fit these points to a three dimensional Gauss function and evaluate this function at any x
and y
.
So far the only manner I've found of doing this is using a Gaussian Mixture model with a maximum of 1 component (see code below) and going into the handle of ezcontour
to take the X, Y, and Z data out.
The problems with this method is firstly that its a very ugly roundabout manner of getting this done and secondly the ezcontour command only gives me a grid of 60x60 but I need a much higher resolution.
Does anyone know a more elegant and useful method that will allow me to find the underlying Gauss function and extract its value at any x
and y
?
Code:
GaussDistribution = fitgmdist([varX varY],1); %Not exactly the intention of fitgmdist, but it gets the job done.
h = ezcontour(@(x,y)pdf(GaussDistributions,[x y]),[-500 -400], [-40 40]);
Gaussian Distribution in general form is like this:
I am not allowed to upload picture but the Formula of gaussian is:
1/((2*pi)^(D/2)*sqrt(det(Sigma)))*exp(-1/2*(x-Mu)*Sigma^-1*(x-Mu)');
where D is the data dimension (for you is 2);Sigma is covariance matrix;and Mu is mean of each data vector.
here is an example. In this example a guassian is fitted into two vectors of randomly generated samples from normal distributions with parameters N1(4,7) and N2(-2,4):
Data = [random('norm',4,7,30,1),random('norm',-2,4,30,1)];
X = -25:.2:25;
Y = -25:.2:25;
D = length(Data(1,:));
Mu = mean(Data);
Sigma = cov(Data);
P_Gaussian = zeros(length(X),length(Y));
for i=1:length(X)
for j=1:length(Y)
x = [X(i),Y(j)];
P_Gaussian(i,j) = 1/((2*pi)^(D/2)*sqrt(det(Sigma)))...
*exp(-1/2*(x-Mu)*Sigma^-1*(x-Mu)');
end
end
mesh(P_Gaussian)
run the code in matlab. For the sake of clarity I wrote the code like this it can be written more more efficient from programming point of view.
这篇关于拟合二维高斯到二维数据的Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!