Guest User

Untitled

a guest
Aug 22nd, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. void find_most_violated_constraint_marginrescaling(PATTERN x, LABEL y, LABEL *ybar, LATENT_VAR *hbar, STRUCTMODEL *sm, STRUCT_LEARN_PARM *sparm) {
  2. /*
  3.   Finds the most violated constraint (loss-augmented inference), i.e.,
  4.   computing argmax_{(ybar,hbar)} [<w,psi(x,ybar,hbar)> + loss(y,ybar,hbar)].
  5.   The output (ybar,hbar) are stored at location pointed by
  6.   pointers *ybar and *hbar.
  7. */
  8.  
  9.     int i;
  10.     int width = x.width;
  11.     int height = x.height;
  12.     int cur_class, cur_position_x, cur_position_y;
  13.     double max_score,score;
  14.     double *hog;
  15.     FILE    *fp;
  16.  
  17.     max_score = -DBL_MAX;
  18.     for(cur_position_x = 0; cur_position_x < width; cur_position_x++) {
  19.         for(cur_position_y = 0; cur_position_y < height; cur_position_y++) {
  20.  
  21.             hog = x.hog[cur_position_x][cur_position_y];
  22.  
  23.             for(cur_class = 0; cur_class < sparm->n_classes; cur_class++) {
  24.                 score = 0;
  25.                 for(i = 0; i < sparm->size_hog; i++) {
  26.                     score += sm->w[cur_class*sparm->size_hog+i+1]*hog[i];
  27.                 }
  28.                 if(cur_class != y.label)
  29.                     score += 1;
  30.                 if(score > max_score) {
  31.                     max_score = score;
  32.                     ybar->label = cur_class;
  33.                     hbar->position_x = cur_position_x;
  34.                     hbar->position_y = cur_position_y;
  35.                 }
  36.             }
  37.  
  38.         }
  39.     }
  40.  
  41.     return;
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment