2017-06-06 101 views
0

MATLAB輪廓數據我有這個二維正態分佈定義爲二維正常累積概率密度

mu = [0 0]; 
Sigma = [1 0.5^0.5; 0.5^0.5 1]; 

有沒有辦法時的累積概率說的是95%,以獲得輪廓數據。我不想要情節,而是(x,y)點的值導致95%輪廓。

如果有人可以幫忙,這將是非常善良。在此先感謝

+0

請參考副本。看看Amro的答案 - 特別是編輯部分,該部分討論如何沿95%誤差橢圓生成點。 – rayryeng

+0

我無法按照答案。這個問題的目標似乎有所不同。 – user1612986

+1

該帖子生成數據周圍的橢圓點。它找到這些點,然後繪製它。該編輯還會告訴您如何爲95%誤差橢圓做到這一點。你正在尋找的只是點,而不是陰謀。所以盡一切努力,但不包括情節。重複是爲兩個對象繪製這個圖,但你只有一個。另外,生成點的行是:'e = bsxfun(@plus,VV * e,Mu');'。因此'e'將是一個兩列矩陣,其中每列是沿橢圓點的座標('x'或'y')。 – rayryeng

回答

1

可以使用數值解算器找到輪廓如下:

% plot the distribution 
figure; 
x = (-5:0.5:5)'; 
y = (-5:0.5:5)'; 
[X1,X2] = meshgrid(x',y'); 
X = [X1(:) X2(:)]; 
p = mvncdf(X,mu,Sigma); 
X3 = reshape(p,length(x),length(y)); 
surf(X1,X2,X3); 

x = (-5:0.1:5)'; % define the x samples at which the contour should be calculated 
y0 = zeros(size(x)); % initial guess 
y = fsolve(@(y) mvncdf([x y], mu, Sigma) - 0.95, y0); % solve your problem 
z = mvncdf([x y],mu,Sigma); % calculate the correspond cdf values 
hold on 
plot3(x(z>0.94), y(z>0.94), z(z>0.94), 'LineWidth', 5); % plot only the valid solutions, i.e. a solution does not exist for all sample points of x. 

enter image description here

爲了獲得所需輪廓的更好的數字表示,您可以對選定的y值重複上述方法。所以,你的線條會更好地填充整個圖表。

作爲替代,可以使用contour來計算輪廓上的要點如下:

figure 
[c, h] = contour(X1, X2, X3, [0.95 0.95]); 
c(3, :) = mvncdf(c',mu,Sigma); 

figure(1) 
plot3(c(1, :)', c(2, :)', c(3, :)', 'LineWidth', 5); 
xlim([-5 5]) 
ylim([-5 5]) 

enter image description here

這種方法的缺點是,你沒有控制權採樣輪廓的粗糙度。其次,這種方法使用(內插)3D cdf,這比用fsolve計算的值更不準確。

0

這將有助於?

clear all 
close all 
mu = [0 0]; 
Sigma = [1 0.5^0.5; 0.5^0.5 1]; 
x1 = -3:.2:3; x2 = -3:.2:3; 
[X1,X2] = meshgrid(x1,x2); 
F = mvnpdf([X1(:) X2(:)],mu,Sigma); 
F = reshape(F,length(x2),length(x1)); 
subplot(1,3,1) 
surf(x1,x2,F); axis square 

X = [X1(:) X2(:)]; 
p = mvncdf(X,mu,Sigma); 
P = reshape(p,31,31); 
subplot(1,3,2) 
surf(X1,X2,P); axis square 

subplot(1,3,3) 
P(P<0.95) = NaN; 
surf(X1,X2,P); axis square 

enter image description here

或與適當的軸 enter image description here

與輪廓替換衝浪enter image description here