【问题标题】:matlab pdf estimation (ksdensity) not workingmatlab pdf估计(ksdensity)不起作用
【发布时间】:2013-12-12 19:13:00
【问题描述】:

我正在使用 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);

还有这样的照片

您发现估计根本不起作用。

那么这里有什么问题? BTW matlab中还有其他的pdf估计方法吗?

【问题讨论】:

    标签: matlab probability-density


    【解决方案1】:

    这是否更接近您的预期?

    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)
    

    【讨论】:

    • 搞清楚我在想什么真是太棒了,而且非常有帮助。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-10
      • 2018-04-06
      • 2015-04-18
      • 2021-11-18
      • 2021-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多