def compute_topic_document_probability
      outp = []

      @corpus.documents.each_with_index do |doc, idx|
        tops = [0.0] * num_topics
        ttl  = doc.counts.inject(0.0) { |sum, i| sum + i }
        phi[idx].each_with_index do |word_dist, word_idx|
          word_dist.each_with_index do |top_prob, top_idx|
            tops[top_idx] += Math.log(top_prob) * doc.counts[word_idx]
          end
        end
        tops = tops.map { |i| i / ttl }
        outp << tops
      end

      outp
    end
def compute_topic_document_probability
      outp = []

      @corpus.documents.each_with_index do |doc, idx|
        tops = [0.0] * num_topics
        ttl  = doc.counts.inject(0.0) { |sum, i| sum + i }
        phi[idx].each_with_index do |word_dist, word_idx|
          word_dist.each_with_index do |top_prob, top_idx|
            tops[top_idx] += Math.log(top_prob) * doc.counts[word_idx]
          end
        end
        tops = tops.map { |i| i / ttl }
        outp << tops
      end

      outp
    end
Compute the average log probability for each topic for each document in the corpus.
 This method returns a matrix:  num_docs x num_topics with the average log probability
 for the topic in the document.