lib/lda-inference.c in ealdent-lda-ruby-0.1.5 vs lib/lda-inference.c in ealdent-lda-ruby-0.1.6
- old
+ new
@@ -544,16 +544,18 @@
// store model and likelihood
last_model = model;
last_gamma = var_gamma;
+ last_phi = phi;
}
// output the final model
last_model = model;
last_gamma = var_gamma;
+ last_phi = phi;
// output the word assignments (for visualization)
/*
char filename[100];
sprintf(filename, "%s/word-assignments.dat", directory);
@@ -833,10 +835,31 @@
}
return arr;
}
+static VALUE wrap_get_phi(VALUE self) {
+ if (!model_loaded)
+ return Qnil;
+
+ VALUE arr;
+ int i = 0, j = 0;
+ int max_length = max_corpus_length(last_corpus);
+
+
+ arr = rb_ary_new2(max_length);
+ for (i = 0; i < max_length; i++) {
+ VALUE arr2 = rb_ary_new2(last_model->num_topics);
+ for (j = 0; j < last_model->num_topics; j++) {
+ rb_ary_store(arr2, j, rb_float_new(last_phi[i][j]));
+ }
+ rb_ary_store(arr, i, arr2);
+ }
+
+ return arr;
+}
+
/*
* Get the beta matrix after the model has been run.
*/
static VALUE wrap_get_model_beta(VALUE self) {
if (!model_loaded)
@@ -938,9 +961,10 @@
rb_define_method(rb_cLda, "verbose=", wrap_set_verbosity, 1);
// retrieve model and gamma
rb_define_method(rb_cLda, "beta", wrap_get_model_beta, 0);
rb_define_method(rb_cLda, "gamma", wrap_get_gamma, 0);
+ rb_define_method(rb_cLda, "phi", wrap_get_phi, 0);
rb_define_method(rb_cLda, "model", wrap_get_model_settings, 0);
}
#endif
\ No newline at end of file