Skip to content

Commit

Permalink
Merge pull request #12 from alexanderrich/fix_time_range
Browse files Browse the repository at this point in the history
fix max_time off-by-one error and max_nterms calculation
  • Loading branch information
Jaan Altosaar committed Dec 12, 2017
2 parents 67139e6 + 0774574 commit 810d9ab
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions dtm/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,17 @@ void fit_dtm(int min_time, int max_time)
&& min_time >= 0
&& max_time < data_full->len);
data_subset = (corpus_seq_t*) malloc(sizeof(corpus_seq_t));
data_subset->len = max_time - min_time + 1;
data_subset->len = max_time - min_time;
data_subset->nterms = data_full->nterms;
data_subset->corpus = (corpus_t**) malloc(
sizeof(corpus_t*) * data_subset->len);
int max_nterms = 0;
int ndocs = 0;
for (int i=min_time; i < max_time; ++i) {
corpus_t* corpus = data_full->corpus[i];
max_nterms = max_nterms > corpus->nterms ? max_nterms : corpus->nterms;
data_subset->corpus[i - min_time] = corpus;
ndocs += corpus->ndocs;
}
data_subset->max_nterms = max_nterms;
data_subset->max_nterms = compute_max_nterms(data_subset);
data_subset->ndocs = ndocs;
} else {
// Use the entire dataset.
Expand Down Expand Up @@ -226,7 +224,7 @@ int main(int argc, char* argv[])
// mode for fitting a dynamic topic model

if (FLAGS_mode == "fit") {
fit_dtm(0, FLAGS_heldout_time - 1);
fit_dtm(0, FLAGS_heldout_time);
}

// mode for analyzing documents through time according to a DTM
Expand Down

0 comments on commit 810d9ab

Please sign in to comment.