我正在尝试使用matlab绘制高斯混合模型。我正在使用以下代码/数据:
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]);
但是由此产生的表面似乎真的“尖刻”。我做错了吗?
答案 0 :(得分:2)
似乎问题在于绘制函数 这段代码要慢得多,但它对我有用
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')
答案 1 :(得分:1)
问题是默认的网格大小,即60.设置一个更高的数字,您将得到预期的结果:
figure(1);
ezcontour(@(x,y)pdf(obj,[x y]), [-10 10], [-10 10],300);
figure(2);
ezsurf(@(x,y)pdf(obj,[x y]), [-10 10], [-10 10],300);