Gamma,Beta,Dirichlet分布图像

Gamma分布

http://cos.name/2013/01/lda-math-gamma-function/ 神奇的Gamma函数

其中 α 称为 shape parameter, 主要决定了分布曲线的形状;而β 称为 rate parameter 或者inverse scale parameter (1/β 称为scale parameter),主要决定曲线有多陡。

x=0:0.01:10;
color=['b','g','r','k','c','y','m']
a=ones(length(x),10);
% for i=1:10
%     a(:,i)=gampdf(x,i,1);
%     legend(num2str(i))
%     hold on
% end
% plot(x,a)
% b=num2str(1:10)
% legend(b(1),b(5),b(9),b(13),b(17),b(21),b(25),b(29),b(33),b(36:37))
for i=1:7
    subplot(3,1,1)
    plot(x,gampdf(x,i,1),color(i))
    hold on
end
t=[]
for i=1:7
    t=[t;strcat('\beta=',num2str(i))];
end
legend(t)

for i=1:7
    subplot(3,1,2)
    plot(x,gampdf(x,1,i),color(i))
    hold on
end
t=[]
for i=1:7
    t=[t;strcat('\alpha=',num2str(i))];
end
legend(t)

for i=1:7
    subplot(3,1,3)
    plot(x,gampdf(x,i,i),color(i))
    hold on
end
t=[]
for i=1:7
    str=sprintf('\\alpha=%d,\\beta=%d',i,i);
    t=[t;str];
end
legend(t)

Beta分布

$\alpha$,$\beta$代表先验,都等于1,则是uniform,相等情况下,越大,则概率为0.5的后验概率越大。均值为$\frac{\alpha}{  (\alpha+\beta)}$

 

Dirichlet分布生成随机数

程序,摘自topictoolbox,
function r = drchrnd(a,n)
% take a sample from a dirichlet distribution
p = length(a);
r = gamrnd(repmat(a,n,1),1,n,p);
r = r ./ repmat(sum(r,2),1,p);

这样生成的r就是服从dirichlet distribution的样本。就是这么简单,
a= drchrnd([1 1 1],10)

a =

    0.0703 0.4272 0.5025
    0.8037 0.0126 0.1837
    0.3358 0.5767 0.0875
    0.8500 0.0952 0.0549
    0.0230 0.5806 0.3964
    0.4690 0.0569 0.4741
    0.4175 0.1979 0.3846
    0.2218 0.6157 0.1624
    0.5576 0.0332 0.4091
    0.1335 0.7247 0.1418

topic toolbox中,之所以可以这么写,充分利用了dirichlet distribution和gamma分布之间的关系。经过推导可以证明,dirichlet distribution可以看作是多个gamma(ai,1)的乘积(包括除)。同时利用了gamma的分布的一个重要性质,xi~gamma(ai,b)分布,则sum(xi)~gamma(sum(ai),b)分布。

 

 

转载于:https://www.cnblogs.com/huashiyiqike/articles/3232082.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值