Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void find_most_violated_constraint_marginrescaling(PATTERN x, LABEL y, LABEL *ybar, LATENT_VAR *hbar, STRUCTMODEL *sm, STRUCT_LEARN_PARM *sparm) {
- /*
- Finds the most violated constraint (loss-augmented inference), i.e.,
- computing argmax_{(ybar,hbar)} [<w,psi(x,ybar,hbar)> + loss(y,ybar,hbar)].
- The output (ybar,hbar) are stored at location pointed by
- pointers *ybar and *hbar.
- */
- double max_score, score;
- int *pattern_hash, max_pos,j,h;
- pattern_hash = sm->pattern_hash[x.example_id];
- max_score = -1E10;
- max_pos = -1;
- for (h=0;h<x.length-sparm->motif_length-sparm->bg_markov_order;h++) {
- score = 0.0;
- for (j=h;j<h+sparm->motif_length;j++) {
- score += sm->w[sm->sizePsi-(4*(j-h)+base2int(x.sequence[j]))];
- score -= sm->w[1+pattern_hash[j]];
- }
- if (score>max_score) {
- max_score = score;
- max_pos = h;
- }
- }
- /* zero-one loss */
- if (y.label==1) {
- if (max_score>1.0) {
- ybar->label = 1;
- hbar->position = max_pos;
- } else {
- ybar->label = -1;
- hbar->position = -1;
- }
- } else {
- if (1.0+max_score>0) {
- ybar->label = 1;
- hbar->position = max_pos;
- } else {
- ybar->label = -1;
- hbar->position = -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment