1

我正在使用 matlab 估计概率密度函数(pdf)。

代码是这样的

xi = -2:0.1:2;
a1 = normpdf(xi, 1, 0.3);
a2 = normpdf(xi, -1, 0.3);
subplot(211);
plot(xi, a1+a2);
[f, xs] = ksdensity(a1+a2);
subplot(212);
plot(xs, f);

和这样的照片

绘图结果

您会看到估计根本不起作用。

那么这里有什么问题呢?顺便说一句,matlab中还有其他pdf估计方法吗?

4

2 回答 2

3

这是否更接近您的预期?

ksdensity函数需要来自分布的样本向量,而您正在向它提供概率密度函数的值。

>> xi = -3:0.1:3;
>> p1 = normpdf(xi, 1, 0.3);
>> p2 = normpdf(xi,-1, 0.3);
>> subplot(211)
>> plot(xi, 0.5*p1+0.5*p2)
>> a1 = 1 + 0.3 * randn(10000,1);  % construct the same distribution
>> a2 = -1 + 0.3 * randn(10000,1); % construct the same distribution
>> [f, xs] = ksdensity([a1;a2]);
>> subplot(212)
>> plot(xs, f)

在此处输入图像描述

于 2013-12-12T08:55:39.627 回答
1

ksdensity 为您提供输入值的概率分布(默认为 100 个点)。您的输入值 a1+a2 的值介于 0 和 1.5 之间,其中大部分接近 0,而较小部分接近 1.5。您看到的第二个图反映了这种分布。

如果您想查看两个相似的图,请将元素集中在 -1 和 1 附近的向量作为 ksdensity 的输入。

于 2013-12-12T06:53:18.920 回答