public void SaveTopWords(string modelpath) { int tw = twords > V ? V : twords; using (System.IO.StreamWriter sw = new System.IO.StreamWriter(modelpath)) { for (int k = 0; k < K; k++) { var wordsProbsList = new Dictionary <int, double>(); for (int w = 0; w < V; w++) { wordsProbsList.Add(w, phi[k][w]); } double ans = 0; for (int w = 0; w < V; w++) { ans += phi[k][w]; } if (Math.Abs(ans - 1.00) > 0.1) { throw (new Exception("Phi Calculation Error")); } sw.Write("Topic " + k + "th:\n"); var wordsProbsListOrdered = wordsProbsList.OrderBy(e => - e.Value).ToList(); for (int i = 0; i < tw; i++) { string word = cor.GetStringByID(wordsProbsListOrdered[i].Key); sw.WriteLine("\t" + word + " " + wordsProbsListOrdered[i].Value); } } } }