id \lambda)}.
\]</span></p>
<p>On the log scale, the normalized probability is computed as
<span class="math display">\[
\begin{array}{l}
\log \mbox{Pr}(z_n = k \mid y_n, \mu, \sigma, \lambda)
\\
\mbox { } \ \ \ = \log p(y_n \mid z_n = k, \mu, \sigma)
  + \log \mbox{Pr}(z_n = k \mid \lambda)
  - \mathrm{log\_sum\_exp}_{k&#39; = 1}^K
      \log p(y_n \mid z_n = k&#39;, \mu, \sigma)
      + \log p(z_n = k&#39; \mid \lambda).
\end{array}
\]</span>
This can be coded up directly in Stan; the change-point model i