Skip to content

Commit

Permalink
add a java ut
Browse files Browse the repository at this point in the history
  • Loading branch information
hhbyyh committed Apr 30, 2015
1 parent 4041723 commit 68c2318
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,37 @@ public void distributedLDAModel() {
assert(model.logPrior() < 0.0);
}


@Test
public void OnlineOptimizerCompatibility() {
int k = 3;
double topicSmoothing = 1.2;
double termSmoothing = 1.2;

// Train a model
OnlineLDAOptimizer op = new OnlineLDAOptimizer().setTau_0(1024).setKappa(0.51)
.setGammaShape(1e40).setMiniBatchFraction(0.5);
LDA lda = new LDA();
lda.setK(k)
.setDocConcentration(topicSmoothing)
.setTopicConcentration(termSmoothing)
.setMaxIterations(5)
.setSeed(12345)
.setOptimizer(op);

LDAModel model = lda.run(corpus);

// Check: basic parameters
assertEquals(model.k(), k);
assertEquals(model.vocabSize(), tinyVocabSize);

// Check: topic summaries
Tuple2<int[], double[]>[] roundedTopicSummary = model.describeTopics();
assertEquals(roundedTopicSummary.length, k);
Tuple2<int[], double[]>[] roundedLocalTopicSummary = model.describeTopics();
assertEquals(roundedLocalTopicSummary.length, k);
}

private static int tinyK = LDASuite$.MODULE$.tinyK();
private static int tinyVocabSize = LDASuite$.MODULE$.tinyVocabSize();
private static Matrix tinyTopics = LDASuite$.MODULE$.tinyTopics();
Expand Down

0 comments on commit 68c2318

Please sign in to comment.