pure implementation of LDA