Skip to content

Commit

Permalink
Resolved issue in likelihood calculation for LDA. Note that likelihoo…
Browse files Browse the repository at this point in the history
…d calculation is relatively slow (costly) and probably should not be enabled by default.
  • Loading branch information
jegonzal committed Oct 1, 2013
1 parent dfdffb6 commit fcb6b55
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions toolkits/topic_modeling/cgs_lda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

// Global Types
// ============================================================================
typedef int count_type;
typedef long count_type;


/**
Expand Down Expand Up @@ -721,15 +721,15 @@ class likelihood_aggregator : public graphlab::IS_POD_TYPE {
likelihood_aggregator ret;
if(is_word(vertex)) {
for(size_t t = 0; t < NTOPICS; ++t) {
const double value = std::max(count_type(factor[t]), count_type(0));
const count_type value = std::max(count_type(factor[t]), count_type(0));
ret.lik_words_given_topics += lgamma(value + BETA);
}
} else { ASSERT_TRUE(is_doc(vertex));
double ntokens_in_doc = 0;
for(size_t t = 0; t < NTOPICS; ++t) {
const double value = std::max(count_type(factor[t]), count_type(0));
const count_type value = std::max(count_type(factor[t]), count_type(0));
ret.lik_topics += lgamma(value + ALPHA);
ntokens_in_doc += factor[t];
ntokens_in_doc += value;
}
ret.lik_topics -= lgamma(ntokens_in_doc + NTOPICS * ALPHA);
}
Expand All @@ -741,7 +741,9 @@ class likelihood_aggregator : public graphlab::IS_POD_TYPE {
// Address the global sum terms
double denominator = 0;
for(size_t t = 0; t < NTOPICS; ++t) {
denominator += lgamma(GLOBAL_TOPIC_COUNT[t] + NWORDS * BETA);
const count_type value =
std::max(count_type(GLOBAL_TOPIC_COUNT[t]), count_type(0));
denominator += lgamma(value + NWORDS * BETA);
} // end of for loop

const double lik_words_given_topics =
Expand Down Expand Up @@ -1129,15 +1131,15 @@ int main(int argc, char** argv) {
ASSERT_TRUE(success);
}

/* { // Add the likelihood aggregator
{ // Add the likelihood aggregator
const bool success =
engine.add_vertex_aggregator<likelihood_aggregator>
("likelihood",
likelihood_aggregator::map,
likelihood_aggregator::finalize) &&
engine.aggregate_periodic("likelihood", 10);
ASSERT_TRUE(success);
}*/
}

///! schedule only documents
dc.cout() << "Running The Collapsed Gibbs Sampler" << std::endl;
Expand Down

0 comments on commit fcb6b55

Please sign in to comment.