Guest User

Untitled

a guest
Aug 22nd, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 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. double max_score, score;
  9. int *pattern_hash, max_pos,j,h;
  10.  
  11. pattern_hash = sm->pattern_hash[x.example_id];
  12.  
  13. max_score = -1E10;
  14. max_pos = -1;
  15. for (h=0;h<x.length-sparm->motif_length-sparm->bg_markov_order;h++) {
  16. score = 0.0;
  17. for (j=h;j<h+sparm->motif_length;j++) {
  18. score += sm->w[sm->sizePsi-(4*(j-h)+base2int(x.sequence[j]))];
  19. score -= sm->w[1+pattern_hash[j]];
  20. }
  21. if (score>max_score) {
  22. max_score = score;
  23. max_pos = h;
  24. }
  25. }
  26.  
  27. /* zero-one loss */
  28. if (y.label==1) {
  29. if (max_score>1.0) {
  30. ybar->label = 1;
  31. hbar->position = max_pos;
  32. } else {
  33. ybar->label = -1;
  34. hbar->position = -1;
  35. }
  36. } else {
  37. if (1.0+max_score>0) {
  38. ybar->label = 1;
  39. hbar->position = max_pos;
  40. } else {
  41. ybar->label = -1;
  42. hbar->position = -1;
  43. }
  44.  
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment