(libload "torch/torch")

;; create the dataset

(setq data (new MatDataSet     ))

;; kmean
(setq kmeans_trainer (new EMTrainer (new KMeans            )))
(==>  kmeans_trainer  setROption "end accuracy"      )
(==>  kmeans_trainer  setIOption "max iter"          )

(setq kmeans_measurers (new MeasurerList))
(==>  kmeans_measurers  addNode (new  NLLMeasurer           ))

;; gaussian mixture
(setq gmm  (new DiagonalGMM          :kmeans_trainer:p))
(==>  gmm  setVarThreshold    )
(==>  gmm  setROption "prior weights"    )
(==>  gmm  setOOption "initial kmeans trainer measurers"  :kmeans_measurers:p)

(setq measurers (new MeasurerList))
(==>  measurers addNode  (new NLLMeasurer        ))

(setq trainer (new EMTrainer  :gmm:p))
(==>  trainer setIOption "max iter"    )
(==>  trainer setROption "end accuracy"   )

(==>  trainer train  :data:p  :measurers:p)

(setq result_model  (new DiskXFile    "w"))
(==>  result_model  taggedWrite       )
(==>  result_model  taggedWrite       )

(==>  gmm saveXFile  :result_model:p)
