diff options
author | John Langford <jl@hunch.net> | 2011-08-19 02:44:50 +0400 |
---|---|---|
committer | John Langford <jl@hunch.net> | 2011-08-19 02:44:50 +0400 |
commit | dec02180dbbb4d5762be0b997b68377327f2c32a (patch) | |
tree | ca767b663833699c44e533b5ace83dacf0d6b6cd /lda_core.cc | |
parent | bc9141695f7ef687d833b88e11d2d4e033631356 (diff) |
normalized termination condition from Matt
Diffstat (limited to 'lda_core.cc')
-rw-r--r-- | lda_core.cc | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lda_core.cc b/lda_core.cc index da3daa14..94397d7f 100644 --- a/lda_core.cc +++ b/lda_core.cc @@ -350,9 +350,12 @@ void expdigammify_2(float* gamma, float* norm) float average_diff(float* oldgamma, float* newgamma)
{
float sum = 0.;
- for (size_t i = 0; i<global.lda; i++)
+ float normalizer = 0.;
+ for (size_t i = 0; i<global.lda; i++) {
sum += fabsf(oldgamma[i] - newgamma[i]);
- return sum;
+ normalizer += newgamma[i];
+ }
+ return sum / normalizer;
}
// Returns E_q[log p(\theta)] - E_q[log q(\theta)].
@@ -436,11 +439,10 @@ float lda_loop(float* v,weight* weights,example* ec, float power_t) doc_length += f->x;
}
}
- for (size_t k =0; k<global.lda; k++) {
+ for (size_t k =0; k<global.lda; k++)
new_gamma[k] = new_gamma[k]*v[k]+global.lda_alpha;
- }
}
- while (average_diff(old_gamma, new_gamma) > 0.1);
+ while (average_diff(old_gamma, new_gamma) > 0.001);
ec->topic_predictions.erase();
if (ec->topic_predictions.end_array - ec->topic_predictions.begin < (int)global.lda)
|