public void trainDocuments( InstanceList documents, int numTopics, int numIterations, double alpha, double beta) { double alphaSum = alpha * numTopics; lda = new ParallelTopicModel(numTopics, alphaSum, beta); lda.addInstances(documents); lda.setNumThreads(4); lda.setNumIterations(numIterations); lda.printLogLikelihood = false; try { lda.estimate(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("LDA parameter, alphaSum: " + lda.alphaSum + ", beta: " + lda.beta); }
public static void main(String[] args) throws Exception { InstanceList instances = InstanceList.load(new File(args[0])); int numTopics = Integer.parseInt(args[1]); ParallelTopicModel model = new ParallelTopicModel(numTopics, 5.0, 0.01); model.addInstances(instances); model.setNumIterations(1000); model.estimate(); TopicModelDiagnostics diagnostics = new TopicModelDiagnostics(model, 20); if (args.length == 3) { PrintWriter out = new PrintWriter(args[2]); out.println(diagnostics.toXML()); out.close(); } }