二维正态累积概率密度的 matlab 轮廓数据

matlab contour data for 2D normal cumulative probability density

我将这个二维正态分布定义为

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

有没有办法在累计概率为95%的情况下得到轮廓数据?我不想要情节,而是 (x,y) 点的值导致 95% 等高线。

如果有人能提供帮助,那就太好了。提前致谢

这会有帮助吗?

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

或使用适当的轴

用等高线代替冲浪

您可以使用数值解算器找到等高线,如下所示:

% 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.

为了获得所需轮廓的更好数值表示,您可以对所选的 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])

这种方法的缺点是您无法控制采样轮廓的粗糙度。其次,此方法使用 3D cdf(插值),其精度低于使用 fsolve.

计算的值