Example #1
0
def find_most_violated_constraint_margin(x, y, model, sparm):
    """Return ybar associated with x's most violated constraint.

    The find most violated constraint function for margin rescaling.
    The default behavior is that this returns the value from the
    general find_most_violated_constraint function."""

    w = list(model.w)

    print '\nFinding most violated constraint'
    print '  w: ',w
    print '  y: ',y

    A = path.compute_loss_augmented_terms(x, w, y, path.L2)
    ybar = viterbi.solve(A)

    D = path.compute_data_terms(x, w)
    print '  ybar: ',ybar
    print '  loss: ',path.compute_loss(y, ybar, path.L2)
    #print 'Data terms:\n', np.round(D, 2)
    #print 'Loss augmented terms:\n', np.round(A, 2)

    return ybar
Example #2
0
def classify_example(x, model, sparm):
    """Given a pattern x, return the predicted label."""

    w = list(model.w)
    return viterbi.solve(path.compute_data_terms(x, w))