public function gibbsSample(array &$docs)
    {
        foreach ($docs as $i=>$doc) {
            foreach ($doc as $idx=>$w) {
                // remove word $w from the dataset
                $topic = $this->word_doc_assigned_topic[$i][$idx];
                $this->count_docs_topics[$i][$topic]--;
                $this->count_topics_words[$topic][$w]--;
                $this->words_in_topic[$topic]--;
                $this->words_in_doc[$i]--;
                // ---------------------------

                // recompute the probabilities of all topics and
                // resample a topic for this word $w
                $p_topics = $this->conditionalDistribution($i,$w);
                $topic = $this->drawIndex($p_topics);
                // ---------------------------

                // add word $w back into the dataset
                if (!isset($this->count_topics_words[$topic][$w]))
                    $this->count_topics_words[$topic][$w]=0;
                $this->count_topics_words[$topic][$w]++;

                $this->count_docs_topics[$i][$topic]++;
                $this->words_in_topic[$topic]++;
                $this->words_in_doc[$i]++;
                $this->word_doc_assigned_topic[$i][$idx] = $topic;
                // ---------------------------
            }
        }
     }