From 0e29cdd9fdd90bdd72d02102e13da89b6148b0ca Mon Sep 17 00:00:00 2001 From: Al Date: Wed, 30 Nov 2016 15:42:09 -0800 Subject: [PATCH] [parser] fixing some uninitialized value issues during parser training --- src/averaged_perceptron_trainer.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/averaged_perceptron_trainer.c b/src/averaged_perceptron_trainer.c index 83693ef8..235b62b7 100644 --- a/src/averaged_perceptron_trainer.c +++ b/src/averaged_perceptron_trainer.c @@ -193,14 +193,12 @@ khash_t(class_weights) *averaged_perceptron_trainer_get_class_weights(averaged_p static inline bool averaged_perceptron_trainer_update_weight(khash_t(class_weights) *weights, uint64_t iter, uint32_t class_id, double value) { - class_weight_t weight; + class_weight_t weight = NULL_WEIGHT; size_t index; khiter_t k; k = kh_get(class_weights, weights, class_id); - if (k == kh_end(weights)) { - weight = NULL_WEIGHT; - } else { + if (k != kh_end(weights)) { weight = kh_value(weights, k); } @@ -257,7 +255,7 @@ uint32_t averaged_perceptron_trainer_predict(averaged_perceptron_trainer_t *self scores->n = num_classes; } - double_array_set(scores->a, scores->n, 0.0); + double_array_zero(scores->a, scores->n); cstring_array_foreach(features, i, feature, { if (!averaged_perceptron_trainer_get_feature_id(self, feature, &feature_id, add_if_missing)) { @@ -368,7 +366,6 @@ bool averaged_perceptron_trainer_train_example(averaged_perceptron_trainer_t *se } uint32_t guess = averaged_perceptron_trainer_predict(self, features); - char *predicted = cstring_array_get_string(self->class_strings, guess); // Online error-driven learning, only needs to update weights when it gets a wrong answer, making training fast if (guess != truth) {