在Matlab中以所需的支持截断泊松分布 [英] Truncating Poisson distribution on desired support in Matlab

查看:410
本文介绍了在Matlab中以所需的支持截断泊松分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Lambda参数为[0.4, 0.2, 0.6]的Matlab中构建3维Poisson分布,并且我希望将其截断以在[0;1;2;3;4;5]中获得支持.这三个组件是独立的.

I want to construct a 3-dimensional Poisson distribution in Matlab with lambda parameters [0.4, 0.2, 0.6] and I want to truncate it to have support in [0;1;2;3;4;5]. The 3 components are independent.

这就是我要做的

clear
n=3; %number components of the distribution 

supp_marginal=0:1:5;
suppsize_marginal=size(supp_marginal,2); 

supp_temp=repmat(supp_marginal.',1,n); 
supp_temp_cell=num2cell(supp_temp,1); 
output_temp_cell=cell(1,n);
[output_temp_cell{:}] = ndgrid(supp_temp_cell{:});
supp=zeros(suppsize_marginal^n,n);

for h=1:n
    temp=output_temp_cell{h};
    supp(:,h)=temp(:);  
end
suppsize=size(supp,1); 

lambda_1=0.4;
lambda_2=0.2;
lambda_3=0.6;

pr_mass=zeros(suppsize,1);
for j=1:suppsize
    pr_mass(j)=(poisspdf(supp(j,1),lambda_1).*...
                poisspdf(supp(j,2),lambda_2).*...
                poisspdf(supp(j,3),lambda_3))/...
                sum(poisspdf(supp(:,1),lambda_1).*...
                    poisspdf(supp(:,2),lambda_2).*...
                    poisspdf(supp(j,3),lambda_3));
end 

计算所得分布的均值时,得到的是lambda_1lambda_2,但不是lambda_3.

When I compute the mean of the obtained distribution, I get lambda_1 and lambda_2 but not lambda_3.

lambda_empirical=sum(supp.*repmat(pr_mass,1,3)); 

问题:为什么我没有得到lambda_3?

Question: why I do not get lambda_3?

推荐答案

tl; dr:截断会更改分布,因此期望使用不同的方法.

由于截断本身已更改了分发,因此可以预期并肯定会调整均值.您可以从下面的实验中看到这一点.请注意,对于您选择的参数,这在 lambda = 0.6时才开始变得明显.

This is expected as truncation itself has changed the distribution and certainly adjusts the mean. You can see this from the experiment below. Notice that for your chosen parameters, this just starts to become noticable around lambda = 0.6.

类似于 Wiki页面,这说明了E [ X ](不包含截断的 X 期望;均值的奇特词)和E [ X | LB X UB ]( X 的期望值是在间隔[ LB UB ]).这个有条件的期望意味着与 X 的无条件分布(〜Poisson( lambda ))不同的分布.

Similar to the wiki page, this illustrates the difference between E[X] (expectation of X without truncation; fancy word for mean) and E[ X | LBXUB] (expectation of X given it is on interval [LB,UB]). This conditional expectation implies a different distribution than the unconditional distribution of X (~Poisson(lambda)).

% MATLAB R2018b
% Setup
LB = 0;   % lowerbound 
UB = 5;   % upperbound

% Simple test to compare theoretical means with and without truncation
TestLam = 0.2:0.01:1.5;
Gap = zeros(size(TestLam(:)));
for jj = 1:length(TestLam)
    TrueMean = mean(makedist('Poisson','Lambda',TestLam(jj)));
    TruncatedMean = mean(truncate(makedist('Poisson','Lambda',TestLam(jj)),LB,UB));
    Gap(jj) = TrueMean-TruncatedMean;
end

plot(TestLam,Gap)

请注意,具有这些截断边界的间隙和0.6的lambda仍然很小,并且在lambda接近零时可以忽略不计.

Notice the gap with these truncation bounds and a lambda of 0.6 is still small and is negligible as lambda approaches zero.

lam = 0.6;    %  <---- try different values   (must be greater than 0)
pd = makedist('Poisson','Lambda',lam)
pdt = truncate(pd,LB,UB)
mean(pd)                         % 0.6
mean(pdt)                        % 0.5998


其他资源:
1. 截短的分布
的Wiki. 2. 什么是截断分布
3. truncate() makedist()
4. MATLAB:使用概率分布(对象)


Other Resources:
1. Wiki for Truncated Distributions
2. What is a Truncated Distribution
3. MATLAB documentation for truncate(), makedist()
4. MATLAB: Working with Probability Distribution (Objects)

这篇关于在Matlab中以所需的支持截断泊松分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆