Skip to content

Commit

Permalink
some style change
Browse files Browse the repository at this point in the history
  • Loading branch information
hhbyyh committed May 1, 2015
1 parent 68c2318 commit 54cf8da
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class OnlineLDAOptimizer extends LDAOptimizer {
}

/**
* The function is for test only now. In the future, it can help support training strop/resume
* The function is for test only now. In the future, it can help support training stop/resume
*/
private[clustering] def setLambda(lambda: BDM[Double]): this.type = {
this.lambda = lambda
Expand All @@ -310,8 +310,9 @@ class OnlineLDAOptimizer extends LDAOptimizer {
this
}

override private[clustering] def initialize(docs: RDD[(Long, Vector)], lda: LDA):
OnlineLDAOptimizer = {
override private[clustering] def initialize(
docs: RDD[(Long, Vector)],
lda: LDA): OnlineLDAOptimizer = {
this.k = lda.getK
this.corpusSize = docs.count()
this.vocabSize = docs.first()._2.size
Expand All @@ -333,7 +334,6 @@ class OnlineLDAOptimizer extends LDAOptimizer {
submitMiniBatch(batch)
}


/**
* Submit a subset (like 1%, decide by the miniBatchFraction) of the corpus to the Online LDA
* model, and it will update the topic distribution adaptively for the terms appearing in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,35 +109,38 @@ 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);
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();
Expand Down

0 comments on commit 54cf8da

Please sign in to comment.