Learn the mathematical principles behind the LDA model. Refer to the LDA mathematical gossip article, which describes Markov chains and their stable distribution. It is interesting and easy to understand, the author's data and conclusions are verified using Java. The code is now posted for future reference.
Public class Main {private static final double [] [] tm = {0.65, 0.28, 0.07}, {0.15, 0.67, 0.18}, {0.12, 0.36 }}; private static final double [] pi = {0.21, 0.68, 0.11 }; /** calculate the distribution of each class after n generations based on the initial probability and transition matrix **/public static double [] nGen (int n) {double [] [] temp = new double [2] [3]; temp [0] = pi. clone (); int cur = 1; int last = 0; while (-- n> = 0) {for (int j = 0; j <3; j ++) {temp [cur] [j] = 0.0f; for (int k = 0; k <3; k ++) {temp [cur] [j] + = temp [last] [k] * tm [k] [j];} last = cur; cur = (cur + 1) % 2;} return temp [last];} public static void main (String [] args) {double [] d = nGen (1); for (int I = 0; I <d. length; I ++) {System. out. println (d [I]) ;}}
In fact, there is nothing complicated: matrix multiplication in linear algebra, plus a little bit of coding techniques in rolling arrays!
This article from the "every day progress a little" blog, please be sure to keep this source http://sbp810050504.blog.51cto.com/2799422/1297929