2017-06-06 108 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