コード例 #1
0
/**********************************************************************
 * print_matrix
 *
 * Print the best guesses out of the match rating matrix.
 **********************************************************************/
void print_matrix(MATRIX rating_matrix) {
  int x;
  int dimension;
  int spread;
  CHOICES rating;

  cprintf ("Ratings Matrix (top choices)\n");

  dimension = matrix_dimension (rating_matrix);
  /* Do each diagonal */
  for (spread = 0; spread < dimension; spread++) {
    /* For each spot */
    for (x = 0; x < dimension - spread; x++) {
      /* Process one square */
      rating = matrix_get (rating_matrix, x, x + spread);

      if (rating != NOT_CLASSIFIED) {
        cprintf ("\t[%d,%d] : ", x, x + spread);
        if (first_node (rating))
          cprintf ("%-10s%4.0f\t|\t",
            class_string (first_node (rating)),
            class_probability (first_node (rating)));
        if (second_node (rating))
          cprintf ("%-10s%4.0f\t|\t",
            class_string (second_node (rating)),
            class_probability (second_node (rating)));
        if (third (rating))
          cprintf ("%-10s%4.0f\n",
            class_string (third (rating)),
            class_probability (third (rating)));
        else
          new_line();
      }
    }
  }
}
コード例 #2
0
/**********************************************************************
 * improve_by_chopping
 *
 * Start with the current word of blobs and its classification.  Find
 * the worst blobs and try to divide them up to improve the ratings.
 * As long as ratings are produced by the new blob splitting.  When
 * all the splitting has been accomplished all the ratings memory is
 * reclaimed.
 **********************************************************************/
void improve_by_chopping(register TWERD *word,
                         CHOICES_LIST *char_choices,
                         int fx,
                         STATE *best_state,
                         A_CHOICE *best_choice,
                         A_CHOICE *raw_choice,
                         SEAMS *seam_list,
                         DANGERR *fixpt,
                         STATE *chop_states,
                         INT32 *state_count,
                         STATE *correct_state,
                         INT32 pass) {
  INT32 blob_number;
  INT32 index;                   //to states
  CHOICES_LIST choices = *char_choices;
  float old_best;
  int fixpt_valid = 1;
  static INT32 old_count;        //from pass1

  do {
                                 /* Improvement loop */
    if (!fixpt_valid)
      fixpt->index = -1;
    old_best = class_probability (best_choice);
    choices = improve_one_blob (word, *char_choices, fx,
      &blob_number, seam_list, fixpt,
      chop_states + *state_count, correct_state,
      pass);
    if (choices != NULL) {
      LogNewSplit(blob_number);
      permute_characters (choices,
        class_probability (best_choice),
        best_choice, raw_choice);
      *char_choices = choices;

      if (old_best > class_probability (best_choice)) {
        set_n_ones (best_state, array_count (*char_choices) - 1);
        fixpt_valid = 1;
      }
      else {
        insert_new_chunk (best_state, blob_number,
          array_count (*char_choices) - 2);
        fixpt_valid = 0;
      }
      if (*state_count > 0) {
        if (pass == 0) {
          for (index = 0; index < *state_count; index++)
            insert_new_chunk (&chop_states[index], blob_number,
              array_count (*char_choices) - 2);
          set_n_ones (&chop_states[index],
            array_count (*char_choices) - 1);
        }
        (*state_count)++;
      }

      if (chop_debug)
        print_state ("best state = ",
          best_state, count_blobs (word->blobs) - 1);
      if (first_pass)
        chops_performed1++;
      else
        chops_performed2++;

    }
  }
  while (choices &&
    !AcceptableChoice (*char_choices, best_choice, raw_choice, fixpt) &&
    !blob_skip && array_count (*char_choices) < MAX_NUM_CHUNKS);
  if (pass == 0)
    old_count = *state_count;
  else {
    if (old_count != *state_count)
      fprintf (matcher_fp,
        "Mis-matched state counts, " INT32FORMAT " pass1, "
        INT32FORMAT " pass2\n", old_count, *state_count);
  }
  if (!fixpt_valid)
    fixpt->index = -1;
}