Example #1
0
size_t lnn_sentence_scores(sentence_type *s, const lnn_weights_type* wt, 
			   size_t nhidden, size_t nfeatures,
			   Float score0[], Float score1[],
			   Float *max_correct_score, Float *max_score) {
  int i, best_i = 0, best_correct_i = -1;
  Float sc;
  assert(s->nparses > 0);

  *max_score = score1[0] = sc 
    = lnn_parse_score(&s->parse[0], wt, nhidden, nfeatures, &score0[0]);

  if (s->parse[0].Pyx > 0) {
    best_correct_i = 0;
    *max_correct_score = sc;
  }

  for (i = 1; i < s->nparses; ++i) {
    score1[i] = sc 
      = lnn_parse_score(&s->parse[i], wt, nhidden, nfeatures, &score0[i*nhidden]);
    if (sc >= *max_score) {
      best_i = i;
      *max_score = sc;
    }
    if (s->parse[i].Pyx > 0 && (best_correct_i < 0 || sc > *max_correct_score)) {
      best_correct_i = i;
      *max_correct_score = sc;
    }
  }

  assert(finite(*max_score));
  assert(s->Px == 0 || best_correct_i >= 0);
  /* assert(best_correct_i >= 0); assert(finite(*max_correct_score)); */
  return best_i;
}  /* lnn_sentence_scores() */
void lnn_sentence_scores(sentence_type *s, const lnn_weights_type* wt, 
			 size_type nhidden, size_type nfeatures,
			 Float score0[], Float score1[],
			 Float *best_correct_score, int *best_correct_i,
			 Float *best_score, int *best_i) {
  int i;
  Float sc;
  assert(s->nparses > 0);

  *best_i = 0;
  *best_correct_i = -1;

  *best_score = score1[0] = sc 
    = lnn_parse_score(&s->parse[0], wt, nhidden, nfeatures, &score0[0]);

  if (s->parse[0].Pyx > 0) {
    *best_correct_i = 0;
    *best_correct_score = sc;
  }

  for (i = 1; i < s->nparses; ++i) {
    score1[i] = sc 
      = lnn_parse_score(&s->parse[i], wt, nhidden, nfeatures, &score0[i*nhidden]);
    if (sc >= *best_score) {
      *best_i = i;
      *best_score = sc;
    }
    if (s->parse[i].Pyx > 0 && (*best_correct_i < 0 || sc > *best_correct_score)) {
      *best_correct_i = i;
      *best_correct_score = sc;
    }
  }

  assert(finite(*best_score));
  assert(s->Px == 0 || (*best_correct_i >= 0 && *best_correct_i < s->nparses));
  /* assert(best_correct_i >= 0); assert(finite(*best_correct_score)); */
}  /* lnn_sentence_scores() */