def _run_gibbs_sampling(self, doc_ids):
        """Runs one iteration of Gibbs sampling on the provided docs.

        The statez variable is used for debugging, and possibly convergence
        testing in the future.
        """
        if doc_ids is None:
            doc_ids = xrange(self._num_docs)

        statez = {
            'updates': 0,
            'computes': 0
        }

        for d in doc_ids:
            doc, labels = self._get_doc_with_label_vector(d)
            for p, w in enumerate(doc):
                l = self._l_dp[d][p]

                self._decrement_counting_matrices(d, w, l)

                coeff_a = 1.0 / (
                    self._c_dl[d].sum() + self._num_labels * self._alpha)
                coeff_b = 1.0 / (
                    self._c_lw.sum(axis=1) + self._num_words * self._beta)
                label_probabilities = (
                    labels *
                    coeff_a * (self._c_dl[d] + self._alpha) *
                    coeff_b * (self._c_lw[:, w] + self._beta))
                new_label = numpy.random.multinomial(
                    1,
                    label_probabilities / label_probabilities.sum()).argmax()

                statez['computes'] += 1
                if l != new_label:
                    statez['updates'] += 1

                self._l_dp[d][p] = new_label
                self._increment_counting_matrices(d, w, new_label)

        return statez
dataset/ETHPy150Open oppia/oppia/core/domain/classifier_services.py/StringClassifier._run_gibbs_sampling/original