Chinese Restaurant Process I want to implement Chinese Restaurant Process representation of Dirichlet Process for random partitions. The problem setup is as follows:  
I have some data (customers) which I have to randomly group (assign table). According to CRP,  


*

*First customer C1 will always choose first empty table i.e.
T1

*Second customer C2 will choose T1 with probability
$P(T1) = c / (n - 1 + α)$  
and C2 will choose T2 with probability 
$P(T2) = α / (n - 1 + α)$  
where $c$ is number of customer sitting at existing table and $n$ is total number of customers.  
My 3 questions are:  
1.  Choosing New Table 


*

*How to decide that C2 will choose which table? Should C2 choose table with greater probability from $P(T1)$ and $P(T2)$?
2.  Same Probability value for Existing & New Table 
For instance, C2 have chosen T2, whereas at this stage $P(T1)$ and  $P(T2)$ are same as: 
$P(T1) = 1/(2 + α)$ and
$P(T2) = 1/(2 + α)$ Now  


*

*How to decide C3 will choose which table?
3.  Choosing from more than 1 Existing Tables 
For another instance, if there have been assigned $3$ tables yet and $4th$ table will be new table, as we have a single new table probability value and several existing tables probability values, then  


*

*How to decide that next customer choose which table from existing $3$ tables?
 A: You need to be very precise about what $c$ and $n$ are.
Let $c_i$ be the number of customers at table $i$.
Let $n$ be the customer number, i.e. $n-1$ clients are already seated at all tables.
Let $k$ be the current number of tables.
Then randomly choose a table using this probabilities:
$$
P(T_i) =
\begin{cases}
c_i / (n - 1 + \alpha) & \text{ for }i\leq k
\\
\alpha / (n - 1 + \alpha) & \text{ for } i = k +1
\\
0 & \text{otherwise}
\end{cases}
$$
This is a total distribution, because
$$
\sum_i P(T_i)
=
\frac{\sum c_i + \alpha}{n - 1 + \alpha}
=
\frac{n -1 + \alpha}{n - 1 + \alpha}
= 1
$$
Therefore, you can draw a random number such that exactly one of these cases happens; i.e. the customer chooses exactly one table.
If $n=1$, $k=0$, then the probability of choosing the first (new) table is $\alpha/\alpha=1$.
Just reading this in a book only gets you halfway. What you need to learn is to work out such details yourself. The way to figure out these things is where you learn, not by looking at the final result.
This is not a clustering algorithm. It is a random stochastic process to simulate certain data distributions. But it is not based on any data. It is a theoretical model to back certain considerations. Judging from your earlier questions, it appears as if you were mislead to believe this could be easily used to cluster some text data?
