# Understanding the sum in the stick breaking process

I am writing some R code for sampling from a Dirichlet process, but am having a hard time understanding how to take the final sum when there is a dirac delta function.

The stick breaking representation of the DP is the following:

I am able to calculate the weights, but when it comes to calculate $$f(x)$$ I'm stuck because I get lost in the dirac notation. If it helps, here is a simple example:

Imagine you have weights $$(\beta_1,\beta_2,\beta_3,\beta_4)=(0.5,0.3,0.15,0.5)$$ and samples from the base distribution $$(x_1,x_2,x_3,x_4) = (2.3,1.2,0.4,5)$$. How would I actually calculate $$f(x)$$? In my mind it is just the sum of the weights,i.e., $$f(x) = \sum_{k=1}^4\beta_k\delta_{x_k}(x) = 0.5(1) + 0.3(1) + 0.15(1) + 0.05(1) = 1$$ but then that simply sums to one number, and doesn't really take the x values into account. What am I missing? An explanation of the formula is greatly appreciated!

I'll evaluate $$f(x_1)$$ in your example to help with your understanding, \begin{align} f(x_1) = \sum_{k=1}^4\beta_k\delta_{x_k}(x_k) &= \beta_1\delta_{x_1}(x_1) + \beta_2\delta_{x_2}(x_1) + \beta_3\delta_{x_3}(x_1) + \beta_4\delta_{x_4}(x_1) \\ &= \beta_1(1) + \beta_2(0) + \beta_3(0) + \beta_4(0)\\ &= \beta_1 \\ &= 0.5 \end{align}

Similarly we would find that $$f(x_k) = \beta_k$$.

Now notice that if $$x$$ is not one of the $$x_k$$ then we have $$\delta_{x_k}(x) = 0$$ for all $$k$$, which in turn means that $$f(x) = 0$$ in this case.

So another way to write this equation is

$$f(x) = \begin{cases} \beta_k \text{, if } x = x_k \\ 0 \text{, otherwise} \end{cases}$$

If it helps, one may also write the Dirac delta as

$$\delta_{x_k}(x) = \begin{cases} 1 \text{, if } x = x_k \\ 0 \text{, otherwise} \end{cases}$$

• I think I understand it more now. So you don't evaluate all of the x's at once. But if I wanted to plot f(x) it would just be the four values f(x_1), f(x_2), f(x_3), f(x_4). Correct? Dec 14, 2019 at 1:27
• @JohnSmith You would also include other points, and all of them would be on the x-axis (since $f(x) = 0$ at all other points). Dec 14, 2019 at 2:11