iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📊

[Statistics] Categorical Distribution: Definition, Expectation, and Variance

に公開

Probability Mass Function

When X_1, \cdots X_K are obtained with probabilities \mu_1, \cdots \mu_K respectively in a single trial, the distribution followed by the random variable X=[X_1, \cdots ,X_K] is called the categorical distribution. The probability mass function of the categorical distribution is as follows:

\begin{align*} Cat(\mathbf{x}|\mu) &= \prod_{k=1}^K \mu_k^{x_k} \\ \text{Where,} \; K &\in \N,\; 2 \leq K \\ \mathbf{x} &= [x_1, \cdots ,x_K], \; \sum_k x_k=1, \; \forall x_k \in \{0,1\} \\ \mathbf{\mu} &= [\mu_1, \cdots ,\mu_K], \; \sum_k \mu_k=1, \; \forall \mu_k \in [0,1] \end{align*}

Please note the following:

  • The realized value of X is a vector.
    • In particular, a vector such as \mathbf{x} = [x_1, \cdots ,x_K], \; \sum_k x_k=1, \; \forall x_k \in \{0,1\} is called a one-hot vector.
  • P(X=\mathbf{x}) is a scalar.
  • \mathbb{E}(X_k) is a scalar.

For example, the probability that a random variable X following a categorical distribution with K=3 takes the value [0,1,0] is as follows:

\begin{align*} P(X=[0,1,0]) &= \prod_{k=1}^3\mu_k^{x_k} \\ &= \mu_1^{x_1} \cdot \mu_2^{x_2} \cdot \mu_3^{x_3} \\ &= \mu_1^{0} \cdot \mu_2^{1} \cdot \mu_3^{0} \\ &= 1 \cdot \mu_2^{1} \cdot 1 \\ &= \mu_2 \end{align*}

Concrete examples of variables following a categorical distribution include:

  • Events when drawing a lottery ticket numbered from 1 to K.
    • Using a one-hot vector, the event of drawing ticket 1 can be described as [1,\cdots,0].
    • Other numbers can be described similarly.
  • The outcome of a die roll.
    • Using a one-hot vector, rolling a 2 can be described as [0,1,\cdots,0].
    • Other outcomes can be described similarly.

Examples of the use of categorical distribution include:

  • Used as the word distribution for each topic and the topic distribution for each document in Latent Dirichlet Allocation (LDA), a common technique in natural language processing.

Expectation and Variance

In derivation, note the following.

\begin{align*} \mathbf{x} &= [x_1, \cdots ,x_K], \; \sum_k x_k=1, \; \forall x_k \in \{0,1\}\; \text{then the following holds:} \\ \exist k' &\in K\;\text{s.t}\; x_{k'}=1, \;\forall k \ne k', \; x_k=0 \end{align*}

Expectation

Find the expectation of x_k.

\begin{align*} \mathbb{E}(X_k) &= x_kP(x_k)+\bar{x_k}P(\bar{x_k})\\ &= x_kCat(\mathbf{x}|\mathbf{\mu}) \end{align*}

Note that for \mathbf{x}, let k'=k.

\begin{align*} \mathbb{E}(X_k) &= x_kP(x_k)+x_kP(\bar{x_k})\\ &= x_kCat(\mathbf{x}|\mathbf{\mu}) \\ &= x_k \prod_{c=1}^K\mu_c^{x_c} \\ &= x_k\biggl( \mu_k^{x_k} \cdot \prod_{c \in C,c\ne k}\mu_c^{x_c} \biggr) \\ &= 1\biggl( \mu_k^{1} \cdot \prod_{c \in C,c\ne k}\mu_c^{0} \biggr) \\ &= \biggl( \mu_k^{1} \cdot \prod_{c \in C,c\ne k}1 \biggr) \\ &= \mu_k \end{align*}

The first line divides the cases into the event where x_k occurs and other events.
The second line removes terms since x_k=0 when the event x_k does not occur.
The third line uses C and c as the number of categories and indices to avoid confusion with k.

Variance

Similarly to the first-order moment (expectation), find the second-order moment.

\begin{align*} \mathbb{E}(X_k^2) &= x_k^2P(x_k)+x_k^2P(\bar{x_k})\\ &= x_k^2Cat(\mathbf{x}|\mathbf{\mu}) \\ &= x_k^2 \prod_{c=1}^K\mu_c^{x_c} \\ &= x_k^2\biggl( \mu_k^{x_k} \cdot \prod_{c \in C,c\ne k}\mu_c^{x_c} \biggr) \\ &= 1\biggl( \mu_k^{1} \cdot \prod_{c \in C,c\ne k}\mu_c^{0} \biggr) \\ &= \biggl( \mu_k^{1} \cdot \prod_{c \in C,c\ne k}1 \biggr) \\ &= \mu_k \end{align*}

Therefore,

\begin{align*} \mathbb{V}(X_k^2) &= \mathbb{E}(X_k^2) - \mathbb{E}(X_k)^2\\ &= \mu_k - \mu_k^2\\ &= \mu_k(1-\mu_k) \end{align*}

References

(1) C. M. Bishop. "Pattern Recognition and Machine Learning". 2019. Maruzen Publishing Co., Ltd.
(2) Tomoharu Iwata. "Topic Models". 2015. Kodansha Scientific Ltd.
(3) Atsushi Suyama. "Introduction to Machine Learning through Bayesian Inference". 2018. Kodansha Scientific Ltd.

Discussion