;;; Copyright (c) 2015 MIT Probabilistic Computing Project.
;;;
;;; This file is part of Venture.
;;;
;;; Venture is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; Venture is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with Venture. If not, see <http://www.gnu.org/licenses/>.

[define model
 (lambda (n_topics vocab_size)
  (do (assume n_topics ,n_topics)
      (assume vocab_size ,vocab_size)
      (assume alpha_document_topic (gamma 1.0 2.0))
      (assume alpha_topic_word (gamma 1.0 2.0))
      (assume doc
       (mem (lambda (doc_id)
              (make_sym_dir_cat alpha_document_topic n_topics))))
      (assume topic
       (mem (lambda (topic_id)
              (make_sym_dir_cat alpha_topic_word vocab_size))))
      (assume word
       (mem (lambda (doc_id pos)
              ((topic ((doc doc_id)))))))]

;; TODO Generate data from the prior
[define data
 (lambda (n_docs n_words_per_doc)
  (for_each (arange n_docs)
   (lambda (doc_id)
    (for_each (arange n_words_per_doc)
     (lambda (pos)
      (observe (word ,doc_id ,pos) integer<0>))))))]

; Smoke test with
; venture -f lda.vnt -e 'do(model(2, 2), data(3, 4), resimulation_mh(default, one, 500))'
