多項、ディリクレ分布:カテゴリカルな決断

  • ベータ分布
    • \frac{1}{B(a_1,a_2)}x_1^{a_1-1}x_2^{a_2-1}
      • B(a_1,a_2) = \frac{\Gamma(a_1)\Gamma(a_2)}{\Gamma(a_1+a_2)}
      • 特にa_1,a_2が整数であれば、
      • B(a_1,a_2) = \frac{(a_1-1)!(a_2-1)!}{(a-1+a_2-1)!}
      •  = \frac{(a_1-1)!(a_2-1)!}{(a_1-1+a_2-1)!(a_1+a_2-1)}
      •  =\frac{1}{_{(a_1-1)+(a_2-1)}C_{a_1-1}} \times \frac{1}{a_1+a_2-1}
      • B(a_1+1,a_2+1) = \frac{1}{_(a_1+a_2)C_{a_1}}\times \frac{1}{a_1+a_2+1}
> x_1 <- 4
> x_2 <- 3
> beta(x_1,x_2)
[1] 0.01666667
> 1/choose(x_1-1+x_2-1,x_1-1) * 1/(x_1+x_2-1)
[1] 0.01666667
> beta(x_1+1,x_2+1)
[1] 0.003571429
> 1/choose(x_1+x_2,x_1) * 1/(x_1+x_2+1)
[1] 0.003571429
  • ディリクレ分布
    • \frac{1}{B(\mathbf{a})}\prod_{i=1}^K x_i^{a_i-1}=\frac{1}{B(\mathbf{a})} \mathbf{x}^{\mathbf{a}-1}
      • \mathbf{a} = (a_1,...,a_K),\mathbf{x}=(x_1,...,x_K),\sum_{i=1}^K x_i = 1
      • B(\mathbf{a}) = \frac{\prod_{i=1}^K\Gamma(a_i)}{\Gamma(\sum_{i=1}^K a_i)}
> library(MCMCpack)
> K <- 2
> a <- c(5,10)
> x <- runif(K)
> x <- x/sum(x)
> dbeta(x[1],a[1],a[2])
[1] 0.7927549
> ddirichlet(x,a)
[1] 0.7927549
> K <- 4
> a <- sample(10:20,K)
> x <- runif(K)
> x <- x/sum(x)
> ddirichlet(x,a)
[1] 8.641452e-09