Package cc.mallet.topics

Examples of cc.mallet.topics.HDP


                             3, 2, 1)); // data, label, name fields
    testInstances.addThruPipe(new CsvIterator (testfileReader, Pattern.compile("^(\\S*)[\\s,]*(\\S*)[\\s,]*(.*)$"),
           3, 2, 1)); // data, label, name fields
   
    //setup HDP parameters(alpha, beta, gamma, initialTopics)
    HDP hdp = new HDP(1.0, 0.1, 1.0, 10);
    hdp.initialize(instances);
   
    //set number of iterations, and display result or not
    hdp.estimate(2000);
   
    //get topic distribution for first instance
    double[] distr = hdp.topicDistribution(0);
    //print out
    for(int j=0; j<distr.length ; j++){
      System.out.print(distr[j] + " ");
    }
   
    //for inferencer
    HDPInferencer inferencer = hdp.getInferencer();
    inferencer.setInstance(testInstances);
    inferencer.estimate(100);
    //get topic distribution for first test instance
    distr = inferencer.topicDistribution(0);   
    //print out
    for(int j=0; j<distr.length ; j++){
      System.out.print(distr[j] + " ");
    }
    //get preplexity
    double prep = inferencer.getPreplexity();
    System.out.println("preplexity for the test set=" + prep);
   
    //10-folds cross validation, with 1000 iteration for each test.
    hdp.runCrossValidation(10, 1000);
   
  }
View Full Code Here

TOP

Related Classes of cc.mallet.topics.HDP

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.